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