Hooked up stbi to decode images for the app GUI

This commit is contained in:
x1nixmzeng 2017-01-07 20:16:12 +00:00
parent 996f71a6df
commit de66b62e0e
2 changed files with 42 additions and 15 deletions

View File

@ -36,6 +36,8 @@
#include "WndAbout.h"
#include "ResCxbx.h"
#include "stb_image.h"
#include <cstdio>
WndAbout::WndAbout(HINSTANCE x_hInstance, HWND x_parent) : Wnd(x_hInstance)
@ -101,13 +103,25 @@ LRESULT CALLBACK WndAbout::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM l
{
HRSRC hSrc = FindResource(NULL, MAKEINTRESOURCE(IDR_JPEG_ABOUT), "JPEG");
HGLOBAL hRes = LoadResource(NULL, hSrc);
uint08 *jpgData = (uint08*)LockResource(hRes);
uint08 *jpgData = (uint08*)LockResource(hRes);
uint32 jpgFileSize = SizeofResource(NULL, hSrc);
uint32 bmpFileSize = 0;
uint32 bmpWidth, bmpHeight;
uint32 bmpWidth = 0;
uint32 bmpHeight = 0;
uint08 *bmpBuff = nullptr; // jpeg2bmp(jpgData, jpgFileSize, &bmpFileSize, &bmpWidth, &bmpHeight);
uint08 *bmpBuff = reinterpret_cast<uint08*>
(
stbi_load_from_memory
(
reinterpret_cast<const stbi_uc*>(jpgData),
static_cast<int>(jpgFileSize),
reinterpret_cast<int*>(&bmpWidth),
reinterpret_cast<int*>(&bmpHeight),
nullptr,
STBI_rgb
)
);
// create bitmap
{
@ -115,7 +129,7 @@ LRESULT CALLBACK WndAbout::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM l
BmpInfo.bmiHeader.biSize = sizeof(BITMAPINFO) - sizeof(RGBQUAD);
BmpInfo.bmiHeader.biWidth = bmpWidth;
BmpInfo.bmiHeader.biHeight = 0 - (int)bmpHeight;
BmpInfo.bmiHeader.biHeight = 0 - (long)bmpHeight;
BmpInfo.bmiHeader.biPlanes = 1;
BmpInfo.bmiHeader.biBitCount = 24;
BmpInfo.bmiHeader.biCompression = BI_RGB;
@ -128,8 +142,9 @@ LRESULT CALLBACK WndAbout::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM l
SetDIBits(hDC, m_BackBmp, 0, bmpHeight, bmpBuff, &BmpInfo, DIB_RGB_COLORS);
}
free(bmpBuff);
stbi_image_free(bmpBuff);
FreeResource(hRes);
UnlockResource(hRes);
}

View File

@ -42,11 +42,10 @@
#include <io.h>
/**
* Silly little hack to fix link error with libjpeg on MSVC 2015
*/
FILE _iob[] = { *stdin, *stdout, *stderr };
extern "C" FILE * __cdecl __iob_func(void) { return _iob; }
#define STBI_ONLY_JPEG
#define STBI_NO_LINEAR
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
WndMain::WndMain(HINSTANCE x_hInstance) :
Wnd(x_hInstance),
@ -226,13 +225,25 @@ LRESULT CALLBACK WndMain::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lP
{
HRSRC hSrc = FindResource(NULL, MAKEINTRESOURCE(IDR_JPEG_SPLASH), "JPEG");
HGLOBAL hRes = LoadResource(NULL, hSrc);
uint08 *jpgData = (uint08*)LockResource(hRes);
uint08 *jpgData = (uint08*)LockResource(hRes);
uint32 jpgFileSize = SizeofResource(NULL, hSrc);
uint32 bmpFileSize = 0;
uint32 bmpWidth, bmpHeight;
uint32 bmpWidth = 0;
uint32 bmpHeight = 0;
uint08 *bmpBuff = nullptr;// jpeg2bmp(jpgData, jpgFileSize, &bmpFileSize, &bmpWidth, &bmpHeight);
uint08 *bmpBuff = reinterpret_cast<uint08*>
(
stbi_load_from_memory
(
reinterpret_cast<const stbi_uc*>(jpgData),
static_cast<int>(jpgFileSize),
reinterpret_cast<int*>(&bmpWidth),
reinterpret_cast<int*>(&bmpHeight),
nullptr,
STBI_rgb
)
);
// create bitmap
{
@ -240,7 +251,7 @@ LRESULT CALLBACK WndMain::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lP
BmpInfo.bmiHeader.biSize = sizeof(BITMAPINFO) - sizeof(RGBQUAD);
BmpInfo.bmiHeader.biWidth = bmpWidth;
BmpInfo.bmiHeader.biHeight = 0 - (int)bmpHeight;
BmpInfo.bmiHeader.biHeight = 0 - (long)bmpHeight;
BmpInfo.bmiHeader.biPlanes = 1;
BmpInfo.bmiHeader.biBitCount = 24;
BmpInfo.bmiHeader.biCompression = BI_RGB;
@ -253,8 +264,9 @@ LRESULT CALLBACK WndMain::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lP
SetDIBits(hDC, m_BackBmp, 0, bmpHeight, bmpBuff, &BmpInfo, DIB_RGB_COLORS);
}
free(bmpBuff);
stbi_image_free(bmpBuff);
FreeResource(hRes);
UnlockResource(hRes);
}