~random-stuff/libpng/libpng-1.6.x

« back to all changes in this revision

Viewing changes to contrib/visupng/VisualPng.c

  • Committer: Sérgio Benjamim
  • Date: 2015-10-10 23:00:20 UTC
  • Revision ID: sergio_br2@yahoo.com.br-20151010230020-gdtmmv30zn25396n
Update to 1.6.18.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//------------------------------------
2
 
//  VisualPng.C -- Shows a PNG image
3
 
//------------------------------------
4
 
 
5
 
// Copyright 2000, Willem van Schaik.
6
 
 
7
 
// This code is released under the libpng license.
8
 
// For conditions of distribution and use, see the disclaimer
9
 
// and license in png.h
10
 
 
11
 
// switches
12
 
 
13
 
// defines
 
1
/*------------------------------------
 
2
 *  VisualPng.C -- Shows a PNG image
 
3
 *------------------------------------
 
4
 *
 
5
 * Copyright 2000, Willem van Schaik.
 
6
 *
 
7
 * This code is released under the libpng license.
 
8
 * For conditions of distribution and use, see the disclaimer
 
9
 * and license in png.h
 
10
 */
 
11
 
 
12
/* switches */
 
13
 
 
14
/* defines */
14
15
 
15
16
#define PROGNAME  "VisualPng"
16
17
#define LONGNAME  "Win32 Viewer for PNG-files"
17
18
#define VERSION   "1.0 of 2000 June 07"
18
19
 
19
 
// constants
 
20
/* constants */
20
21
 
21
22
#define MARGIN 8
22
23
 
23
 
// standard includes
 
24
/* standard includes */
24
25
 
25
26
#include <stdio.h>
26
27
#include <stdlib.h>
27
28
#include <string.h>
28
29
#include <windows.h>
 
30
#include <zlib.h>
29
31
 
30
 
// application includes
 
32
/* application includes */
31
33
 
32
34
#include "png.h"
33
35
#include "pngfile.h"
34
36
#include "resource.h"
35
37
 
36
 
// macros
 
38
/* macros */
37
39
 
38
 
// function prototypes
 
40
/* function prototypes */
39
41
 
40
42
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
41
43
BOOL    CALLBACK AboutDlgProc (HWND, UINT, WPARAM, LPARAM) ;
65
67
        BYTE *pbImage, int cxImgSize, int cyImgSize, int cImgChannels,
66
68
        BOOL bStretched);
67
69
 
68
 
// a few global variables
 
70
/* a few global variables */
69
71
 
70
72
static char *szProgName = PROGNAME;
71
73
static char *szAppName = LONGNAME;
72
74
static char *szIconName = PROGNAME;
73
75
static char szCmdFileName [MAX_PATH];
74
76
 
75
 
// MAIN routine
 
77
/* MAIN routine */
76
78
 
77
79
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
78
80
                    PSTR szCmdLine, int iCmdShow)
90
92
    wndclass.hInstance     = hInstance;
91
93
    wndclass.hIcon         = LoadIcon (hInstance, szIconName) ;
92
94
    wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW);
93
 
    wndclass.hbrBackground = NULL; // (HBRUSH) GetStockObject (GRAY_BRUSH);
 
95
    wndclass.hbrBackground = NULL; /* (HBRUSH) GetStockObject (GRAY_BRUSH); */
94
96
    wndclass.lpszMenuName  = szProgName;
95
97
    wndclass.lpszClassName = szProgName;
96
98
 
101
103
        return 0;
102
104
    }
103
105
 
104
 
    // if filename given on commandline, store it
 
106
    /* if filename given on commandline, store it */
105
107
    if ((szCmdLine != NULL) && (*szCmdLine != '\0'))
106
108
        if (szCmdLine[0] == '"')
107
109
            strncpy (szCmdFileName, szCmdLine + 1, strlen(szCmdLine) - 2);
110
112
    else
111
113
        strcpy (szCmdFileName, "");
112
114
 
113
 
    // calculate size of window-borders
 
115
    /* calculate size of window-borders */
114
116
    ixBorders = 2 * (GetSystemMetrics (SM_CXBORDER) +
115
117
                     GetSystemMetrics (SM_CXDLGFRAME));
