mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 12:32: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/TLSingleton.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)
|
||||
|
||||
|
@ -15,7 +19,7 @@ static TLSingleton<String> gResLib_TLStrReturn;
|
|||
|
||||
BF_EXPORT PSDReader* BF_CALLTYPE Res_OpenPSD(const char* fileName)
|
||||
{
|
||||
//gPerfManager->StartRecording();
|
||||
//gPerfManager->StartRecording();
|
||||
|
||||
PSDReader* aPSDReader = new PSDReader();
|
||||
if (!aPSDReader->Init(fileName))
|
||||
|
@ -41,7 +45,7 @@ BF_EXPORT TextureSegment* BF_CALLTYPE Res_PSD_GetLayerTexture(PSDReader* pSDRead
|
|||
if (texture == NULL)
|
||||
return NULL;
|
||||
|
||||
TextureSegment* textureSegment = new TextureSegment();
|
||||
TextureSegment* textureSegment = new TextureSegment();
|
||||
textureSegment->InitFromTexture(texture);
|
||||
return textureSegment;
|
||||
}
|
||||
|
@ -55,7 +59,7 @@ BF_EXPORT TextureSegment* BF_CALLTYPE Res_PSD_GetMergedLayerTexture(PSDReader* p
|
|||
if (texture == NULL)
|
||||
return NULL;
|
||||
|
||||
TextureSegment* textureSegment = new TextureSegment();
|
||||
TextureSegment* textureSegment = new TextureSegment();
|
||||
textureSegment->InitFromTexture(texture);
|
||||
return textureSegment;
|
||||
}
|
||||
|
@ -71,21 +75,21 @@ BF_EXPORT PSDLayerInfo* BF_CALLTYPE Res_PSD_GetLayerInfo(PSDReader* pSDReader, i
|
|||
}
|
||||
|
||||
BF_EXPORT void BF_CALLTYPE Res_PSDLayer_GetSize(PSDLayerInfo* layerInfo, int* x, int* y, int* width, int* height)
|
||||
{
|
||||
{
|
||||
*x = layerInfo->mX;
|
||||
*y = layerInfo->mY;
|
||||
*width = layerInfo->mWidth;
|
||||
*height = layerInfo->mHeight;
|
||||
*height = layerInfo->mHeight;
|
||||
}
|
||||
|
||||
BF_EXPORT int BF_CALLTYPE Res_PSDLayer_GetLayerId(PSDLayerInfo* layerInfo)
|
||||
{
|
||||
{
|
||||
return layerInfo->mLayerId;
|
||||
}
|
||||
|
||||
BF_EXPORT const char* BF_CALLTYPE Res_PSDLayer_GetName(PSDLayerInfo* layerInfo)
|
||||
{
|
||||
return layerInfo->mName.c_str();
|
||||
{
|
||||
return layerInfo->mName.c_str();
|
||||
}
|
||||
|
||||
BF_EXPORT int BF_CALLTYPE Res_PSDLayer_IsVisible(PSDLayerInfo* layerInfo)
|
||||
|
@ -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)
|
||||
{
|
||||
String& outString = *gResLib_TLStrReturn.Get();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue