现在尝试2天没有任何运气。我的目标是获取通常由其创建2个exr文件的2个数据数组,并创建一个多层/多页TIFF文件(FreeImage仅支持tif,gif和ico的多页,并且我们也需要在python中也能很好地工作)。
static unsigned DLL_CALLCONV
myReadProc(void *buffer, unsigned size, unsigned count, freeimage::fi_handle handle) {
return (unsigned)fread(buffer, size, count, (FILE *)handle);
}
static unsigned DLL_CALLCONV
myWriteProc(void *buffer, unsigned size, unsigned count, freeimage::fi_handle handle) {
return (unsigned)fwrite(buffer, size, count, (FILE *)handle);
}
static int DLL_CALLCONV
mySeekProc(freeimage::fi_handle handle, long offset, int origin) {
return fseek((FILE *)handle, offset, origin);
}
static long DLL_CALLCONV
myTellProc(freeimage::fi_handle handle) {
return ftell((FILE *)handle);
}
void MyClass::TestMultilayeredFile(math::float4 *data1, math::float4 *data2, Hash128 &hash, const int width, const int height)
{
freeimage::FreeImageIO io;
io.read_proc = myReadProc;
io.write_proc = myWriteProc;
io.seek_proc = mySeekProc;
io.tell_proc = myTellProc;
core::string cachePathAsset = GetAbsoluteHashFilePath(GetRelativeHashFilePath(hash, "_combined.tiff"));
const int pixelCount = width * height;
enum Layers
{
kData1 = 0,
kData2 = 1,
kLayerCount = 2
};
FILE *file = fopen(cachePathAsset.c_str(), "w+b");
if (file != NULL) {
freeimage::FIMULTIBITMAP *out = freeimage::FreeImage_OpenMultiBitmapFromHandle(freeimage::FREE_IMAGE_FORMAT::FIF_TIFF, &io, (freeimage::fi_handle)file, 0x0800);
if (out)
{
const math::float4* kLayers[2] = { data1, data2 };
for (int layer = 0; layer < kLayerCount; ++layer)
{
freeimage::FIBITMAP* bitmap = freeimage::FreeImage_AllocateT(freeimage::FIT_RGBAF, width, height);
const int pitch = freeimage::FreeImage_GetPitch(bitmap);
void* bytes = (freeimage::BYTE*)freeimage::FreeImage_GetBits(bitmap);
const int bytesPerPixel = freeimage::FreeImage_GetBPP(bitmap) / 8;
DebugAssert(pitch == width * bytesPerPixel);
DebugAssert(bytes);
DebugAssert(bytesPerPixel == 16);
memcpy(bytes, kLayers[layer], pixelCount * bytesPerPixel);
freeimage::FreeImage_AppendPage(out, bitmap);
freeimage::FreeImage_Unload(bitmap);
}
// Save the multi-page file to the stream
BOOL bSuccess = freeimage::FreeImage_SaveMultiBitmapToHandle(freeimage::FREE_IMAGE_FORMAT::FIF_TIFF, out, &io, (freeimage::fi_handle)file, 0x0800);
freeimage::FreeImage_CloseMultiBitmap(out, 0);
}
}
}
已创建tiff文件,但仅包含1kb。另外,bSuccess
返回false。生成单个图像的代码在过去曾行之有效,但之前从未进行过复用。