116
118
    iyBorders = 2 * (GetSystemMetrics (SM_CYBORDER) +
117
119
                     GetSystemMetrics (SM_CYDLGFRAME)) +
118
120
                     GetSystemMetrics (SM_CYCAPTION) +
119
121
                     GetSystemMetrics (SM_CYMENUSIZE) +
120
 
                     1; /* WvS: don't ask me why? */
 
122
                     1; /* WvS: don't ask me why?  */
121
123
 
122
124
    hwnd = CreateWindow (szProgName, szAppName,
123
125
        WS_OVERLAPPEDWINDOW,
124
126
        CW_USEDEFAULT, CW_USEDEFAULT,
125
127
        512 + 2 * MARGIN + ixBorders, 384 + 2 * MARGIN + iyBorders,
126
 
//      CW_USEDEFAULT, CW_USEDEFAULT,
 
128
/*      CW_USEDEFAULT, CW_USEDEFAULT, */
127
129
        NULL, NULL, hInstance, NULL);
128
130
 
129
131
    ShowWindow (hwnd, iCmdShow);
180
182
 
181
183
        strcpy (szImgPathName, "");
182
184
 
183
 
        // in case we process file given on command-line
 
185
        /* in case we process file given on command-line */
184
186
 
185
187
        if (szCmdFileName[0] != '\0')
