#include "libxisf.h" #include #include "../rawimage.h" bool OpenGLES = false; bool loadXISF(const LibXISF::ByteArray &data, HBITMAP *hbmp, UINT thumbSize) { OutputDebugStringA("TENMON"); try { LibXISF::XISFReader xisf; xisf.open(data); const LibXISF::Image &xisfImage = xisf.getImage(0); RawImage::DataType type; switch(xisfImage.sampleFormat()) { case LibXISF::Image::UInt8: type = RawImage::UINT8; break; case LibXISF::Image::UInt16: type = RawImage::UINT16; break; case LibXISF::Image::UInt32: type = RawImage::UINT32; break; case LibXISF::Image::Float32: type = RawImage::FLOAT32; break; case LibXISF::Image::Float64: type = RawImage::FLOAT64; break; default: break; } LibXISF::Image tmpImage = xisfImage; tmpImage.convertPixelStorageTo(LibXISF::Image::Planar); UINT w = tmpImage.width(); UINT h = tmpImage.height(); std::shared_ptr rawImage; if(tmpImage.colorSpace() == LibXISF::Image::ColorSpace::Gray) { rawImage = std::make_shared(tmpImage.width(), tmpImage.height(), 1, type); std::memcpy(rawImage->data(), tmpImage.imageData(), tmpImage.imageDataSize() / tmpImage.channelCount()); } else if(tmpImage.channelCount() == 3 || tmpImage.channelCount() == 4) { rawImage = RawImage::fromPlanar(tmpImage.imageData(), tmpImage.width(), tmpImage.height(), tmpImage.channelCount(), type); } rawImage->calcStats(); if(rawImage->imageStats().m_median[0] < rawImage->norm() * 0.2f) { OutputDebugStringA("Stretch image"); MTFParam params = rawImage->calcMTFParams(); rawImage->applySTF(params); } UINT cw = thumbSize; UINT ch = thumbSize; if (w > h) ch = h * thumbSize / w; else cw = w * thumbSize / h; rawImage->resize(cw, ch); rawImage->convertToType(RawImage::UINT8); BITMAPINFO bmi = {}; bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader); bmi.bmiHeader.biWidth = cw; bmi.bmiHeader.biHeight = -static_cast(ch); bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biBitCount = 32; bmi.bmiHeader.biCompression = BI_RGB; UINT lw = cw * 4; BYTE *pBits; HBITMAP bmp = CreateDIBSection(NULL, &bmi, DIB_RGB_COLORS, reinterpret_cast(&pBits), NULL, 0); const unsigned char *p = (const unsigned char*)rawImage->data(); const unsigned short *ps = (const unsigned short*)rawImage->data(); if(tmpImage.channelCount() == 1) { for(UINT y = 0; y < ch; y++) { for(UINT x = 0; x < cw; x++) { pBits[(y * lw) + x * 4 + 0] = p[y * cw + x]; pBits[(y * lw) + x * 4 + 1] = p[y * cw + x]; pBits[(y * lw) + x * 4 + 2] = p[y * cw + x]; pBits[(y * lw) + x * 4 + 3] = 255; } } } else { for(UINT y = 0; y < ch; y++) { for(UINT x = 0; x < cw; x++) { pBits[(y * lw) + x * 4 + 0] = p[y * cw * 4 + x * 4 + 2]; pBits[(y * lw) + x * 4 + 1] = p[y * cw * 4 + x * 4 + 1]; pBits[(y * lw) + x * 4 + 2] = p[y * cw * 4 + x * 4 + 0]; pBits[(y * lw) + x * 4 + 3] = 255; } } } *hbmp = bmp; return true; } catch (LibXISF::Error &err) { char text[1024]; sprintf(text, "Failed to open XISF image %s", err.what()); OutputDebugStringA(text); return false; } return false; }