jpegdec improvements (width/height)

This commit is contained in:
Aaron Robinson 2004-04-15 06:00:31 +00:00
parent 0495630eb1
commit 6005da558d
5 changed files with 17 additions and 11 deletions

BIN
Cxbx.opt

Binary file not shown.

View File

@ -37,6 +37,6 @@
#include "Cxbx.h"
// convert in memory jpeg to bmp
uint08 *jpeg2bmp(uint08 *jpeg, uint32 jpegSize, uint32 &bmpSize);
uint08 *jpeg2bmp(uint08 *jpeg, uint32 jpegSize, uint32 *bmpSize, uint32 *bmpWidth, uint32 *bmpHeight);
#endif

View File

@ -104,18 +104,19 @@ LRESULT CALLBACK WndAbout::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM l
uint32 jpgFileSize = SizeofResource(NULL, hSrc);
uint32 bmpFileSize = 0;
uint32 bmpWidth, bmpHeight;
uint08 *bmpBuff = 0;
bmpBuff = jpeg2bmp(jpgData, jpgFileSize, bmpFileSize);
bmpBuff = jpeg2bmp(jpgData, jpgFileSize, &bmpFileSize, &bmpWidth, &bmpHeight);
// create bitmap
{
BITMAPINFO BmpInfo;
BmpInfo.bmiHeader.biSize = sizeof(BITMAPINFO) - sizeof(RGBQUAD);
BmpInfo.bmiHeader.biWidth = 400;
BmpInfo.bmiHeader.biHeight = -300;
BmpInfo.bmiHeader.biWidth = bmpWidth;
BmpInfo.bmiHeader.biHeight = 0 - (int)bmpHeight;
BmpInfo.bmiHeader.biPlanes = 1;
BmpInfo.bmiHeader.biBitCount = 24;
BmpInfo.bmiHeader.biCompression = BI_RGB;

View File

@ -253,18 +253,19 @@ LRESULT CALLBACK WndMain::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lP
uint32 jpgFileSize = SizeofResource(NULL, hSrc);
uint32 bmpFileSize = 0;
uint32 bmpWidth, bmpHeight;
uint08 *bmpBuff = 0;
bmpBuff = jpeg2bmp(jpgData, jpgFileSize, bmpFileSize);
bmpBuff = jpeg2bmp(jpgData, jpgFileSize, &bmpFileSize, &bmpWidth, &bmpHeight);
// create bitmap
{
BITMAPINFO BmpInfo;
BmpInfo.bmiHeader.biSize = sizeof(BITMAPINFO) - sizeof(RGBQUAD);
BmpInfo.bmiHeader.biWidth = 640;
BmpInfo.bmiHeader.biHeight = -480;
BmpInfo.bmiHeader.biWidth = bmpWidth;
BmpInfo.bmiHeader.biHeight = 0 - (int)bmpHeight;
BmpInfo.bmiHeader.biPlanes = 1;
BmpInfo.bmiHeader.biBitCount = 24;
BmpInfo.bmiHeader.biCompression = BI_RGB;

View File

@ -137,7 +137,7 @@ void jpeg_memory_src(j_decompress_ptr cinfo, uint08 *buffer, uint32 bufferSize)
}
// convert in memory jpeg to bmp
uint08 *jpeg2bmp(uint08 *jpeg, uint32 jpegSize, uint32 &bmpSize)
uint08 *jpeg2bmp(uint08 *jpeg, uint32 jpegSize, uint32 *bmpSize, uint32 *bmpWidth, uint32 *bmpHeight)
{
jpeg_decompress_struct cinfo;
jpeg_error_mgr jerr;
@ -164,11 +164,15 @@ uint08 *jpeg2bmp(uint08 *jpeg, uint32 jpegSize, uint32 &bmpSize)
// update row_stride
row_stride = cinfo.output_width * cinfo.output_components;
// save these for caller
*bmpWidth = cinfo.output_width;
*bmpHeight = cinfo.output_height;
// calculate bitmap size
bmpSize = row_stride*cinfo.output_height;
*bmpSize = row_stride*cinfo.output_height;
// allocate bitmap data
buffer = (uint08*)malloc(bmpSize);
buffer = (uint08*)malloc(*bmpSize);
bufcur = buffer;
for(y=0;y<cinfo.output_height;y++)
@ -199,7 +203,7 @@ uint08 *jpeg2bmp(uint08 *jpeg, uint32 jpegSize, uint32 &bmpSize)
jpeg_destroy_decompress(&cinfo);
bmpSize = row_stride*cinfo.output_height;
*bmpSize = row_stride*cinfo.output_height;
return (uint08*)buffer;
}