mirror of
https://git.code.sf.net/p/libpng/code.git
synced 2025-07-10 18:04:09 +02:00
[devel] Changed "// ..." comments to "/* .. */" in the visupng project.
This commit is contained in:
parent
ad8b7b71b4
commit
ef43c17bfe
@ -1,12 +1,13 @@
|
||||
//-------------------------------------
|
||||
// PNGFILE.C -- Image File Functions
|
||||
//-------------------------------------
|
||||
|
||||
// Copyright 2000, Willem van Schaik.
|
||||
//
|
||||
// This code is released under the libpng license.
|
||||
// For conditions of distribution and use, see the disclaimer
|
||||
// and license in png.h
|
||||
/*-------------------------------------
|
||||
* PNGFILE.C -- Image File Functions
|
||||
*-------------------------------------
|
||||
*
|
||||
* Copyright 2000, Willem van Schaik.
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
* and license in png.h
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
#include <commdlg.h>
|
||||
@ -28,7 +29,7 @@ static png_structp png_ptr = NULL;
|
||||
static png_infop info_ptr = NULL;
|
||||
|
||||
|
||||
// cexcept interface
|
||||
/* cexcept interface */
|
||||
|
||||
static void
|
||||
png_cexcept_error(png_structp png_ptr, png_const_charp msg)
|
||||
@ -43,7 +44,7 @@ png_cexcept_error(png_structp png_ptr, png_const_charp msg)
|
||||
}
|
||||
}
|
||||
|
||||
// Windows open-file functions
|
||||
/* Windows open-file functions */
|
||||
|
||||
void PngFileInitialize (HWND hwnd)
|
||||
{
|
||||
@ -57,13 +58,13 @@ void PngFileInitialize (HWND hwnd)
|
||||
ofn.lpstrCustomFilter = NULL;
|
||||
ofn.nMaxCustFilter = 0;
|
||||
ofn.nFilterIndex = 0;
|
||||
ofn.lpstrFile = NULL; // Set in Open and Close functions
|
||||
ofn.lpstrFile = NULL; /* Set in Open and Close functions */
|
||||
ofn.nMaxFile = MAX_PATH;
|
||||
ofn.lpstrFileTitle = NULL; // Set in Open and Close functions
|
||||
ofn.lpstrFileTitle = NULL; /* Set in Open and Close functions */
|
||||
ofn.nMaxFileTitle = MAX_PATH;
|
||||
ofn.lpstrInitialDir = NULL;
|
||||
ofn.lpstrTitle = NULL;
|
||||
ofn.Flags = 0; // Set in Open and Close functions
|
||||
ofn.Flags = 0; /* Set in Open and Close functions */
|
||||
ofn.nFileOffset = 0;
|
||||
ofn.nFileExtension = 0;
|
||||
ofn.lpstrDefExt = TEXT ("png");
|
||||
@ -92,7 +93,7 @@ BOOL PngFileSaveDlg (HWND hwnd, PTSTR pstrFileName, PTSTR pstrTitleName)
|
||||
return GetSaveFileName (&ofn);
|
||||
}
|
||||
|
||||
// PNG image handler functions
|
||||
/* PNG image handler functions */
|
||||
|
||||
BOOL PngLoadImage (PTSTR pstrFileName, png_byte **ppbImageData,
|
||||
int *piWidth, int *piHeight, int *piChannels, png_color *pBkgColor)
|
||||
@ -109,7 +110,7 @@ BOOL PngLoadImage (PTSTR pstrFileName, png_byte **ppbImageData,
|
||||
static png_byte **ppbRowPointers = NULL;
|
||||
int i;
|
||||
|
||||
// open the PNG input file
|
||||
/* open the PNG input file */
|
||||
|
||||
if (!pstrFileName)
|
||||
{
|
||||
@ -123,7 +124,7 @@ BOOL PngLoadImage (PTSTR pstrFileName, png_byte **ppbImageData,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// first check the eight byte PNG signature
|
||||
/* first check the eight byte PNG signature */
|
||||
|
||||
fread(pbSig, 1, 8, pfFile);
|
||||
if (png_sig_cmp(pbSig, 0, 8))
|
||||
@ -132,7 +133,7 @@ BOOL PngLoadImage (PTSTR pstrFileName, png_byte **ppbImageData,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// create the two png(-info) structures
|
||||
/* create the two png(-info) structures */
|
||||
|
||||
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL,
|
||||
(png_error_ptr)png_cexcept_error, (png_error_ptr)NULL);
|
||||
@ -153,7 +154,7 @@ BOOL PngLoadImage (PTSTR pstrFileName, png_byte **ppbImageData,
|
||||
Try
|
||||
{
|
||||
|
||||
// initialize the png structure
|
||||
/* initialize the png structure */
|
||||
|
||||
#ifdef PNG_STDIO_SUPPORTED
|
||||
png_init_io(png_ptr, pfFile);
|
||||
@ -163,17 +164,17 @@ BOOL PngLoadImage (PTSTR pstrFileName, png_byte **ppbImageData,
|
||||
|
||||
png_set_sig_bytes(png_ptr, 8);
|
||||
|
||||
// read all PNG info up to image data
|
||||
/* read all PNG info up to image data */
|
||||
|
||||
png_read_info(png_ptr, info_ptr);
|
||||
|
||||
// get width, height, bit-depth and color-type
|
||||
/* get width, height, bit-depth and color-type */
|
||||
|
||||
png_get_IHDR(png_ptr, info_ptr, piWidth, piHeight, &iBitDepth,
|
||||
&iColorType, NULL, NULL, NULL);
|
||||
|
||||
// expand images of all color-type and bit-depth to 3x8 bit RGB images
|
||||
// let the library process things like alpha, transparency, background
|
||||
/* expand images of all color-type and bit-depth to 3x8-bit RGB */
|
||||
/* let the library process alpha, transparency, background, etc. */
|
||||
|
||||
#ifdef PNG_READ_16_TO_8_SUPPORTED
|
||||
if (iBitDepth == 16)
|
||||
@ -193,7 +194,7 @@ BOOL PngLoadImage (PTSTR pstrFileName, png_byte **ppbImageData,
|
||||
iColorType == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||
png_set_gray_to_rgb(png_ptr);
|
||||
|
||||
// set the background color to draw transparent and alpha images over.
|
||||
/* set the background color to draw transparent and alpha images over */
|
||||
if (png_get_bKGD(png_ptr, info_ptr, &pBackground))
|
||||
{
|
||||
png_set_background(png_ptr, pBackground, PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
|
||||
@ -206,28 +207,28 @@ BOOL PngLoadImage (PTSTR pstrFileName, png_byte **ppbImageData,
|
||||
pBkgColor = NULL;
|
||||
}
|
||||
|
||||
// if required set gamma conversion
|
||||
/* if required set gamma conversion */
|
||||
if (png_get_gAMA(png_ptr, info_ptr, &dGamma))
|
||||
png_set_gamma(png_ptr, (double) 2.2, dGamma);
|
||||
|
||||
// after the transformations have been registered update info_ptr data
|
||||
/* after the transformations are registered, update info_ptr data */
|
||||
|
||||
png_read_update_info(png_ptr, info_ptr);
|
||||
|
||||
// get again width, height and the new bit-depth and color-type
|
||||
/* get again width, height and the new bit-depth and color-type */
|
||||
|
||||
png_get_IHDR(png_ptr, info_ptr, piWidth, piHeight, &iBitDepth,
|
||||
&iColorType, NULL, NULL, NULL);
|
||||
|
||||
|
||||
// row_bytes is the width x number of channels
|
||||
/* row_bytes is the width x number of channels */
|
||||
|
||||
ulRowBytes = png_get_rowbytes(png_ptr, info_ptr);
|
||||
ulChannels = png_get_channels(png_ptr, info_ptr);
|
||||
|
||||
*piChannels = ulChannels;
|
||||
|
||||
// now we can allocate memory to store the image
|
||||
/* now we can allocate memory to store the image */
|
||||
|
||||
if (pbImageData)
|
||||
{
|
||||
@ -241,7 +242,7 @@ BOOL PngLoadImage (PTSTR pstrFileName, png_byte **ppbImageData,
|
||||
}
|
||||
*ppbImageData = pbImageData;
|
||||
|
||||
// and allocate memory for an array of row-pointers
|
||||
/* and allocate memory for an array of row-pointers */
|
||||
|
||||
if ((ppbRowPointers = (png_bytepp) malloc((*piHeight)
|
||||
* sizeof(png_bytep))) == NULL)
|
||||
@ -249,25 +250,25 @@ BOOL PngLoadImage (PTSTR pstrFileName, png_byte **ppbImageData,
|
||||
png_error(png_ptr, "Visual PNG: out of memory");
|
||||
}
|
||||
|
||||
// set the individual row-pointers to point at the correct offsets
|
||||
/* set the individual row-pointers to point at the correct offsets */
|
||||
|
||||
for (i = 0; i < (*piHeight); i++)
|
||||
ppbRowPointers[i] = pbImageData + i * ulRowBytes;
|
||||
|
||||
// now we can go ahead and just read the whole image
|
||||
/* now we can go ahead and just read the whole image */
|
||||
|
||||
png_read_image(png_ptr, ppbRowPointers);
|
||||
|
||||
// read the additional chunks in the PNG file (not really needed)
|
||||
/* read the additional chunks in the PNG file (not really needed) */
|
||||
|
||||
png_read_end(png_ptr, NULL);
|
||||
|
||||
// and we're done
|
||||
/* and we're done */
|
||||
|
||||
free (ppbRowPointers);
|
||||
ppbRowPointers = NULL;
|
||||
|
||||
// yepp, done
|
||||
/* yepp, done */
|
||||
}
|
||||
|
||||
Catch (msg)
|
||||
@ -301,7 +302,7 @@ BOOL PngSaveImage (PTSTR pstrFileName, png_byte *pDiData,
|
||||
static png_byte **ppbRowPointers = NULL;
|
||||
int i;
|
||||
|
||||
// open the PNG output file
|
||||
/* open the PNG output file */
|
||||
|
||||
if (!pstrFileName)
|
||||
return FALSE;
|
||||
@ -309,7 +310,7 @@ BOOL PngSaveImage (PTSTR pstrFileName, png_byte *pDiData,
|
||||
if (!(pfFile = fopen(pstrFileName, "wb")))
|
||||
return FALSE;
|
||||
|
||||
// prepare the standard PNG structures
|
||||
/* prepare the standard PNG structures */
|
||||
|
||||
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL,
|
||||
(png_error_ptr)png_cexcept_error, (png_error_ptr)NULL);
|
||||
@ -328,7 +329,7 @@ BOOL PngSaveImage (PTSTR pstrFileName, png_byte *pDiData,
|
||||
|
||||
Try
|
||||
{
|
||||
// initialize the png structure
|
||||
/* initialize the png structure */
|
||||
|
||||
#ifdef PNG_STDIO_SUPPORTED
|
||||
png_init_io(png_ptr, pfFile);
|
||||
@ -336,52 +337,52 @@ BOOL PngSaveImage (PTSTR pstrFileName, png_byte *pDiData,
|
||||
png_set_write_fn(png_ptr, (png_voidp)pfFile, png_write_data, png_flush);
|
||||
#endif
|
||||
|
||||
// we're going to write a very simple 3x8 bit RGB image
|
||||
/* we're going to write a very simple 3x8-bit RGB image */
|
||||
|
||||
png_set_IHDR(png_ptr, info_ptr, iWidth, iHeight, ciBitDepth,
|
||||
PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE,
|
||||
PNG_FILTER_TYPE_BASE);
|
||||
|
||||
// write the file header information
|
||||
/* write the file header information */
|
||||
|
||||
png_write_info(png_ptr, info_ptr);
|
||||
|
||||
// swap the BGR pixels in the DiData structure to RGB
|
||||
/* swap the BGR pixels in the DiData structure to RGB */
|
||||
|
||||
png_set_bgr(png_ptr);
|
||||
|
||||
// row_bytes is the width x number of channels
|
||||
/* row_bytes is the width x number of channels */
|
||||
|
||||
ulRowBytes = iWidth * ciChannels;
|
||||
|
||||
// we can allocate memory for an array of row-pointers
|
||||
/* we can allocate memory for an array of row-pointers */
|
||||
|
||||
if ((ppbRowPointers = (png_bytepp) malloc(iHeight * sizeof(png_bytep))) == NULL)
|
||||
Throw "Visualpng: Out of memory";
|
||||
|
||||
// set the individual row-pointers to point at the correct offsets
|
||||
/* set the individual row-pointers to point at the correct offsets */
|
||||
|
||||
for (i = 0; i < iHeight; i++)
|
||||
ppbRowPointers[i] = pDiData + i * (((ulRowBytes + 3) >> 2) << 2);
|
||||
|
||||
// write out the entire image data in one call
|
||||
/* write out the entire image data in one call */
|
||||
|
||||
png_write_image (png_ptr, ppbRowPointers);
|
||||
|
||||
// write the additional chunks to the PNG file (not really needed)
|
||||
/* write the additional chunks to the PNG file (not really needed) */
|
||||
|
||||
png_write_end(png_ptr, info_ptr);
|
||||
|
||||
// and we're done
|
||||
/* and we're done */
|
||||
|
||||
free (ppbRowPointers);
|
||||
ppbRowPointers = NULL;
|
||||
|
||||
// clean up after the write, and free any memory allocated
|
||||
/* clean up after the write, and free any memory allocated */
|
||||
|
||||
png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
|
||||
|
||||
// yepp, done
|
||||
/* yepp, done */
|
||||
}
|
||||
|
||||
Catch (msg)
|
||||
@ -443,6 +444,7 @@ png_flush(png_structp png_ptr)
|
||||
|
||||
#endif
|
||||
|
||||
//-----------------
|
||||
// end of source
|
||||
//-----------------
|
||||
/*-----------------
|
||||
* end of source
|
||||
*-----------------
|
||||
*/
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
//------------------------------------------
|
||||
// PNGFILE.H -- Header File for pngfile.c
|
||||
//------------------------------------------
|
||||
/*------------------------------------------*/
|
||||
/* PNGFILE.H -- Header File for pngfile.c*/
|
||||
/*------------------------------------------*/
|
||||
|
||||
// Copyright 2000, Willem van Schaik.
|
||||
/* Copyright 2000, Willem van Schaik.*/
|
||||
|
||||
// This code is released under the libpng license.
|
||||
// For conditions of distribution and use, see the disclaimer
|
||||
// and license in png.h
|
||||
/* This code is released under the libpng license.*/
|
||||
/* For conditions of distribution and use, see the disclaimer*/
|
||||
/* and license in png.h*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
@ -1,41 +1,42 @@
|
||||
//------------------------------------
|
||||
// VisualPng.C -- Shows a PNG image
|
||||
//------------------------------------
|
||||
/*------------------------------------
|
||||
* VisualPng.C -- Shows a PNG image
|
||||
*------------------------------------
|
||||
*
|
||||
* Copyright 2000, Willem van Schaik.
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
* and license in png.h
|
||||
*/
|
||||
|
||||
// Copyright 2000, Willem van Schaik.
|
||||
/* switches */
|
||||
|
||||
// This code is released under the libpng license.
|
||||
// For conditions of distribution and use, see the disclaimer
|
||||
// and license in png.h
|
||||
|
||||
// switches
|
||||
|
||||
// defines
|
||||
/* defines */
|
||||
|
||||
#define PROGNAME "VisualPng"
|
||||
#define LONGNAME "Win32 Viewer for PNG-files"
|
||||
#define VERSION "1.0 of 2000 June 07"
|
||||
|
||||
// constants
|
||||
/* constants */
|
||||
|
||||
#define MARGIN 8
|
||||
|
||||
// standard includes
|
||||
/* standard includes */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <windows.h>
|
||||
|
||||
// application includes
|
||||
/* application includes */
|
||||
|
||||
#include "png.h"
|
||||
#include "pngfile.h"
|
||||
#include "resource.h"
|
||||
|
||||
// macros
|
||||
/* macros */
|
||||
|
||||
// function prototypes
|
||||
/* function prototypes */
|
||||
|
||||
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
|
||||
BOOL CALLBACK AboutDlgProc (HWND, UINT, WPARAM, LPARAM) ;
|
||||
@ -65,14 +66,14 @@ BOOL FillBitmap (
|
||||
BYTE *pbImage, int cxImgSize, int cyImgSize, int cImgChannels,
|
||||
BOOL bStretched);
|
||||
|
||||
// a few global variables
|
||||
/* a few global variables */
|
||||
|
||||
static char *szProgName = PROGNAME;
|
||||
static char *szAppName = LONGNAME;
|
||||
static char *szIconName = PROGNAME;
|
||||
static char szCmdFileName [MAX_PATH];
|
||||
|
||||
// MAIN routine
|
||||
/* MAIN routine */
|
||||
|
||||
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
||||
PSTR szCmdLine, int iCmdShow)
|
||||
@ -90,7 +91,7 @@ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
||||
wndclass.hInstance = hInstance;
|
||||
wndclass.hIcon = LoadIcon (hInstance, szIconName) ;
|
||||
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
|
||||
wndclass.hbrBackground = NULL; // (HBRUSH) GetStockObject (GRAY_BRUSH);
|
||||
wndclass.hbrBackground = NULL; /* (HBRUSH) GetStockObject (GRAY_BRUSH); */
|
||||
wndclass.lpszMenuName = szProgName;
|
||||
wndclass.lpszClassName = szProgName;
|
||||
|
||||
@ -101,7 +102,7 @@ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
||||
return 0;
|
||||
}
|
||||
|
||||
// if filename given on commandline, store it
|
||||
/* if filename given on commandline, store it */
|
||||
if ((szCmdLine != NULL) && (*szCmdLine != '\0'))
|
||||
if (szCmdLine[0] == '"')
|
||||
strncpy (szCmdFileName, szCmdLine + 1, strlen(szCmdLine) - 2);
|
||||
@ -110,20 +111,20 @@ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
||||
else
|
||||
strcpy (szCmdFileName, "");
|
||||
|
||||
// calculate size of window-borders
|
||||
/* calculate size of window-borders */
|
||||
ixBorders = 2 * (GetSystemMetrics (SM_CXBORDER) +
|
||||
GetSystemMetrics (SM_CXDLGFRAME));
|
||||
iyBorders = 2 * (GetSystemMetrics (SM_CYBORDER) +
|
||||
GetSystemMetrics (SM_CYDLGFRAME)) +
|
||||
GetSystemMetrics (SM_CYCAPTION) +
|
||||
GetSystemMetrics (SM_CYMENUSIZE) +
|
||||
1; /* WvS: don't ask me why? */
|
||||
1; /* WvS: don't ask me why? */
|
||||
|
||||
hwnd = CreateWindow (szProgName, szAppName,
|
||||
WS_OVERLAPPEDWINDOW,
|
||||
CW_USEDEFAULT, CW_USEDEFAULT,
|
||||
512 + 2 * MARGIN + ixBorders, 384 + 2 * MARGIN + iyBorders,
|
||||
// CW_USEDEFAULT, CW_USEDEFAULT,
|
||||
/* CW_USEDEFAULT, CW_USEDEFAULT, */
|
||||
NULL, NULL, hInstance, NULL);
|
||||
|
||||
ShowWindow (hwnd, iCmdShow);
|
||||
@ -180,29 +181,29 @@ LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam,
|
||||
|
||||
strcpy (szImgPathName, "");
|
||||
|
||||
// in case we process file given on command-line
|
||||
/* in case we process file given on command-line */
|
||||
|
||||
if (szCmdFileName[0] != '\0')
|
||||
{
|
||||
strcpy (szImgPathName, szCmdFileName);
|
||||
|
||||
// read the other png-files in the directory for later
|
||||
// next/previous commands
|
||||
/* read the other png-files in the directory for later */
|
||||
/* next/previous commands */
|
||||
|
||||
BuildPngList (szImgPathName, &pPngFileList, &iPngFileCount,
|
||||
&iPngFileIndex);
|
||||
|
||||
// load the image from file
|
||||
/* load the image from file */
|
||||
|
||||
if (!LoadImageFile (hwnd, szImgPathName,
|
||||
&pbImage, &cxImgSize, &cyImgSize, &cImgChannels, &bkgColor))
|
||||
return 0;
|
||||
|
||||
// invalidate the client area for later update
|
||||
/* invalidate the client area for later update */
|
||||
|
||||
InvalidateRect (hwnd, NULL, TRUE);
|
||||
|
||||
// display the PNG into the DIBitmap
|
||||
/* display the PNG into the DIBitmap */
|
||||
|
||||
DisplayImage (hwnd, &pDib, &pDiData, cxWinSize, cyWinSize,
|
||||
pbImage, cxImgSize, cyImgSize, cImgChannels, bStretched);
|
||||
@ -214,11 +215,11 @@ LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam,
|
||||
cxWinSize = LOWORD (lParam);
|
||||
cyWinSize = HIWORD (lParam);
|
||||
|
||||
// invalidate the client area for later update
|
||||
/* invalidate the client area for later update */
|
||||
|
||||
InvalidateRect (hwnd, NULL, TRUE);
|
||||
|
||||
// display the PNG into the DIBitmap
|
||||
/* display the PNG into the DIBitmap */
|
||||
|
||||
DisplayImage (hwnd, &pDib, &pDiData, cxWinSize, cyWinSize,
|
||||
pbImage, cxImgSize, cyImgSize, cImgChannels, bStretched);
|
||||
@ -242,28 +243,28 @@ LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam,
|
||||
{
|
||||
case IDM_FILE_OPEN:
|
||||
|
||||
// show the File Open dialog box
|
||||
/* show the File Open dialog box */
|
||||
|
||||
if (!PngFileOpenDlg (hwnd, szImgPathName, szTitleName))
|
||||
return 0;
|
||||
|
||||
// read the other png-files in the directory for later
|
||||
// next/previous commands
|
||||
/* read the other png-files in the directory for later */
|
||||
/* next/previous commands */
|
||||
|
||||
BuildPngList (szImgPathName, &pPngFileList, &iPngFileCount,
|
||||
&iPngFileIndex);
|
||||
|
||||
// load the image from file
|
||||
/* load the image from file */
|
||||
|
||||
if (!LoadImageFile (hwnd, szImgPathName,
|
||||
&pbImage, &cxImgSize, &cyImgSize, &cImgChannels, &bkgColor))
|
||||
return 0;
|
||||
|
||||
// invalidate the client area for later update
|
||||
/* invalidate the client area for later update */
|
||||
|
||||
InvalidateRect (hwnd, NULL, TRUE);
|
||||
|
||||
// display the PNG into the DIBitmap
|
||||
/* display the PNG into the DIBitmap */
|
||||
|
||||
DisplayImage (hwnd, &pDib, &pDiData, cxWinSize, cyWinSize,
|
||||
pbImage, cxImgSize, cyImgSize, cImgChannels, bStretched);
|
||||
@ -272,12 +273,12 @@ LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam,
|
||||
|
||||
case IDM_FILE_SAVE:
|
||||
|
||||
// show the File Save dialog box
|
||||
/* show the File Save dialog box */
|
||||
|
||||
if (!PngFileSaveDlg (hwnd, szImgPathName, szTitleName))
|
||||
return 0;
|
||||
|
||||
// save the PNG to a disk file
|
||||
/* save the PNG to a disk file */
|
||||
|
||||
SetCursor (LoadCursor (NULL, IDC_WAIT));
|
||||
ShowCursor (TRUE);
|
||||
@ -295,7 +296,7 @@ LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam,
|
||||
|
||||
case IDM_FILE_NEXT:
|
||||
|
||||
// read next entry in the directory
|
||||
/* read next entry in the directory */
|
||||
|
||||
if (SearchPngList (pPngFileList, iPngFileCount, &iPngFileIndex,
|
||||
NULL, szImgPathName))
|
||||
@ -303,17 +304,17 @@ LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam,
|
||||
if (strcmp (szImgPathName, "") == 0)
|
||||
return 0;
|
||||
|
||||
// load the image from file
|
||||
/* load the image from file */
|
||||
|
||||
if (!LoadImageFile (hwnd, szImgPathName, &pbImage,
|
||||
&cxImgSize, &cyImgSize, &cImgChannels, &bkgColor))
|
||||
return 0;
|
||||
|
||||
// invalidate the client area for later update
|
||||
/* invalidate the client area for later update */
|
||||
|
||||
InvalidateRect (hwnd, NULL, TRUE);
|
||||
|
||||
// display the PNG into the DIBitmap
|
||||
/* display the PNG into the DIBitmap */
|
||||
|
||||
DisplayImage (hwnd, &pDib, &pDiData, cxWinSize, cyWinSize,
|
||||
pbImage, cxImgSize, cyImgSize, cImgChannels, bStretched);
|
||||
@ -323,7 +324,7 @@ LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam,
|
||||
|
||||
case IDM_FILE_PREVIOUS:
|
||||
|
||||
// read previous entry in the directory
|
||||
/* read previous entry in the directory */
|
||||
|
||||
if (SearchPngList (pPngFileList, iPngFileCount, &iPngFileIndex,
|
||||
szImgPathName, NULL))
|
||||
@ -332,17 +333,17 @@ LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam,
|
||||
if (strcmp (szImgPathName, "") == 0)
|
||||
return 0;
|
||||
|
||||
// load the image from file
|
||||
/* load the image from file */
|
||||
|
||||
if (!LoadImageFile (hwnd, szImgPathName, &pbImage, &cxImgSize,
|
||||
&cyImgSize, &cImgChannels, &bkgColor))
|
||||
return 0;
|
||||
|
||||
// invalidate the client area for later update
|
||||
/* invalidate the client area for later update */
|
||||
|
||||
InvalidateRect (hwnd, NULL, TRUE);
|
||||
|
||||
// display the PNG into the DIBitmap
|
||||
/* display the PNG into the DIBitmap */
|
||||
|
||||
DisplayImage (hwnd, &pDib, &pDiData, cxWinSize, cyWinSize,
|
||||
pbImage, cxImgSize, cyImgSize, cImgChannels, bStretched);
|
||||
@ -352,9 +353,9 @@ LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam,
|
||||
|
||||
case IDM_FILE_EXIT:
|
||||
|
||||
// more cleanup needed...
|
||||
/* more cleanup needed... */
|
||||
|
||||
// free image buffer
|
||||
/* free image buffer */
|
||||
|
||||
if (pDib != NULL)
|
||||
{
|
||||
@ -362,7 +363,7 @@ LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam,
|
||||
pDib = NULL;
|
||||
}
|
||||
|
||||
// free file-list
|
||||
/* free file-list */
|
||||
|
||||
if (pPngFileList != NULL)
|
||||
{
|
||||
@ -370,7 +371,7 @@ LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam,
|
||||
pPngFileList = NULL;
|
||||
}
|
||||
|
||||
// let's go ...
|
||||
/* let's go ... */
|
||||
|
||||
exit (0);
|
||||
|
||||
@ -383,11 +384,11 @@ LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam,
|
||||
else
|
||||
CheckMenuItem (hMenu, IDM_OPTIONS_STRETCH, MF_UNCHECKED);
|
||||
|
||||
// invalidate the client area for later update
|
||||
/* invalidate the client area for later update */
|
||||
|
||||
InvalidateRect (hwnd, NULL, TRUE);
|
||||
|
||||
// display the PNG into the DIBitmap
|
||||
/* display the PNG into the DIBitmap */
|
||||
|
||||
DisplayImage (hwnd, &pDib, &pDiData, cxWinSize, cyWinSize,
|
||||
pbImage, cxImgSize, cyImgSize, cImgChannels, bStretched);
|
||||
@ -398,7 +399,7 @@ LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam,
|
||||
DialogBox (hInstance, TEXT ("AboutBox"), hwnd, AboutDlgProc) ;
|
||||
return 0;
|
||||
|
||||
} // end switch
|
||||
} /* end switch */
|
||||
|
||||
break;
|
||||
|
||||
@ -450,10 +451,10 @@ BOOL CALLBACK AboutDlgProc (HWND hDlg, UINT message,
|
||||
return FALSE ;
|
||||
}
|
||||
|
||||
//---------------
|
||||
// CenterAbout
|
||||
//---------------
|
||||
|
||||
/*---------------
|
||||
* CenterAbout
|
||||
*---------------
|
||||
*/
|
||||
BOOL CenterAbout (HWND hwndChild, HWND hwndParent)
|
||||
{
|
||||
RECT rChild, rParent, rWorkArea;
|
||||
@ -461,19 +462,19 @@ BOOL CenterAbout (HWND hwndChild, HWND hwndParent)
|
||||
int xNew, yNew;
|
||||
BOOL bResult;
|
||||
|
||||
// Get the Height and Width of the child window
|
||||
/* Get the Height and Width of the child window */
|
||||
GetWindowRect (hwndChild, &rChild);
|
||||
wChild = rChild.right - rChild.left;
|
||||
hChild = rChild.bottom - rChild.top;
|
||||
|
||||
// Get the Height and Width of the parent window
|
||||
/* Get the Height and Width of the parent window */
|
||||
GetWindowRect (hwndParent, &rParent);
|
||||
wParent = rParent.right - rParent.left;
|
||||
hParent = rParent.bottom - rParent.top;
|
||||
|
||||
// Get the limits of the 'workarea'
|
||||
/* Get the limits of the 'workarea' */
|
||||
bResult = SystemParametersInfo(
|
||||
SPI_GETWORKAREA, // system parameter to query or set
|
||||
SPI_GETWORKAREA, /* system parameter to query or set */
|
||||
sizeof(RECT),
|
||||
&rWorkArea,
|
||||
0);
|
||||
@ -483,7 +484,7 @@ BOOL CenterAbout (HWND hwndChild, HWND hwndParent)
|
||||
rWorkArea.bottom = GetSystemMetrics(SM_CYSCREEN);
|
||||
}
|
||||
|
||||
// Calculate new X position, then adjust for workarea
|
||||
/* Calculate new X position, then adjust for workarea */
|
||||
xNew = rParent.left + ((wParent - wChild) /2);
|
||||
if (xNew < rWorkArea.left) {
|
||||
xNew = rWorkArea.left;
|
||||
@ -491,7 +492,7 @@ BOOL CenterAbout (HWND hwndChild, HWND hwndParent)
|
||||
xNew = rWorkArea.right - wChild;
|
||||
}
|
||||
|
||||
// Calculate new Y position, then adjust for workarea
|
||||
/* Calculate new Y position, then adjust for workarea */
|
||||
yNew = rParent.top + ((hParent - hChild) /2);
|
||||
if (yNew < rWorkArea.top) {
|
||||
yNew = rWorkArea.top;
|
||||
@ -499,15 +500,15 @@ BOOL CenterAbout (HWND hwndChild, HWND hwndParent)
|
||||
yNew = rWorkArea.bottom - hChild;
|
||||
}
|
||||
|
||||
// Set it, and return
|
||||
/* Set it, and return */
|
||||
return SetWindowPos (hwndChild, NULL, xNew, yNew, 0, 0, SWP_NOSIZE |
|
||||
SWP_NOZORDER);
|
||||
}
|
||||
|
||||
//----------------
|
||||
// BuildPngList
|
||||
//----------------
|
||||
|
||||
/*----------------
|
||||
* BuildPngList
|
||||
*----------------
|
||||
*/
|
||||
BOOL BuildPngList (PTSTR pstrPathName, TCHAR **ppFileList, int *pFileCount,
|
||||
int *pFileIndex)
|
||||
{
|
||||
@ -523,7 +524,7 @@ BOOL BuildPngList (PTSTR pstrPathName, TCHAR **ppFileList, int *pFileCount,
|
||||
int i, ii;
|
||||
int j, jj;
|
||||
|
||||
// free previous file-list
|
||||
/* free previous file-list */
|
||||
|
||||
if (*ppFileList != NULL)
|
||||
{
|
||||
@ -531,7 +532,7 @@ BOOL BuildPngList (PTSTR pstrPathName, TCHAR **ppFileList, int *pFileCount,
|
||||
*ppFileList = NULL;
|
||||
}
|
||||
|
||||
// extract foldername, filename and search-name
|
||||
/* extract foldername, filename and search-name */
|
||||
|
||||
strcpy (szImgPathName, pstrPathName);
|
||||
strcpy (szImgFileName, strrchr (pstrPathName, '\\') + 1);
|
||||
@ -540,7 +541,7 @@ BOOL BuildPngList (PTSTR pstrPathName, TCHAR **ppFileList, int *pFileCount,
|
||||
*(strrchr (szImgFindName, '\\') + 1) = '\0';
|
||||
strcat (szImgFindName, "*.png");
|
||||
|
||||
// first cycle: count number of files in directory for memory allocation
|
||||
/* first cycle: count number of files in directory for memory allocation */
|
||||
|
||||
*pFileCount = 0;
|
||||
|
||||
@ -554,11 +555,11 @@ BOOL BuildPngList (PTSTR pstrPathName, TCHAR **ppFileList, int *pFileCount,
|
||||
}
|
||||
FindClose(hFind);
|
||||
|
||||
// allocation memory for file-list
|
||||
/* allocation memory for file-list */
|
||||
|
||||
*ppFileList = (TCHAR *) malloc (*pFileCount * MAX_PATH);
|
||||
|
||||
// second cycle: read directory and store filenames in file-list
|
||||
/* second cycle: read directory and store filenames in file-list */
|
||||
|
||||
hFind = FindFirstFile(szImgFindName, &finddata);
|
||||
bOk = (hFind != (HANDLE) -1);
|
||||
@ -580,7 +581,7 @@ BOOL BuildPngList (PTSTR pstrPathName, TCHAR **ppFileList, int *pFileCount,
|
||||
}
|
||||
FindClose(hFind);
|
||||
|
||||
// finally we must sort the file-list
|
||||
/* finally we must sort the file-list */
|
||||
|
||||
for (i = 0; i < *pFileCount - 1; i++)
|
||||
{
|
||||
@ -594,7 +595,7 @@ BOOL BuildPngList (PTSTR pstrPathName, TCHAR **ppFileList, int *pFileCount,
|
||||
strcpy (*ppFileList + jj, *ppFileList + ii);
|
||||
strcpy (*ppFileList + ii, szTmp);
|
||||
|
||||
// check if this was the current image that we moved
|
||||
/* check if this was the current image that we moved */
|
||||
|
||||
if (*pFileIndex == i)
|
||||
*pFileIndex = j;
|
||||
@ -608,9 +609,10 @@ BOOL BuildPngList (PTSTR pstrPathName, TCHAR **ppFileList, int *pFileCount,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
//----------------
|
||||
// SearchPngList
|
||||
//----------------
|
||||
/*----------------
|
||||
* SearchPngList
|
||||
*----------------
|
||||
*/
|
||||
|
||||
BOOL SearchPngList (
|
||||
TCHAR *pFileList, int FileCount, int *pFileIndex,
|
||||
@ -618,7 +620,7 @@ BOOL SearchPngList (
|
||||
{
|
||||
if (FileCount > 0)
|
||||
{
|
||||
// get previous entry
|
||||
/* get previous entry */
|
||||
|
||||
if (pstrPrevName != NULL)
|
||||
{
|
||||
@ -630,7 +632,7 @@ BOOL SearchPngList (
|
||||
strcpy (pstrPrevName, pFileList + (*pFileIndex * MAX_PATH));
|
||||
}
|
||||
|
||||
// get next entry
|
||||
/* get next entry */
|
||||
|
||||
if (pstrNextName != NULL)
|
||||
{
|
||||
@ -650,9 +652,10 @@ BOOL SearchPngList (
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------
|
||||
// LoadImageFile
|
||||
//-----------------
|
||||
/*-----------------
|
||||
* LoadImageFile
|
||||
*-----------------
|
||||
*/
|
||||
|
||||
BOOL LoadImageFile (HWND hwnd, PTSTR pstrPathName,
|
||||
png_byte **ppbImage, int *pxImgSize, int *pyImgSize,
|
||||
@ -660,7 +663,7 @@ BOOL LoadImageFile (HWND hwnd, PTSTR pstrPathName,
|
||||
{
|
||||
static TCHAR szTmp [MAX_PATH];
|
||||
|
||||
// if there's an existing PNG, free the memory
|
||||
/* if there's an existing PNG, free the memory */
|
||||
|
||||
if (*ppbImage)
|
||||
{
|
||||
@ -668,7 +671,7 @@ BOOL LoadImageFile (HWND hwnd, PTSTR pstrPathName,
|
||||
*ppbImage = NULL;
|
||||
}
|
||||
|
||||
// Load the entire PNG into memory
|
||||
/* Load the entire PNG into memory */
|
||||
|
||||
SetCursor (LoadCursor (NULL, IDC_WAIT));
|
||||
ShowCursor (TRUE);
|
||||
@ -694,10 +697,10 @@ BOOL LoadImageFile (HWND hwnd, PTSTR pstrPathName,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
//----------------
|
||||
// DisplayImage
|
||||
//----------------
|
||||
|
||||
/*----------------
|
||||
* DisplayImage
|
||||
*----------------
|
||||
*/
|
||||
BOOL DisplayImage (HWND hwnd, BYTE **ppDib,
|
||||
BYTE **ppDiData, int cxWinSize, int cyWinSize,
|
||||
BYTE *pbImage, int cxImgSize, int cyImgSize, int cImgChannels,
|
||||
@ -705,14 +708,14 @@ BOOL DisplayImage (HWND hwnd, BYTE **ppDib,
|
||||
{
|
||||
BYTE *pDib = *ppDib;
|
||||
BYTE *pDiData = *ppDiData;
|
||||
// BITMAPFILEHEADER *pbmfh;
|
||||
/* BITMAPFILEHEADER *pbmfh; */
|
||||
BITMAPINFOHEADER *pbmih;
|
||||
WORD wDIRowBytes;
|
||||
png_color bkgBlack = {0, 0, 0};
|
||||
png_color bkgGray = {127, 127, 127};
|
||||
png_color bkgWhite = {255, 255, 255};
|
||||
|
||||
// allocate memory for the Device Independant bitmap
|
||||
/* allocate memory for the Device Independant bitmap */
|
||||
|
||||
wDIRowBytes = (WORD) ((3 * cxWinSize + 3L) >> 2) << 2;
|
||||
|
||||
@ -733,7 +736,7 @@ BOOL DisplayImage (HWND hwnd, BYTE **ppDib,
|
||||
*ppDib = pDib;
|
||||
memset (pDib, 0, sizeof(BITMAPINFOHEADER));
|
||||
|
||||
// initialize the dib-structure
|
||||
/* initialize the dib-structure */
|
||||
|
||||
pbmih = (BITMAPINFOHEADER *) pDib;
|
||||
pbmih->biSize = sizeof(BITMAPINFOHEADER);
|
||||
@ -745,11 +748,11 @@ BOOL DisplayImage (HWND hwnd, BYTE **ppDib,
|
||||
pDiData = pDib + sizeof(BITMAPINFOHEADER);
|
||||
*ppDiData = pDiData;
|
||||
|
||||
// first fill bitmap with gray and image border
|
||||
/* first fill bitmap with gray and image border */
|
||||
|
||||
InitBitmap (pDiData, cxWinSize, cyWinSize);
|
||||
|
||||
// then fill bitmap with image
|
||||
/* then fill bitmap with image */
|
||||
|
||||
if (pbImage)
|
||||
{
|
||||
@ -762,16 +765,16 @@ BOOL DisplayImage (HWND hwnd, BYTE **ppDib,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
//--------------
|
||||
// InitBitmap
|
||||
//--------------
|
||||
|
||||
/*--------------
|
||||
* InitBitmap
|
||||
*--------------
|
||||
*/
|
||||
BOOL InitBitmap (BYTE *pDiData, int cxWinSize, int cyWinSize)
|
||||
{
|
||||
BYTE *dst;
|
||||
int x, y, col;
|
||||
|
||||
// initialize the background with gray
|
||||
/* initialize the background with gray */
|
||||
|
||||
dst = pDiData;
|
||||
for (y = 0; y < cyWinSize; y++)
|
||||
@ -779,13 +782,13 @@ BOOL InitBitmap (BYTE *pDiData, int cxWinSize, int cyWinSize)
|
||||
col = 0;
|
||||
for (x = 0; x < cxWinSize; x++)
|
||||
{
|
||||
// fill with GRAY
|
||||
/* fill with GRAY */
|
||||
*dst++ = 127;
|
||||
*dst++ = 127;
|
||||
*dst++ = 127;
|
||||
col += 3;
|
||||
}
|
||||
// rows start on 4 byte boundaries
|
||||
/* rows start on 4 byte boundaries */
|
||||
while ((col % 4) != 0)
|
||||
{
|
||||
dst++;
|
||||
@ -796,10 +799,10 @@ BOOL InitBitmap (BYTE *pDiData, int cxWinSize, int cyWinSize)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
//--------------
|
||||
// FillBitmap
|
||||
//--------------
|
||||
|
||||
/*--------------
|
||||
* FillBitmap
|
||||
*--------------
|
||||
*/
|
||||
BOOL FillBitmap (
|
||||
BYTE *pDiData, int cxWinSize, int cyWinSize,
|
||||
BYTE *pbImage, int cxImgSize, int cyImgSize, int cImgChannels,
|
||||
@ -824,11 +827,12 @@ BOOL FillBitmap (
|
||||
cxNewSize = cxWinSize - 2 * MARGIN;
|
||||
cyNewSize = cyWinSize - 2 * MARGIN;
|
||||
|
||||
// stretch the image to it's window determined size
|
||||
/* stretch the image to it's window determined size */
|
||||
|
||||
// the following two are the same, but the first has side-effects
|
||||
// because of rounding
|
||||
// if ((cyNewSize / cxNewSize) > (cyImgSize / cxImgSize))
|
||||
/* the following two are mathematically the same, but the first
|
||||
* has side-effects because of rounding
|
||||
*/
|
||||
/* if ((cyNewSize / cxNewSize) > (cyImgSize / cxImgSize)) */
|
||||
if ((cyNewSize * cxImgSize) > (cyImgSize * cxNewSize))
|
||||
{
|
||||
cyNewSize = cxNewSize * cyImgSize / cxImgSize;
|
||||
@ -867,12 +871,12 @@ BOOL FillBitmap (
|
||||
}
|
||||
}
|
||||
|
||||
// calculate row-bytes
|
||||
/* calculate row-bytes */
|
||||
|
||||
wImgRowBytes = cImgChannels * cxNewSize;
|
||||
wDIRowBytes = (WORD) ((cDIChannels * cxWinSize + 3L) >> 2) << 2;
|
||||
|
||||
// copy image to screen
|
||||
/* copy image to screen */
|
||||
|
||||
for (yImg = 0, yWin = cyImgPos; yImg < cyNewSize; yImg++, yWin++)
|
||||
{
|
||||
@ -888,7 +892,7 @@ BOOL FillBitmap (
|
||||
r = *src++;
|
||||
g = *src++;
|
||||
b = *src++;
|
||||
*dst++ = b; /* note the reverse order */
|
||||
*dst++ = b; /* note the reverse order */
|
||||
*dst++ = g;
|
||||
*dst++ = r;
|
||||
if (cImgChannels == 4)
|
||||
@ -898,7 +902,7 @@ BOOL FillBitmap (
|
||||
}
|
||||
}
|
||||
|
||||
// free memory
|
||||
/* free memory */
|
||||
|
||||
if (pStretchedImage != NULL)
|
||||
{
|
||||
@ -908,28 +912,28 @@ BOOL FillBitmap (
|
||||
|
||||
}
|
||||
|
||||
// process the image not-stretched
|
||||
/* process the image not-stretched */
|
||||
|
||||
else
|
||||
{
|
||||
// calculate the central position
|
||||
/* calculate the central position */
|
||||
|
||||
cxImgPos = (cxWinSize - cxImgSize) / 2;
|
||||
cyImgPos = (cyWinSize - cyImgSize) / 2;
|
||||
|
||||
// check for image larger than window
|
||||
/* check for image larger than window */
|
||||
|
||||
if (cxImgPos < MARGIN)
|
||||
cxImgPos = MARGIN;
|
||||
if (cyImgPos < MARGIN)
|
||||
cyImgPos = MARGIN;
|
||||
|
||||
// calculate both row-bytes
|
||||
/* calculate both row-bytes */
|
||||
|
||||
wImgRowBytes = cImgChannels * cxImgSize;
|
||||
wDIRowBytes = (WORD) ((cDIChannels * cxWinSize + 3L) >> 2) << 2;
|
||||
|
||||
// copy image to screen
|
||||
/* copy image to screen */
|
||||
|
||||
for (yImg = 0, yWin = cyImgPos; yImg < cyImgSize; yImg++, yWin++)
|
||||
{
|
||||
@ -945,7 +949,7 @@ BOOL FillBitmap (
|
||||
r = *src++;
|
||||
g = *src++;
|
||||
b = *src++;
|
||||
*dst++ = b; /* note the reverse order */
|
||||
*dst++ = b; /* note the reverse order */
|
||||
*dst++ = g;
|
||||
*dst++ = r;
|
||||
if (cImgChannels == 4)
|
||||
@ -959,6 +963,7 @@ BOOL FillBitmap (
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
//-----------------
|
||||
// end of source
|
||||
//-----------------
|
||||
/*-----------------
|
||||
* end of source
|
||||
*-----------------
|
||||
*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user