update latest stb.h, stb_image.c BMP changes, etc.

This commit is contained in:
nothings.org 2007-07-15 00:13:20 +00:00
parent b9250aa2a5
commit aa882483f5
4 changed files with 2199 additions and 1749 deletions

35
imv.c
View File

@ -116,11 +116,9 @@ HWND win;
void platformDrawBitmap(HDC hdc, int x, int y, unsigned char *bits, int w, int h, int stride, int dim)
{
int i;
BITMAPINFOHEADER b;
BITMAPINFOHEADER b = { sizeof(b) };
int result;
memset(&b, 0, sizeof(b));
b.biSize = sizeof(b);
b.biPlanes=1;
b.biBitCount=BPP*8;
b.biWidth = stride/BPP;
@ -628,8 +626,7 @@ int label_font_height=12;
// build the font for the filename label
void build_label_font(void)
{
LOGFONT lf;
memset(&lf, 0, sizeof(lf));
LOGFONT lf = {0};
lf.lfHeight = label_font_height;
lf.lfOutPrecision = OUT_TT_PRECIS; // prefer truetype to raster fonts
strcpy(lf.lfFaceName, "Times New Roman");
@ -1382,9 +1379,7 @@ static char filenamebuffer[4096];
void open_file(void)
{
OPENFILENAME o;
memset(&o, 0, sizeof(o));
o.lStructSize = sizeof(o);
OPENFILENAME o = { sizeof(o) };
o.lpstrFilter = open_filter;
o.lpstrFile = filenamebuffer;
filenamebuffer[0] = 0;
@ -2140,7 +2135,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
MEMORYSTATUS mem;
MSG msg;
WNDCLASSEX wndclass;
WNDCLASSEX wndclass = { sizeof(wndclass) };
HWND hWnd;
// initial loaded image
@ -2177,8 +2172,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
assert(helptext_center[sizeof(helptext_center)-1]==0);
// create the main window class
memset(&wndclass, 0, sizeof(wndclass));
wndclass.cbSize = sizeof(wndclass);
wndclass.style = CS_OWNDC | CS_DBLCLKS;
wndclass.lpfnWndProc = (WNDPROC)MainWndProc;
wndclass.hInstance = hInstance;
@ -2204,9 +2197,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
if (argc < 1) {
// if run with no arguments, get an initial filename
OPENFILENAME o;
memset(&o, 0, sizeof(o));
o.lStructSize = sizeof(o);
OPENFILENAME o = { sizeof(o) };
o.lpstrFilter = open_filter;
o.lpstrFile = filenamebuffer;
filenamebuffer[0] = 0;
@ -2255,8 +2246,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
// allocate semaphores / mutexes
cache_mutex = stb_mutex_new();
decode_mutex = stb_mutex_new();
decode_queue = stb_sem_new(1,1);
disk_command_queue = stb_sem_new(1,1);
decode_queue = stb_sem_new(1);
disk_command_queue = stb_sem_new(1);
resize_merge = stb_sync_new();
// go ahead and start the other tasks
@ -3167,18 +3158,20 @@ static uint8 *imv_decode_from_memory(uint8 *mem, int len, int *x, int *y, int *n
uint8 *res = NULL;
imv_failure_string = NULL;
res = stbi_load_from_memory(mem, len, x, y, n, n_req);
if (res) return res;
imv_failure_string = stbi_failure_reason();
#ifdef USE_FREEIMAGE
if (!only_stbi) {
if (res == NULL && FreeImagePresent) {
if (FreeImagePresent) {
FIMEMORY *fi = FreeImage_OpenMemory(mem,len);
res = LoadImageWithFreeImage(fi, x, y, n, n_req);
FreeImage_CloseMemory(fi);
// if no error message is generated, because it's not a known type,
// we'll get the unknown-type message from stbi_failure_reason()
}
if (res) return res;
}
#endif
res = stbi_load_from_memory(mem, len, x, y, n, n_req);
if (res == NULL && imv_failure_string == NULL)
imv_failure_string = stbi_failure_reason();
return res;
}

View File

@ -5,14 +5,14 @@
* feature: use FreeImage.dll if it's available
* bugfix: fix bug in right or bottom cursor region due to internal cleanup
Version 0.93: Beta 4
Version 0.93: Beta 4 (2007-07-10)
* bugfix: alter stb_image to support jpegs with weird header blocks
* bugfix: exit after printing directory error message
* bugfix: change naming of frame/border variables
* bugfix: ESC when showing help clears help, rather than exiting
* internal: clean up registry code to halve registry ops
Version 0.92: Beta 3
Version 0.92: Beta 3 (2007-07-03)
* internal: replace Sleep()-based thread-joining code with synchronization primitive
* internal: change work queue internals to use stb_mutex
* internal: change stb_mutex from using win32 semaphore to using CRITICAL_SECTION

3880
stb.h

File diff suppressed because it is too large Load Diff

View File

@ -2174,7 +2174,7 @@ static int bmp_test(void)
get16le(); // discard reserved
get32le(); // discard data offset
sz = get32le();
if (sz == 12 || sz == 40 || sz == 108) return 1;
if (sz == 12 || sz == 40 || sz == 56 || sz == 108) return 1;
return 0;
}
@ -2247,10 +2247,15 @@ static stbi_uc *bmp_load(int *x, int *y, int *comp, int req_comp)
get16le(); // discard reserved
offset = get32le();
hsz = get32le();
if (hsz != 12 && hsz != 40 && hsz != 108) return ep("unknown BMP", "BMP type not supported: unknown");
if (hsz != 12 && hsz != 40 && hsz != 56 && hsz != 108) return ep("unknown BMP", "BMP type not supported: unknown");
failure_reason = "bad BMP";
if (hsz == 12) {
img_x = get16le();
img_y = get16le();
} else {
img_x = get32le();
img_y = get32le();
}
if (get16le() != 1) return 0;
bpp = get16le();
if (bpp == 1) return ep("monochrome", "BMP type not supported: 1-bit");
@ -2260,15 +2265,22 @@ static stbi_uc *bmp_load(int *x, int *y, int *comp, int req_comp)
if (bpp < 24)
psize = (offset - 14 - 24) / 3;
} else {
compress = get32();
compress = get32le();
if (compress == 1 || compress == 2) return ep("BMP RLE", "BMP type not supported: RLE");
get32le(); // discard sizeof
get32le(); // discard hres
get32le(); // discard vres
get32le(); // discard colorsused
get32le(); // discard max important
if (hsz == 40) {
if (hsz == 40 || hsz == 56) {
if (hsz == 56) {
get32le();
get32le();
get32le();
get32le();
}
if (bpp == 16 || bpp == 32) {
mr = mg = mb = 0;
if (compress == 0) {
if (bpp == 32) {
mr = 0xff << 16;
@ -2283,6 +2295,11 @@ static stbi_uc *bmp_load(int *x, int *y, int *comp, int req_comp)
mr = get32le();
mg = get32le();
mb = get32le();
// not documented, but generated by photoshop and handled by mspaint
if (mr == mg && mg == mb) {
// ?!?!?
return NULL;
}
} else
return NULL;
}