186
188
        {
187
189
            strcpy (szImgPathName, szCmdFileName);
188
190
 
189
 
            // read the other png-files in the directory for later
190
 
            // next/previous commands
 
191
            /* read the other png-files in the directory for later */
 
192
            /* next/previous commands */
191
193
 
192
194
            BuildPngList (szImgPathName, &pPngFileList, &iPngFileCount,
193
195
                          &iPngFileIndex);
194
196
 
195
 
            // load the image from file
 
197
            /* load the image from file */
196
198
 
197
199
            if (!LoadImageFile (hwnd, szImgPathName,
198
200
                &pbImage, &cxImgSize, &cyImgSize, &cImgChannels, &bkgColor))
199
201
                return 0;
200
202
 
201
 
            // invalidate the client area for later update
 
203
            /* invalidate the client area for later update */
202
204
 
203
205
            InvalidateRect (hwnd, NULL, TRUE);
204
206
 
205
 
            // display the PNG into the DIBitmap
 
207
            /* display the PNG into the DIBitmap */
206
208
 
207
209
            DisplayImage (hwnd, &pDib, &pDiData, cxWinSize, cyWinSize,
208
210
                pbImage, cxImgSize, cyImgSize, cImgChannels, bStretched);
214
216
        cxWinSize = LOWORD (lParam);
215
217
        cyWinSize = HIWORD (lParam);
216
218
 
217
 
        // invalidate the client area for later update
 
219
        /* invalidate the client area for later update */
218
220
 
219
221
        InvalidateRect (hwnd, NULL, TRUE);
220
222
 
221
 
        // display the PNG into the DIBitmap
 
223
        /* display the PNG into the DIBitmap */
222
224
 
223
225
        DisplayImage (hwnd, &pDib, &pDiData, cxWinSize, cyWinSize,
224
226
            pbImage, cxImgSize, cyImgSize, cImgChannels, bStretched);
242
244
        {
243
245
        case IDM_FILE_OPEN:
244
246
 
245
 
            // show the File Open dialog box
 
247
            /* show the File Open dialog box */
246
248
 
247
249
            if (!PngFileOpenDlg (hwnd, szImgPathName, szTitleName))
248
250
                return 0;
249
251
 
250
 
            // read the other png-files in the directory for later
251
 
            // next/previous commands
 
252
            /* read the other png-files in the directory for later */
 
253
            /* next/previous commands */
252
254
 
253
255
            BuildPngList (szImgPathName, &pPngFileList, &iPngFileCount,
254
256
                          &iPngFileIndex);
255
257
 
256
 
            // load the image from file
 
258
            /* load the image from file */
257
259
 
258
260
            if (!LoadImageFile (hwnd, szImgPathName,
259
261
                &pbImage, &cxImgSize, &cyImgSize, &cImgChannels, &bkgColor))
260
262
                return 0;
261
263
 
262
 
            // invalidate the client area for later update
 
264
            /* invalidate the client area for later update */
263
265
 
264
266
            InvalidateRect (hwnd, NULL, TRUE);
265
267
 
266
 
            // display the PNG into the DIBitmap
 
268
            /* display the PNG into the DIBitmap */
267
269
 
268
270
            DisplayImage (hwnd, &pDib, &pDiData, cxWinSize, cyWinSize,
269
271
                pbImage, cxImgSize, cyImgSize, cImgChannels, bStretched);
272
274
 
273
275
        case IDM_FILE_SAVE:
274
276
 
275
 
            // show the File Save dialog box
 
277
            /* show the File Save dialog box */
276
278
 
277
279
            if (!PngFileSaveDlg (hwnd, szImgPathName, szTitleName))
278
280
                return 0;
279
281
 
280
 
            // save the PNG to a disk file
 
282
            /* save the PNG to a disk file */
281
283
 
282
284
            SetCursor (LoadCursor (NULL, IDC_WAIT));
283
285
            ShowCursor (TRUE);
295
297
 
296
298
        case IDM_FILE_NEXT:
297
299
 
298
 
            // read next entry in the directory
 
300
            /* read next entry in the directory */
299
301
 
300
302
            if (SearchPngList (pPngFileList, iPngFileCount, &iPngFileIndex,
301
303
                NULL, szImgPathName))
302
304
            {
303
305
                if (strcmp (szImgPathName, "") == 0)
304
306
                    return 0;
305
 
                
306
 
                // load the image from file
307
 
                
 
307
 
 
308
                /* load the image from file */
 
309
 
308
310
                if (!LoadImageFile (hwnd, szImgPathName, &pbImage,
309
311
                        &cxImgSize, &cyImgSize, &cImgChannels, &bkgColor))
310
312
                    return 0;
311
 
                
312
 
                // invalidate the client area for later update
313
 
                
 
313
 
 
314
                /* invalidate the client area for later update */
 
315
 
314
316
                InvalidateRect (hwnd, NULL, TRUE);
315
 
                
316
 
                // display the PNG into the DIBitmap
317
 
                
 
317
 
 
318
                /* display the PNG into the DIBitmap */
 
319
 
318
320
                DisplayImage (hwnd, &pDib, &pDiData, cxWinSize, cyWinSize,
319
321
                    pbImage, cxImgSize, cyImgSize, cImgChannels, bStretched);
320
322
            }
321
 
            
 
323
 
322
324
            return 0;
323
325
 
324
326
        case IDM_FILE_PREVIOUS:
325
327
 
326
 
            // read previous entry in the directory
 
328
            /* read previous entry in the directory */
327
329
 
328
330
            if (SearchPngList (pPngFileList, iPngFileCount, &iPngFileIndex,
329
331
                szImgPathName, NULL))
330
332
            {
331
 
                
 
333
 
332
334
                if (strcmp (szImgPathName, "") == 0)
333
335
                    return 0;
334
 
                
335
 
                // load the image from file
336
 
                
 
336
 
 
337
                /* load the image from file */
 
338
 
337
339
                if (!LoadImageFile (hwnd, szImgPathName, &pbImage, &cxImgSize,
338
340
                    &cyImgSize, &cImgChannels, &bkgColor))
339
341
                    return 0;
340
 
                
341
 
                // invalidate the client area for later update
342
 
                
 
342
 
 
343
                /* invalidate the client area for later update */
 
344
 
343
345
                InvalidateRect (hwnd, NULL, TRUE);
344
 
                
345
 
                // display the PNG into the DIBitmap
346
 
                
 
346
 
 
347
                /* display the PNG into the DIBitmap */
 
348
 
347
349
                DisplayImage (hwnd, &pDib, &pDiData, cxWinSize, cyWinSize,
348
350
                    pbImage, cxImgSize, cyImgSize, cImgChannels, bStretched);
349
351
            }
352
354
 
353
355
        case IDM_FILE_EXIT:
354
356
 
355
 
            // more cleanup needed...
 
357
            /* more cleanup needed... */
356
358
 
357
 
            // free image buffer
 
359
            /* free image buffer */
358
360
 
359
361
            if (pDib != NULL)
360
362
            {
362
364
                pDib = NULL;
363
365
            }
364
366
 
365
 
            // free file-list
 
367
            /* free file-list */
366
368
 
367
369
            if (pPngFileList != NULL)
368
370
            {
370
372
                pPngFileList = NULL;
371
373
            }
372
374
 
373
 
            // let's go ...
 
375
            /* let's go ... */
374
376
 
375
377
            exit (0);
376
378
 
383
385
            else
384
386
                CheckMenuItem (hMenu, IDM_OPTIONS_STRETCH, MF_UNCHECKED);
385
387
 
386
 
            // invalidate the client area for later update
 
388
            /* invalidate the client area for later update */
387
389
 
388
390
            InvalidateRect (hwnd, NULL, TRUE);
389
391
 
390
 
            // display the PNG into the DIBitmap
 
392
            /* display the PNG into the DIBitmap */
391
393
 
392
394
            DisplayImage (hwnd, &pDib, &pDiData, cxWinSize, cyWinSize,
393
395
                pbImage, cxImgSize, cyImgSize, cImgChannels, bStretched);
398
400
            DialogBox (hInstance, TEXT ("AboutBox"), hwnd, AboutDlgProc) ;
399
401
            return 0;
400
402
 
401
 
        } // end switch
 
403
        } /* end switch */
