mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 04:22:20 +02:00
Image fixes
This commit is contained in:
parent
4a3e21c1ab
commit
7206038cc5
2 changed files with 93 additions and 38 deletions
|
@ -6,6 +6,10 @@
|
||||||
#include "util/PerfTimer.h"
|
#include "util/PerfTimer.h"
|
||||||
#include "util/TLSingleton.h"
|
#include "util/TLSingleton.h"
|
||||||
#include "img/JPEGData.h"
|
#include "img/JPEGData.h"
|
||||||
|
#include "img/TGAData.h"
|
||||||
|
#include "img/PNGData.h"
|
||||||
|
#include "img/PVRData.h"
|
||||||
|
#include "img/BFIData.h"
|
||||||
|
|
||||||
#pragma warning(disable:4190)
|
#pragma warning(disable:4190)
|
||||||
|
|
||||||
|
@ -95,6 +99,57 @@ BF_EXPORT int BF_CALLTYPE Res_PSDLayer_IsVisible(PSDLayerInfo* layerInfo)
|
||||||
|
|
||||||
///
|
///
|
||||||
|
|
||||||
|
BF_EXPORT uint32* BF_CALLTYPE Res_LoadImage(char* inFileName, int& width, int& height)
|
||||||
|
{
|
||||||
|
String fileName = inFileName;
|
||||||
|
|
||||||
|
int dotPos = (int)fileName.LastIndexOf('.');
|
||||||
|
String ext;
|
||||||
|
if (dotPos != -1)
|
||||||
|
ext = fileName.Substring(dotPos);
|
||||||
|
|
||||||
|
ImageData* imageData = NULL;
|
||||||
|
bool handled = false;
|
||||||
|
bool failed = false;
|
||||||
|
|
||||||
|
if (fileName == "!white")
|
||||||
|
{
|
||||||
|
imageData = new ImageData();
|
||||||
|
imageData->CreateNew(1, 1, true);
|
||||||
|
imageData->mBits[0] = 0xFFFFFFFF;
|
||||||
|
handled = true;
|
||||||
|
}
|
||||||
|
else if (ext == ".tga")
|
||||||
|
imageData = new TGAData();
|
||||||
|
else if (ext == ".png")
|
||||||
|
imageData = new PNGData();
|
||||||
|
else if (ext == ".jpg")
|
||||||
|
imageData = new JPEGData();
|
||||||
|
else if (ext == ".pvr")
|
||||||
|
imageData = new PVRData();
|
||||||
|
else
|
||||||
|
{
|
||||||
|
BF_FATAL("Unknown texture format");
|
||||||
|
return NULL; // Unknown format
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!imageData->LoadFromFile(fileName))
|
||||||
|
{
|
||||||
|
imageData->Deref();
|
||||||
|
BF_FATAL("Failed to load image");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32* bits = imageData->mBits;
|
||||||
|
imageData->mBits = NULL;
|
||||||
|
|
||||||
|
width = imageData->mWidth;
|
||||||
|
height = imageData->mHeight;
|
||||||
|
imageData->Deref();
|
||||||
|
|
||||||
|
return bits;
|
||||||
|
}
|
||||||
|
|
||||||
BF_EXPORT StringView BF_CALLTYPE Res_JPEGCompress(uint32* bits, int width, int height, int quality)
|
BF_EXPORT StringView BF_CALLTYPE Res_JPEGCompress(uint32* bits, int width, int height, int quality)
|
||||||
{
|
{
|
||||||
String& outString = *gResLib_TLStrReturn.Get();
|
String& outString = *gResLib_TLStrReturn.Get();
|
||||||
|
|
|
@ -316,7 +316,7 @@ void JPEGData::Compress(int quality)
|
||||||
|
|
||||||
while (cinfo.next_scanline < cinfo.image_height)
|
while (cinfo.next_scanline < cinfo.image_height)
|
||||||
{
|
{
|
||||||
uint8* src = (uint8*)&mBits[(mHeight - cinfo.next_scanline - 1) * mWidth];
|
uint8* src = (uint8*)&mBits[cinfo.next_scanline * mWidth];
|
||||||
|
|
||||||
uint8* dest = line;
|
uint8* dest = line;
|
||||||
for (int x = 0; x < mWidth; x++)
|
for (int x = 0; x < mWidth; x++)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue