home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / bmp1.zip / Effects.C < prev    next >
C/C++ Source or Header  |  1995-10-03  |  9KB  |  254 lines

  1. #pragma    title("View Bitmap  --  Version 1  --  (Effects.C)")
  2. #pragma    subtitle("   Effects Functions - Interface Definitions")
  3.  
  4. #define    INCL_BITMAPFILEFORMAT       /* Include OS/2 Bitmap Information    */
  5. #define    INCL_DOS           /* Include OS/2 DOS Kernal        */
  6. #define    INCL_GPI           /* Include OS/2 GPI Interface    */
  7. #define    INCL_WIN           /* Include OS/2 PM Windows Interface    */
  8.  
  9. #include <malloc.h>
  10. #include <os2.h>
  11. #include <string.h>
  12.  
  13. #include "appdefs.h"
  14.  
  15.  
  16. /* This    module contains    the functions to apply the desired effects to    */
  17. /* to a    bitmap.                                */
  18.  
  19. /* Filename:   Effects.C                        */
  20.  
  21. /*  Version:   1                            */
  22. /*  Created:   1995-07-08                        */
  23. /*  Revised:   1995-07-22                        */
  24.  
  25. /* Routines:   HBITMAP hbmFlipColourTable(LONG iImage);            */
  26. /*           HBITMAP hbmRefreshBitmap(LONG iImage);            */
  27.  
  28.  
  29. /************************************************************************/
  30. /************************************************************************/
  31. /************************************************************************/
  32. /* DISCLAIMER OF WARRANTIES:                        */
  33. /* -------------------------                        */
  34. /* The following [enclosed] code is sample code    created    by IBM        */
  35. /* Corporation and Prominare Inc.  This    sample code is not part    of any    */
  36. /* standard IBM    product    and is provided    to you solely for the purpose    */
  37. /* of assisting    you in the development of your applications.  The code    */
  38. /* is provided "AS IS",    without    warranty of any    kind.  Neither IBM nor    */
  39. /* Prominare shall be liable for any damages arising out of your    */
  40. /* use of the sample code, even    if they    have been advised of the    */
  41. /* possibility of such damages.                        */
  42. /************************************************************************/
  43. /************************************************************************/
  44. /************************************************************************/
  45. /*               D I S C L A I M E R                */
  46. /* This    code is    provided on an as is basis with    no implied support.    */
  47. /* It should be    considered freeware that cannot    be rebundled as        */
  48. /* part    of a larger "*ware" offering without our consent.        */
  49. /************************************************************************/
  50. /************************************************************************/
  51. /************************************************************************/
  52.  
  53. /* Copyright ╕ International Business Machines Corp., 1995.        */
  54. /* Copyright ╕ 1995  Prominare Inc.  All Rights    Reserved.        */
  55.  
  56. /* --------------------------------------------------------------------    */
  57.  
  58. /* --- Module Prototype    Definitions -----------------------------------    */
  59.  
  60. #pragma    subtitle("   Bitmap Effects - Flip colour Table Function")
  61. #pragma    page( )
  62.  
  63. /* --- hbmFlipColourTable ------------------------------ [ Public ] ---    */
  64. /*                                    */
  65. /*     This function is    used to    flip the colour    table and recreate    */
  66. /*     the bitmap.                            */
  67. /*                                    */
  68. /*     Upon Entry:                            */
  69. /*                                    */
  70. /*     LONG iImage; = Image Index                    */
  71. /*                                    */
  72. /*     Upon Exit:                            */
  73. /*                                    */
  74. /*     Nothing                                */
  75. /*                                    */
  76. /* --------------------------------------------------------------------    */
  77.  
  78. HBITMAP    hbmFlipColourTable(LONG    iImage)
  79.  
  80. {
  81. PBITMAPARRAYFILEHEADER    pbafh;       /* Bitmap Array File    Header Pointer    */
  82. PBITMAPARRAYFILEHEADER2    pbafh2;       /* Bitmap Array File    Header Pointer    */
  83. PBITMAPFILEHEADER    pbfh;       /* Bitmap Array File    Header Pointer    */
  84. PBITMAPFILEHEADER2    pbfh2;       /* Bitmap Array File    Header Pointer    */
  85. PBITMAPINFO        pbmi;       /* Bitmap Info Pointer        */
  86. PBITMAPINFO2        pbmi2;       /* Bitmap Info Pointer        */
  87. PRGB2            prgb2;       /* RGB Array                */
  88. RGB            *prgb;       /* RGB Array                */
  89. register INT i,    n;           /* Loop Counter            */
  90.  
  91.                /* Check    to make    sure that the bitmap is    using    */
  92.                /* a colour table since bitmaps with more than    */
  93.                /* 256 colours use the actual bits of the image    */
  94.                /* to describe the colour            */
  95.  
  96. if ( abm[iImage].cColours <= 256L )
  97.    {
  98.                /* Check    to see if the image is a OS/2 2.x    */
  99.                /* format                    */
  100.    if (    f20Bitmap )
  101.        {
  102.                /* Check    to see if the bitmap is    an array and    */
  103.                /* depending on type, use appropriate        */
  104.                /* structures to    locate the RGB table        */
  105.  
  106.        if ( (cBitmaps == 1) && !fBitmapArray )
  107.        {
  108.        pbfh2 = (PBITMAPFILEHEADER2)abm[iImage].pb;
  109.        pbmi2 = (PBITMAPINFO2)&pbfh2->bmp2;
  110.        }
  111.        else
  112.        {
  113.        pbafh2 = (PBITMAPARRAYFILEHEADER2)abm[iImage].pb;
  114.        pbmi2 = (PBITMAPINFO2)&pbafh2->bfh2.bmp2;
  115.        }
  116.                /* Allocate memory for the RGB table        */
  117.  
  118.        prgb2 = (PRGB2)malloc(abm[iImage].cColours * sizeof(RGB2));
  119.  
  120.                /* Transfer the RGB info    to the new table    */
  121.                /* starting from    the top    of the table moving to    */
  122.                /* the bottom                    */
  123.  
  124.        for ( i = (INT)abm[iImage].cColours - 1,    n = 0; i >= 0; i--, n++    )
  125.        prgb2[n] = pbmi2->argbColor[i];
  126.  
  127.                /* Copy the flipped RGB table back into the    */
  128.                /* bitmap data and release the temporary    table    */
  129.                /* memory                    */
  130.  
  131.        memcpy(pbmi2->argbColor,    prgb2, abm[iImage].cColours * sizeof(RGB2));
  132.        free(prgb2);
  133.        }
  134.    else
  135.                /* Image    a OS/2 1.x format, use the appropriate    */
  136.                /* structures                    */
  137.        {
  138.                /* Check    to see if the bitmap is    an array and    */
  139.                /* depending on type, use appropriate        */
  140.                /* structures to    locate the RGB table        */
  141.  
  142.        if ( (cBitmaps == 1) && !fBitmapArray )
  143.        {
  144.        pbfh    = (PBITMAPFILEHEADER)abm[iImage].pb;
  145.        pbmi    = (PBITMAPINFO)&pbfh->bmp;
  146.        }
  147.        else
  148.        {
  149.        pbafh = (PBITMAPARRAYFILEHEADER)abm[iImage].pb;
  150.        pbmi    = (PBITMAPINFO)&pbafh->bfh.bmp;
  151.        }
  152.                /* Allocate memory for the RGB table        */
  153.  
  154.        prgb = (RGB *)malloc(abm[iImage].cColours * sizeof(RGB));
  155.  
  156.                /* Transfer the RGB info    to the new table    */
  157.                /* starting from    the top    of the table moving to    */
  158.                /* the bottom                    */
  159.  
  160.        for ( i = (INT)abm[iImage].cColours - 1,    n = 0; i >= 0; i--, n++    )
  161.        prgb[n] = pbmi->argbColor[i];
  162.  
  163.                /* Copy the flipped RGB table back into the    */
  164.                /* bitmap data and release the temporary    table    */
  165.                /* memory                    */
  166.  
  167.        memcpy(pbmi->argbColor, prgb, abm[iImage].cColours * sizeof(RGB));
  168.        free(prgb);
  169.        }
  170.                /* Refresh the bitmap inmage to use the new    */
  171.                /* RGB colour table                */
  172.  
  173.    return(hbmRefreshBitmap(iImage));
  174.    }
  175. else
  176.    return(abm[iImage].hbm);
  177. }
  178. #pragma    subtitle("   Bitmap Effects - Bitmap Refresh Function")
  179. #pragma    page( )
  180.  
  181. /* --- hbmRefreshBitmap    -------------------------------- [ Public ] ---    */
  182. /*                                    */
  183. /*     This function is    used to    refresh    the bitmap after the colour    */
  184. /*     table has been revised.                        */
  185. /*                                    */
  186. /*     Upon Entry:                            */
  187. /*                                    */
  188. /*     LONG iImage; = Image Index                    */
  189. /*                                    */
  190. /*     Upon Exit:                            */
  191. /*                                    */
  192. /*     hbmRefreshBitmap    = Bitmap Handle                    */
  193. /*                                    */
  194. /* --------------------------------------------------------------------    */
  195.  
  196. HBITMAP    hbmRefreshBitmap(LONG iImage)
  197.  
  198. {
  199. HPS            hpsMem;       /* Memory Presentation Space    Handle    */
  200. PBITMAPARRAYFILEHEADER    pbafh;       /* Bitmap Array File    Header Pointer    */
  201. PBITMAPARRAYFILEHEADER2    pbafh2;       /* Bitmap Array File    Header Pointer    */
  202. PBITMAPFILEHEADER    pbfh;       /* Bitmap Array File    Header Pointer    */
  203. PBITMAPFILEHEADER2    pbfh2;       /* Bitmap Array File    Header Pointer    */
  204. PBITMAPINFO2        pbmi2;       /* Bitmap Info Pointer        */
  205. ULONG            offBits;   /* Bitmap Offset            */
  206.  
  207. if ( abm[iImage].cColours <= 256L )
  208.    {
  209.                /* Depending on the version of the bitmap    */
  210.                /* structure, locate the    appropriate bitmap    */
  211.                /* data for the revised image            */
  212.    if (    f20Bitmap )
  213.        if ( (cBitmaps == 1) && !fBitmapArray )
  214.        {
  215.        pbfh2 = (PBITMAPFILEHEADER2)abm[iImage].pb;
  216.        pbmi2 = (PBITMAPINFO2)&pbfh2->bmp2;
  217.        offBits = pbfh2->offBits;
  218.        }
  219.        else
  220.        {
  221.        pbafh2 = (PBITMAPARRAYFILEHEADER2)abm[iImage].pb;
  222.        pbmi2 = (PBITMAPINFO2)&pbafh2->bfh2.bmp2;
  223.        offBits = pbafh2->bfh2.offBits;
  224.        }
  225.    else
  226.        if ( (cBitmaps == 1) && !fBitmapArray )
  227.        {
  228.        pbfh    = (PBITMAPFILEHEADER)abm[iImage].pb;
  229.        pbmi2 = (PBITMAPINFO2)&pbfh->bmp;
  230.        offBits = pbfh->offBits;
  231.        }
  232.        else
  233.        {
  234.        pbafh = (PBITMAPARRAYFILEHEADER)abm[iImage].pb;
  235.        pbmi2 = (PBITMAPINFO2)&pbafh->bfh.bmp;
  236.        offBits = pbafh->bfh.offBits;
  237.        }
  238.                /* Destroy previous version of the bitmap    */
  239.  
  240.    GpiDeleteBitmap(abm[iImage].hbm);
  241.  
  242.                /* Point    to the independent bitmap file header    */
  243.                /* since    it is the default            */
  244.  
  245.    abm[iImage].hbm = GpiCreateBitmap(hpsMem = WinGetPS(HWND_DESKTOP), (PBITMAPINFOHEADER2)pbmi2, CBM_INIT,
  246.                      (PBYTE)(abm[0].pb + offBits), pbmi2);
  247.  
  248.                /* Release the memory presentation space        */
  249.    WinReleasePS(hpsMem);
  250.  
  251.    }
  252. return(abm[iImage].hbm);
  253. }
  254.