402
404
 
403
405
        break;
404
406
 
450
452
     return FALSE ;
451
453
}
452
454
 
453
 
//---------------
454
 
//  CenterAbout
455
 
//---------------
456
 
 
 
455
/*---------------
 
456
 *  CenterAbout
 
457
 *---------------
 
458
 */
457
459
BOOL CenterAbout (HWND hwndChild, HWND hwndParent)
458
460
{
459
461
   RECT    rChild, rParent, rWorkArea;
461
463
   int     xNew, yNew;
462
464
   BOOL  bResult;
463
465
 
464
 
   // Get the Height and Width of the child window
 
466
   /* Get the Height and Width of the child window */
465
467
   GetWindowRect (hwndChild, &rChild);
466
468
   wChild = rChild.right - rChild.left;
467
469
   hChild = rChild.bottom - rChild.top;
468
470
 
469
 
   // Get the Height and Width of the parent window
 
471
   /* Get the Height and Width of the parent window */
470
472
   GetWindowRect (hwndParent, &rParent);
471
473
   wParent = rParent.right - rParent.left;
472
474
   hParent = rParent.bottom - rParent.top;
473
475
 
474
 
   // Get the limits of the 'workarea'
 
476
   /* Get the limits of the 'workarea' */
475
477
   bResult = SystemParametersInfo(
476
 
      SPI_GETWORKAREA,  // system parameter to query or set
 
478
      SPI_GETWORKAREA,  /* system parameter to query or set */
477
479
      sizeof(RECT),
478
480
      &rWorkArea,
479
481
      0);
483
485
      rWorkArea.bottom = GetSystemMetrics(SM_CYSCREEN);
484
486
   }
485
487
 
486
 
   // Calculate new X position, then adjust for workarea
 
488
   /* Calculate new X position, then adjust for workarea */
487
489
   xNew = rParent.left + ((wParent - wChild) /2);
488
490
   if (xNew < rWorkArea.left) {
489
491
      xNew = rWorkArea.left;
491
493
      xNew = rWorkArea.right - wChild;
492
494
   }
493
495
 
494
 
   // Calculate new Y position, then adjust for workarea
 
496
   /* Calculate new Y position, then adjust for workarea */
495
497
   yNew = rParent.top  + ((hParent - hChild) /2);
496
498
   if (yNew < rWorkArea.top) {
497
499
      yNew = rWorkArea.top;
499
501
      yNew = rWorkArea.bottom - hChild;
500
502
   }
501
503
 
502
 
   // Set it, and return
 
504
   /* Set it, and return */
503
505
   return SetWindowPos (hwndChild, NULL, xNew, yNew, 0, 0, SWP_NOSIZE |
504
506
          SWP_NOZORDER);
505
507
}
506
508
 
507
 
//----------------
508
 
//  BuildPngList
509
 
//----------------
510
 
 
 
509
/*----------------
 
510
 *  BuildPngList
 
511
 *----------------
 
512
 */
