From 9e0f63ad87038c77658480473b46d330b6953127 Mon Sep 17 00:00:00 2001 From: "nothings.org" Date: Tue, 10 Jul 2007 09:48:36 +0000 Subject: [PATCH] version 0.93 changes --- imv.c | 84 ++++++++++++++++++++++++++--------------------------- notes.txt | 7 +++++ stb_image.c | 17 ++++++++++- version.bat | 2 +- 4 files changed, 65 insertions(+), 45 deletions(-) diff --git a/imv.c b/imv.c index 352b1cc..d110605 100644 --- a/imv.c +++ b/imv.c @@ -540,7 +540,7 @@ int upsample_cubic = TRUE; // declare with extra bytes so we can print the version number into it char helptext_center[88] = "imv(stb)\n" - "Copyright 2007 Sean Barret\n" + "Copyright 2007 Sean Barrett\n" "http://code.google.com/p/stb-imv\n" "version " ; @@ -556,8 +556,8 @@ char helptext_left[] = " (CTRL-) O: open image\n" " P: change preferences\n" " F: toggle frame\n" - "SHIFT-F: toggle white stripe in frame\n" - "CTRL-F: toggle both\n" + "SHIFT-F: toggle frame but keep stripe\n" + " CTRL-F: toggle white stripe in frame\n" " L: toggle filename label\n" "F1, H, ?: help" ; @@ -1110,7 +1110,7 @@ void init_filelist(void) } image_files = stb_readdir_files_mask(path_to_file, "*.jpg;*.jpeg;*.png;*.bmp"); - if (image_files == NULL) error("Error: couldn't read directory."); + if (image_files == NULL) { error("Error: couldn't read directory."); exit(0); } // given the array of filenames, build an equivalent fileinfo array stb_arr_setlen(fileinfo, stb_arr_len(image_files)); @@ -1623,58 +1623,51 @@ void mouse(UINT ev, int x, int y) static unsigned int physmem; // available physical memory according to GlobalMemoryStatus char *reg_root = "Software\\SilverSpaceship\\imv"; +HKEY zreg; + int reg_get(char *str, void *data, int len) { - static char buffer[128]; - int result=0; - HKEY z=0; - if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, reg_root, 0, KEY_READ, &z)) - { - unsigned int type; - if (ERROR_SUCCESS == RegQueryValueEx(z, str, 0, &type, data, &len)) - if (type == REG_BINARY) - result = 1; - } - if (z) - RegCloseKey(z); - return result; + unsigned int type; + if (ERROR_SUCCESS == RegQueryValueEx(zreg, str, 0, &type, data, &len)) + if (type == REG_BINARY) + return TRUE; + return FALSE; } int reg_set(char *str, void *data, int len) { - int result = 0; - HKEY z=0; - if (ERROR_SUCCESS == RegCreateKeyEx(HKEY_LOCAL_MACHINE, reg_root, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &z, NULL)) - { - if (ERROR_SUCCESS == RegSetValueEx(z, str, 0, REG_BINARY, data, len)) - result = 1; - } - if (z) - RegCloseKey(z); - return result; + return (ERROR_SUCCESS == RegSetValueEx(zreg, str, 0, REG_BINARY, data, len)); } // we use very short strings for these to avoid wasting space, since // people shouldn't be mucking with them directly anyway! void reg_save(void) { - int temp = max_cache_bytes >> 20; - reg_set("ac", &alpha_background, 6); - reg_set("up", &upsample_cubic, 4); - reg_set("cache", &temp, 4); - reg_set("lfs", &label_font_height, 4); - reg_set("label", &show_label, 4); + if (ERROR_SUCCESS == RegCreateKeyEx(HKEY_LOCAL_MACHINE, reg_root, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &zreg, NULL)) + { + int temp = max_cache_bytes >> 20; + reg_set("ac", &alpha_background, 6); + reg_set("up", &upsample_cubic, 4); + reg_set("cache", &temp, 4); + reg_set("lfs", &label_font_height, 4); + reg_set("label", &show_label, 4); + RegCloseKey(zreg); + } } void reg_load(void) { int temp; - reg_get("ac", &alpha_background, 6); - reg_get("up", &upsample_cubic, 4); - reg_get("lfs", &label_font_height, 4); - reg_get("label", &show_label, 4); - if (reg_get("cache", &temp, 4)) - max_cache_bytes = temp << 20; + if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, reg_root, 0, KEY_READ, &zreg)) + { + reg_get("ac", &alpha_background, 6); + reg_get("up", &upsample_cubic, 4); + reg_get("lfs", &label_font_height, 4); + reg_get("label", &show_label, 4); + if (reg_get("cache", &temp, 4)) + max_cache_bytes = temp << 20; + RegCloseKey(zreg); + } } static HWND dialog; // preferences dialog @@ -1957,8 +1950,13 @@ int WINAPI MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) | (GetKeyState(VK_CONTROL) < 0 ? MY_CTRL : 0); code += wParam; switch (wParam) { + case 27: - exit(0); + if (!show_help) + exit(0); + show_help = !show_help; + InvalidateRect(win, NULL, FALSE); + break; case ' ': // space advance(1); @@ -2004,17 +2002,17 @@ int WINAPI MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) InvalidateRect(win, NULL, FALSE); break; - case 'F' | MY_SHIFT: + case 'F' | MY_CTRL: extra_border = !extra_border; if (cur) frame(cur); InvalidateRect(win, NULL, FALSE); break; - case 'F': + case 'F' | MY_SHIFT: toggle_frame(); break; - case 'F' | MY_CTRL: + case 'F': toggle_frame(); extra_border = show_frame; if (cur) frame(cur); diff --git a/notes.txt b/notes.txt index f2818e6..9b29030 100644 --- a/notes.txt +++ b/notes.txt @@ -1,3 +1,10 @@ + Version 0.93: Beta 4 + * 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 * internal: replace Sleep()-based thread-joining code with synchronization primitive * internal: change work queue internals to use stb_mutex diff --git a/stb_image.c b/stb_image.c index a821c7c..dff4ce6 100644 --- a/stb_image.c +++ b/stb_image.c @@ -1,4 +1,4 @@ -/* stbi-0.94 - public domain JPEG/PNG reader - http://nothings.org/stb_image.c +/* stbi-0.95 - public domain JPEG/PNG reader - http://nothings.org/stb_image.c when you control the images you're loading QUICK NOTES: @@ -16,6 +16,7 @@ PSD loader history: + 0.95 during header scan, seek to markers in case of padding 0.94 STBI_NO_STDIO to disable stdio usage; rename all #defines the same 0.93 handle jpegtran output; verbose errors 0.92 read 4,8,16,24,32-bit BMP files of several formats @@ -333,6 +334,15 @@ static int get8(void) return 0; } +static int at_eof(void) +{ +#ifndef STBI_NO_STDIO + if (img_file) + return feof(img_file); +#endif + return img_buffer >= img_buffer_end; +} + static uint8 get8u(void) { return (uint8) get8(); @@ -1072,6 +1082,11 @@ static int decode_jpeg_header(int scan) while (!SOF(m)) { if (!process_marker(m)) return 0; m = get_marker(); + while (m == MARKER_none) { + // some files have extra padding after their blocks, so ok, we'll scan + if (at_eof()) return e("no SOF", "Corrupt JPEG"); + m = get_marker(); + } } if (!process_frame_header(scan)) return 0; return 1; diff --git a/version.bat b/version.bat index 4efce96..394a10f 100644 --- a/version.bat +++ b/version.bat @@ -1 +1 @@ -set VERSION="0.92" +set VERSION="0.93"