79 #define PROGNAME "rpng-win" 80 #define LONGNAME "Simple PNG Viewer for Windows" 81 #define VERSION "2.01 of 16 March 2008" 100 #define alpha_composite(composite, fg, alpha, bg) { \ 101 ush temp = ((ush)(fg)*(ush)(alpha) + \ 102 (ush)(bg)*(ush)(255 - (ush)(alpha)) + (ush)128); \ 103 (composite) = (uch)((temp + (temp >> 8)) >> 8); \ 108 static int rpng_win_create_window(HINSTANCE hInst,
int showmode);
109 static int rpng_win_display_image(
void);
110 static void rpng_win_cleanup(
void);
114 static char titlebar[1024];
121 static uch bg_red=0, bg_green=0, bg_blue=0;
123 static double display_exponent;
126 static int image_channels;
130 static ulg wimage_rowbytes;
132 static uch *wimage_data;
133 static BITMAPINFOHEADER *bmih;
135 static HWND global_hwnd;
140 int WINAPI
WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, PSTR cmd,
int showmode)
143 char *
p, *
q, **argv = args;
149 double CRT_exponent = 2.2;
150 double default_display_exponent;
163 freopen(
"CONOUT$",
"a", stderr);
164 freopen(
"CONOUT$",
"a", stdout);
175 LUT_exponent = 1.0 / 2.2;
181 LUT_exponent = 1.0 / 1.7;
184 infile = fopen(
"/etc/config/system.glGammaVal",
"r");
188 fgets(tmpline, 80,
infile);
190 sgi_gamma = atof(tmpline);
192 LUT_exponent = 1.0 / sgi_gamma;
194 #elif defined(Macintosh) 195 LUT_exponent = 1.8 / 2.61;
205 default_display_exponent = LUT_exponent * CRT_exponent;
213 if ((p = getenv(
"SCREEN_GAMMA")) !=
NULL)
214 display_exponent = atof(p);
216 display_exponent = default_display_exponent;
232 argv[argc++] = q =
p;
233 while (*q && *q !=
' ')
246 while (*++argv && !error) {
247 if (!strncmp(*argv,
"-gamma", 2)) {
251 display_exponent = atof(*argv);
252 if (display_exponent <= 0.0)
255 }
else if (!strncmp(*argv,
"-bgcolor", 2)) {
260 if (strlen(bgstr) != 7 || bgstr[0] !=
'#')
287 "Usage: %s [-gamma exp] [-bgcolor bg] file.png\n" 288 " exp \ttransfer-function exponent (``gamma'') of the display\n" 289 "\t\t system in floating-point format (e.g., ``%.1f''); equal\n" 290 "\t\t to the product of the lookup-table exponent (varies)\n" 291 "\t\t and the CRT exponent (usually 2.2); must be positive\n" 292 " bg \tdesired background color in 7-character hex RGB format\n" 293 "\t\t (e.g., ``#ff7700'' for orange: same as HTML colors);\n" 294 "\t\t used with transparent images\n" 295 "\nPress Q, Esc or mouse button 1 after image is displayed to quit.\n" 296 "Press Q or Esc to quit this usage screen.\n" 297 "\n",
PROGNAME, default_display_exponent);
300 while (ch !=
'q' && ch !=
'Q' && ch != 0x1B);
313 ": [%s] is not a PNG file: incorrect signature\n",
318 ": [%s] has bad IHDR (libpng longjmp)\n",
filename);
321 fprintf(stderr,
PROGNAME ": insufficient memory\n");
325 ": unknown readpng_init() error\n");
338 fprintf(stderr,
PROGNAME ": aborting.\n");
341 while (ch !=
'q' && ch !=
'Q' && ch != 0x1B);
346 "\n [console window: closing this window will terminate %s]\n\n",
353 alen = strlen(appname);
355 if (alen + flen + 3 > 1023)
356 sprintf(titlebar,
"%s: ...%s", appname,
filename+(alen+flen+6-1023));
358 sprintf(titlebar,
"%s: %s", appname,
filename);
368 sscanf(bgstr+1,
"%2x%2x%2x", &r, &g, &b);
375 ": libpng error while checking for background color\n");
383 if (rpng_win_create_window(hInst, showmode))
389 Trace((stderr,
"calling readpng_get_image()\n"))
392 Trace((stderr,
"done with readpng_get_image()\n"))
402 fprintf(stderr,
PROGNAME ": unable to decode PNG image\n");
409 Trace((stderr,
"calling rpng_win_display_image()\n"))
410 if (rpng_win_display_image()) {
414 Trace((stderr,
"done with rpng_win_display_image()\n"))
420 "Done. Press Q, Esc or mouse button 1 (within image window) to quit.\n");
423 while (GetMessage(&msg,
NULL, 0, 0)) {
424 TranslateMessage(&msg);
425 DispatchMessage(&msg);
440 static int rpng_win_create_window(HINSTANCE hInst,
int showmode)
443 int extra_width, extra_height;
453 wimage_rowbytes = ((3*
image_width + 3L) >> 2) << 2;
455 if (!(dib = (
uch *)
malloc(
sizeof(BITMAPINFOHEADER) +
468 memset(dib, 0,
sizeof(BITMAPINFOHEADER));
469 bmih = (BITMAPINFOHEADER *)dib;
470 bmih->biSize =
sizeof(BITMAPINFOHEADER);
472 bmih->biHeight = -((
long)image_height);
474 bmih->biBitCount = 24;
475 bmih->biCompression = 0;
476 wimage_data = dib +
sizeof(BITMAPINFOHEADER);
483 dest = wimage_data + j*wimage_rowbytes;
495 memset(&wndclass, 0,
sizeof(wndclass));
497 wndclass.cbSize =
sizeof(wndclass);
498 wndclass.style = CS_HREDRAW | CS_VREDRAW;
500 wndclass.hInstance = hInst;
501 wndclass.hIcon = LoadIcon(
NULL, IDI_APPLICATION);
502 wndclass.hCursor = LoadCursor(
NULL, IDC_ARROW);
503 wndclass.hbrBackground = (HBRUSH)GetStockObject(DKGRAY_BRUSH);
504 wndclass.lpszMenuName =
NULL;
505 wndclass.lpszClassName = progname;
506 wndclass.hIconSm = LoadIcon(
NULL, IDI_APPLICATION);
508 RegisterClassEx(&wndclass);
514 extra_width = 2*(GetSystemMetrics(SM_CXBORDER) +
515 GetSystemMetrics(SM_CXDLGFRAME));
516 extra_height = 2*(GetSystemMetrics(SM_CYBORDER) +
517 GetSystemMetrics(SM_CYDLGFRAME)) +
518 GetSystemMetrics(SM_CYCAPTION);
520 global_hwnd = CreateWindow(progname, titlebar, WS_OVERLAPPEDWINDOW,
521 CW_USEDEFAULT, CW_USEDEFAULT,
image_width+extra_width,
524 ShowWindow(global_hwnd, showmode);
525 UpdateWindow(global_hwnd);
535 static int rpng_win_display_image()
543 Trace((stderr,
"beginning display loop (image_channels == %d)\n",
545 Trace((stderr,
"(width = %ld, rowbytes = %ld, wimage_rowbytes = %d)\n",
557 dest = wimage_data + row*wimage_rowbytes;
558 if (image_channels == 3) {
593 if (((row+1) & 0xf) == 0) {
595 rect.top = (LONG)lastrow;
597 rect.bottom = (LONG)lastrow + 16L;
598 InvalidateRect(global_hwnd, &rect,
FALSE);
599 UpdateWindow(global_hwnd);
604 Trace((stderr,
"calling final image-flush routine\n"))
605 if (lastrow < image_height) {
607 rect.top = (LONG)lastrow;
609 rect.bottom = (LONG)image_height;
610 InvalidateRect(global_hwnd, &rect,
FALSE);
611 UpdateWindow(global_hwnd);
627 static void rpng_win_cleanup()
656 hdc = BeginPaint(hwnd, &ps);
661 wimage_data, (BITMAPINFO *)bmih,
683 return DefWindowProc(hwnd, iMsg, wP, lP);
LRESULT CALLBACK rpng_win_wndproc(HWND, UINT, WPARAM, LPARAM)
GLboolean GLboolean GLboolean GLboolean a
GLdouble GLdouble GLdouble GLdouble q
GLboolean GLboolean GLboolean b
GLenum GLenum GLvoid * row
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, PSTR cmd, int showmode)
GLdouble GLdouble GLdouble r
uch * readpng_get_image(double display_exponent, int *pChannels, ulg *pRowbytes)
typedef long(ZCALLBACK *tell_file_func) OF((voidpf opaque
void readpng_version_info(void)
#define alpha_composite(composite, fg, alpha, bg)
int readpng_get_bgcolor(uch *red, uch *green, uch *blue)
void readpng_cleanup(int free_image_data)
int readpng_init(FILE *infile, ulg *pWidth, ulg *pHeight)