511
513
BOOL BuildPngList (PTSTR pstrPathName, TCHAR **ppFileList, int *pFileCount,
512
514
     int *pFileIndex)
513
515
{
523
525
    int                       i, ii;
524
526
    int                       j, jj;
525
527
 
526
 
    // free previous file-list
 
528
    /* free previous file-list */
527
529
 
528
530
    if (*ppFileList != NULL)
529
531
    {
531
533
        *ppFileList = NULL;
532
534
    }
533
535
 
534
 
    // extract foldername, filename and search-name
 
536
    /* extract foldername, filename and search-name */
535
537
 
536
538
    strcpy (szImgPathName, pstrPathName);
537
539
    strcpy (szImgFileName, strrchr (pstrPathName, '\\') + 1);
540
542
    *(strrchr (szImgFindName, '\\') + 1) = '\0';
541
543
    strcat (szImgFindName, "*.png");
542
544
 
543
 
    // first cycle: count number of files in directory for memory allocation
 
545
    /* first cycle: count number of files in directory for memory allocation */
544
546
 
545
547
    *pFileCount = 0;
546
548
 
554
556
    }
555
557
    FindClose(hFind);
556
558
 
557
 
    // allocation memory for file-list
 
559
    /* allocation memory for file-list */
558
560
 
559
561
    *ppFileList = (TCHAR *) malloc (*pFileCount * MAX_PATH);
560
562
 
561
 
    // second cycle: read directory and store filenames in file-list
 
563
    /* second cycle: read directory and store filenames in file-list */
562
564
 
563
565
    hFind = FindFirstFile(szImgFindName, &finddata);
564
566
    bOk = (hFind != (HANDLE) -1);
580
582
    }
581
583
    FindClose(hFind);
582
584
 
583
 
    // finally we must sort the file-list
 
585
    /* finally we must sort the file-list */
584
586
 
585
587
    for (i = 0; i < *pFileCount - 1; i++)
586
588
    {
594
596
                strcpy (*ppFileList + jj, *ppFileList + ii);
595
597
                strcpy (*ppFileList + ii, szTmp);
596
598
 
597
 
                // check if this was the current image that we moved
 
599
                /* check if this was the current image that we moved */
598
600
 
599
601
                if (*pFileIndex == i)
600
602
                    *pFileIndex = j;
608
610
    return TRUE;
609
611
}
610
612
 
611
 
//----------------
612
 
//  SearchPngList
613
 
//----------------
 
613
/*----------------
 
614
 *  SearchPngList
 
615
 *----------------
 
616
 */
614
617
 
615
618
BOOL SearchPngList (
616
619
        TCHAR *pFileList, int FileCount, int *pFileIndex,
618
621
{
619
622
    if (FileCount > 0)
620
623
    {
621
 
        // get previous entry
622
 
        
 
624
        /* get previous entry */
 
625
 
623
626
        if (pstrPrevName != NULL)
624
627
        {
625
628
            if (*pFileIndex > 0)
626
629
                *pFileIndex -= 1;
627
630
            else
628
631
                *pFileIndex = FileCount - 1;
629
 
            
 
632
 
630
633
            strcpy (pstrPrevName, pFileList + (*pFileIndex * MAX_PATH));
631
634
        }
632
 
        
633
 
        // get next entry
634
 
        
 
635
 
 
636
        /* get next entry */
 
637
 
635
638
        if (pstrNextName != NULL)
636
639
        {
637
640
            if (*pFileIndex < FileCount - 1)
638
641
                *pFileIndex += 1;
639
642
            else
640
643
                *pFileIndex = 0;
641
 
            
 
644
 
642
645
            strcpy (pstrNextName, pFileList + (*pFileIndex * MAX_PATH));
643
646
        }
644
 
        
 
647
 
645
648
        return TRUE;
646
649
    }
647
650
    else
650
653
    }
651
654
}
652
655
 
653
 
//-----------------
654
 
//  LoadImageFile
655
 
//-----------------
 
656
/*-----------------
 
657
 *  LoadImageFile
 
658
 *-----------------
 
659
 */
656
660
 
657
661
BOOL LoadImageFile (HWND hwnd, PTSTR pstrPathName,
658
662
                png_byte **ppbImage, int *pxImgSize, int *pyImgSize,
660
664
{
661
665
    static TCHAR szTmp [MAX_PATH];
662
666
 
663
 
    // if there's an existing PNG, free the memory
 
667
    /* if there's an existing PNG, free the memory */
664
668
 
665
669
    if (*ppbImage)
666
670
    {
668
672
        *ppbImage = NULL;
669
673
    }
670
674
 
671
 
    // Load the entire PNG into memory
 
675
    /* Load the entire PNG into memory */
672
676
 
673
677
    SetCursor (LoadCursor (NULL, IDC_WAIT));
674
678
    ShowCursor (TRUE);
694
698
    return TRUE;
695
699
}
696
700
 
697
 
//----------------
698
 
//  DisplayImage
699
 
//----------------
700
 
 
 
701
/*----------------
 
702
 *  DisplayImage
 
703
 *----------------
 
704
 */
701
705
BOOL DisplayImage (HWND hwnd, BYTE **ppDib,
702
706
        BYTE **ppDiData, int cxWinSize, int cyWinSize,
703
707
        BYTE *pbImage, int cxImgSize, int cyImgSize, int cImgChannels,
705
709
{
706
710
    BYTE                       *pDib = *ppDib;
707
711
    BYTE                       *pDiData = *ppDiData;
708
 
    // BITMAPFILEHEADER        *pbmfh;
 
712
    /* BITMAPFILEHEADER        *pbmfh; */
709
713
    BITMAPINFOHEADER           *pbmih;
710
714
    WORD                        wDIRowBytes;
711
715
    png_color                   bkgBlack = {0, 0, 0};
712
716
    png_color                   bkgGray  = {127, 127, 127};
713
717
    png_color                   bkgWhite = {255, 255, 255};
714
718
 
715
 
    // allocate memory for the Device Independant bitmap
 
719
    /* allocate memory for the Device Independant bitmap */
716
720
 
717
721
    wDIRowBytes = (WORD) ((3 * cxWinSize + 3L) >> 2) << 2;
718
722
 
733
737
    *ppDib = pDib;
734
738
    memset (pDib, 0, sizeof(BITMAPINFOHEADER));
735
739
 
736
 
    // initialize the dib-structure
 
740
    /* initialize the dib-structure */
737
741
 
738
742
    pbmih = (BITMAPINFOHEADER *) pDib;
739
743
    pbmih->biSize = sizeof(BITMAPINFOHEADER);
745
749
    pDiData = pDib + sizeof(BITMAPINFOHEADER);
746
750
    *ppDiData = pDiData;
747
751
 
748
 
    // first fill bitmap with gray and image border
 
752
    /* first fill bitmap with gray and image border */
749
753
 
750
754
    InitBitmap (pDiData, cxWinSize, cyWinSize);
751
755
 
752
 
    // then fill bitmap with image
 
756
    /* then fill bitmap with image */
753
757
 
754
758
    if (pbImage)
755
759
    {
762
766
    return TRUE;
763
767
}
764
768
 
765
 
//--------------
766
 
//  InitBitmap
767
 
//--------------
768
 
 
 
769
/*--------------
 
770
 *  InitBitmap
 
771
 *--------------
 
772
 */
769
773
BOOL InitBitmap (BYTE *pDiData, int cxWinSize, int cyWinSize)
770
774
{
771
775
    BYTE *dst;
772
776
    int x, y, col;
773
777
 
774
 
    // initialize the background with gray
 
778
    /* initialize the background with gray */
775
779
 
776
780
    dst = pDiData;
777
781
    for (y = 0; y < cyWinSize; y++)
779
783
        col = 0;
780
784
        for (x = 0; x < cxWinSize; x++)
781
785
        {
782
 
            // fill with GRAY
 
786
            /* fill with GRAY */
783
787
            *dst++ = 127;
784
788
            *dst++ = 127;
785
789
            *dst++ = 127;
786
790
            col += 3;
787
791
        }
788
 
        // rows start on 4 byte boundaries
 
792
        /* rows start on 4 byte boundaries */
789
793
        while ((col % 4) != 0)
790
794
        {
791
795
            dst++;
796
800
    return TRUE;
797
801
}
798
802
 
799
 
//--------------
800
 
//  FillBitmap
801
 
//--------------
802
 
 
 
803
/*--------------
 
804
 *  FillBitmap
 
805
 *--------------
 
806
 */
803
807
BOOL FillBitmap (
804
808
        BYTE *pDiData, int cxWinSize, int cyWinSize,
805
809
        BYTE *pbImage, int cxImgSize, int cyImgSize, int cImgChannels,
824
828
        cxNewSize = cxWinSize - 2 * MARGIN;
825
829
        cyNewSize = cyWinSize - 2 * MARGIN;
826
830
 
827
 
        // stretch the image to it's window determined size
 
831
        /* stretch the image to it's window determined size */
828
832
 
829
 
        // the following two are the same, but the first has side-effects
830
 
        // because of rounding
831
 
//      if ((cyNewSize / cxNewSize) > (cyImgSize / cxImgSize))
 
833
        /* the following two are mathematically the same, but the first
 
834
         * has side-effects because of rounding
 
835
         */
 
836
/*      if ((cyNewSize / cxNewSize) > (cyImgSize / cxImgSize)) */
832
837
        if ((cyNewSize * cxImgSize) > (cyImgSize * cxNewSize))
833
838
        {
834
839
            cyNewSize = cxNewSize * cyImgSize / cxImgSize;
867
872
            }
868
873
        }
869
874
 
870
 
        // calculate row-bytes
 
875
        /* calculate row-bytes */
871
876
 
872
877
        wImgRowBytes = cImgChannels * cxNewSize;
873
878
        wDIRowBytes = (WORD) ((cDIChannels * cxWinSize + 3L) >> 2) << 2;
874
879
 
875
 
        // copy image to screen
 
880
        /* copy image to screen */
876
881
 
877
882
        for (yImg = 0, yWin = cyImgPos; yImg < cyNewSize; yImg++, yWin++)
878
883
        {
888
893
                r = *src++;
889
894
                g = *src++;
890
895
                b = *src++;
891
 
                *dst++ = b; /* note the reverse order */
 
896
                *dst++ = b; /* note the reverse order  */
892
897
                *dst++ = g;
893
898
                *dst++ = r;
894
899
                if (cImgChannels == 4)
898
903
            }
899
904
        }
900
905
 
901
 
        // free memory
 
906
        /* free memory */
902
907
 
903
908
        if (pStretchedImage != NULL)
904
909
        {
908
913
 
909
914
    }
910
915
 
911
 
    // process the image not-stretched
 
916
    /* process the image not-stretched */
912
917
 
913
918
    else
914
919
    {
915
 
        // calculate the central position
 
920
        /* calculate the central position */
916
921
 
917
922
        cxImgPos = (cxWinSize - cxImgSize) / 2;
918
923
        cyImgPos = (cyWinSize - cyImgSize) / 2;
919
924
 
920
 
        // check for image larger than window
 
925
        /* check for image larger than window */
921
926
 
922
927
        if (cxImgPos < MARGIN)
923
928
            cxImgPos = MARGIN;
924
929
        if (cyImgPos < MARGIN)
925
930
            cyImgPos = MARGIN;
926
931
 
927
 
        // calculate both row-bytes
 
932
        /* calculate both row-bytes */
928
933
 
929
934
        wImgRowBytes = cImgChannels * cxImgSize;
930
935
        wDIRowBytes = (WORD) ((cDIChannels * cxWinSize + 3L) >> 2) << 2;
931
936
 
932
 
        // copy image to screen
 
937
        /* copy image to screen */
933
938
 
934
939
        for (yImg = 0, yWin = cyImgPos; yImg < cyImgSize; yImg++, yWin++)
935
940
        {
945
950
                r = *src++;
946
951
                g = *src++;
947
952
                b = *src++;
948
 
                *dst++ = b; /* note the reverse order */
 
953
                *dst++ = b; /* note the reverse order  */
949
954
                *dst++ = g;
950
955
                *dst++ = r;
951
956
                if (cImgChannels == 4)
959
964
    return TRUE;
960
965
}
961
966
 
962
 
//-----------------
963
 
//  end of source
964
 
//-----------------
 
967
/*-----------------
 
968
 *  end of source
 
969
 *-----------------
 
970
 */