"Fossies" - the Fresh Open Source Software Archive

Member "libgdiplus-6.0.2/tests/testbitmap.c" (1 Aug 2019, 32206 Bytes) of package /linux/misc/mono-sources/libgdiplus/libgdiplus-6.0.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #ifdef WIN32
    2 #ifndef __cplusplus
    3 #error Please compile with a C++ compiler.
    4 #endif
    5 #endif
    6 
    7 #if defined(USE_WINDOWS_GDIPLUS)
    8 #include <Windows.h>
    9 #include <GdiPlus.h>
   10 
   11 #pragma comment(lib, "gdiplus")
   12 #else
   13 #include <GdiPlusFlat.h>
   14 #endif
   15 
   16 #if defined(USE_WINDOWS_GDIPLUS)
   17 using namespace Gdiplus;
   18 using namespace DllExports;
   19 #endif
   20 
   21 #include <assert.h>
   22 #include <math.h>
   23 #include <stdio.h>
   24 #include <stdlib.h>
   25 #include <string.h>
   26 #include "testhelpers.h"
   27 
   28 static void test_createBitmapFromStream ()
   29 {
   30     GpStatus status;
   31     GpBitmap *bitmap;
   32 
   33     // Negative tests.
   34     status = GdipCreateBitmapFromStream (NULL, &bitmap);
   35     assertEqualInt (status, InvalidParameter);
   36 
   37 #if !defined(USE_WINDOWS_GDIPLUS)
   38     int temp = 0;
   39 
   40     status = GdipCreateBitmapFromStream (&temp, NULL);
   41     assertEqualInt (status, InvalidParameter);
   42 
   43     status = GdipCreateBitmapFromStream (&temp, &bitmap);
   44     assertEqualInt (status, NotImplemented);
   45 #endif    
   46 }
   47 
   48 static void test_createBitmapFromFile ()
   49 {
   50     GpStatus status;
   51     GpBitmap *bitmap;
   52     WCHAR *bitmapFile = createWchar ("test.png");
   53     WCHAR *metafileFile = createWchar ("test.wmf");
   54     WCHAR *enhancedMetafileFile = createWchar ("test.emf");
   55     WCHAR *noSuchFile = createWchar ("noSuchFile.bmp");
   56     WCHAR *invalidFile = createWchar ("test.ttf");
   57 
   58     status = GdipCreateBitmapFromFile (bitmapFile, &bitmap);
   59     assertEqualInt (status, Ok);
   60     verifyBitmap ((GpImage *) bitmap, pngRawFormat, PixelFormat24bppRGB, 100, 68, ImageFlagsColorSpaceRGB | ImageFlagsHasRealDPI | ImageFlagsHasRealPixelSize | ImageFlagsReadOnly, 5, TRUE);
   61     GdipDisposeImage ((GpImage *) bitmap);
   62     
   63     status = GdipCreateBitmapFromFile (metafileFile, &bitmap);
   64     assertEqualInt (status, Ok);
   65     verifyBitmap ((GpImage *) bitmap, memoryBmpRawFormat, PixelFormat32bppARGB, 770, 649, ImageFlagsHasAlpha, 0, TRUE);
   66     GdipDisposeImage ((GpImage *) bitmap);
   67     
   68     status = GdipCreateBitmapFromFile (enhancedMetafileFile, &bitmap);
   69     assertEqualInt (status, Ok);
   70     verifyBitmap ((GpImage *) bitmap, memoryBmpRawFormat, PixelFormat32bppARGB, 100, 100, ImageFlagsHasAlpha, 0, TRUE);
   71     GdipDisposeImage ((GpImage *) bitmap);
   72 
   73     // Negative tests.
   74     status = GdipCreateBitmapFromFile (NULL, &bitmap);
   75     assertEqualInt (status, InvalidParameter);
   76 
   77     status = GdipCreateBitmapFromFile (noSuchFile, &bitmap);
   78     assertEqualInt (status, InvalidParameter);
   79 
   80     status = GdipCreateBitmapFromFile (invalidFile, &bitmap);
   81     assertEqualInt (status, InvalidParameter);
   82 
   83     status = GdipCreateBitmapFromFile (noSuchFile, NULL);
   84     assertEqualInt (status, InvalidParameter);
   85 
   86     freeWchar (bitmapFile);
   87     freeWchar (metafileFile);
   88     freeWchar (enhancedMetafileFile);
   89     freeWchar (noSuchFile);
   90     freeWchar (invalidFile);
   91 }
   92 
   93 static void test_createBitmapFromStreamICM ()
   94 {
   95     GpStatus status;
   96     GpBitmap *bitmap;
   97 
   98     // Negative tests.
   99     status = GdipCreateBitmapFromStreamICM (NULL, &bitmap);
  100     assertEqualInt (status, InvalidParameter);
  101 
  102 #if !defined(USE_WINDOWS_GDIPLUS)
  103     int temp = 0;
  104 
  105     status = GdipCreateBitmapFromStreamICM (&temp, NULL);
  106     assertEqualInt (status, InvalidParameter);
  107 
  108     status = GdipCreateBitmapFromStreamICM (&temp, &bitmap);
  109     assertEqualInt (status, NotImplemented);
  110 #endif    
  111 }
  112 
  113 static void test_createBitmapFromFileICM ()
  114 {
  115     GpStatus status;
  116     GpBitmap *bitmap;
  117     WCHAR *bitmapFile = createWchar ("test.png");
  118     WCHAR *metafileFile = createWchar ("test.wmf");
  119     WCHAR *enhancedMetafileFile = createWchar ("test.emf");
  120     WCHAR *noSuchFile = createWchar ("noSuchFile.bmp");
  121     WCHAR *invalidFile = createWchar ("test.ttf");
  122 
  123     status = GdipCreateBitmapFromFileICM (bitmapFile, &bitmap);
  124     assertEqualInt (status, Ok);
  125     verifyBitmap ((GpImage *) bitmap, pngRawFormat, PixelFormat24bppRGB, 100, 68, ImageFlagsColorSpaceRGB | ImageFlagsHasRealDPI | ImageFlagsHasRealPixelSize | ImageFlagsReadOnly, 5, TRUE);
  126     GdipDisposeImage ((GpImage *) bitmap);
  127     
  128     status = GdipCreateBitmapFromFileICM (metafileFile, &bitmap);
  129     assertEqualInt (status, Ok);
  130     verifyBitmap ((GpImage *) bitmap, memoryBmpRawFormat, PixelFormat32bppARGB, 770, 649, ImageFlagsHasAlpha, 0, TRUE);
  131     GdipDisposeImage ((GpImage *) bitmap);
  132 
  133     status = GdipCreateBitmapFromFileICM (enhancedMetafileFile, &bitmap);
  134     assertEqualInt (status, Ok);
  135     verifyBitmap ((GpImage *) bitmap, memoryBmpRawFormat, PixelFormat32bppARGB, 100, 100, ImageFlagsHasAlpha, 0, TRUE);
  136     GdipDisposeImage ((GpImage *) bitmap);
  137 
  138     // Negative tests.
  139     status = GdipCreateBitmapFromFileICM (NULL, &bitmap);
  140     assertEqualInt (status, InvalidParameter);
  141 
  142     status = GdipCreateBitmapFromFileICM (noSuchFile, &bitmap);
  143     assertEqualInt (status, InvalidParameter);
  144 
  145     status = GdipCreateBitmapFromFileICM (invalidFile, &bitmap);
  146     assertEqualInt (status, InvalidParameter);
  147 
  148     status = GdipCreateBitmapFromFileICM (noSuchFile, NULL);
  149     assertEqualInt (status, InvalidParameter);
  150 
  151     freeWchar (bitmapFile);
  152     freeWchar (metafileFile);
  153     freeWchar (enhancedMetafileFile);
  154     freeWchar (noSuchFile);
  155     freeWchar (invalidFile);
  156 }
  157 
  158 static void test_createBitmapFromScan0 ()
  159 {
  160     GpStatus status;
  161     GpBitmap *bitmap;
  162     ARGB emptyPixelsWithAlpha[] = {0x00000000, 0x00000000,0x00000000};
  163     ARGB emptyPixelsWithNoAlpha[] = {0xFF000000, 0xFF000000,0xFF000000};
  164     
  165     // No scan0 - PixelFormat64bppARGB.
  166     status = GdipCreateBitmapFromScan0 (1, 2, 0, PixelFormat64bppARGB, NULL, &bitmap);
  167 #if defined(USE_WINDOWS_GDIPLUS)
  168     assertEqualInt (status, Ok);
  169     verifyBitmap (bitmap, memoryBmpRawFormat, PixelFormat64bppARGB, 1, 2, ImageFlagsHasAlpha, 0, TRUE);
  170     verifyPixels (bitmap, emptyPixelsWithAlpha);
  171     GdipDisposeImage ((GpImage *) bitmap);
  172 #else
  173     assertEqualInt (status, NotImplemented);
  174 #endif
  175     
  176     // Has scan0 - PixelFormat64bppARGB.
  177     BYTE bpp64ArgbData[] = {
  178         0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF,
  179         0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x80,
  180         0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00,
  181     };
  182     status = GdipCreateBitmapFromScan0 (1, 2, 8, PixelFormat64bppARGB, bpp64ArgbData, &bitmap);
  183 #if defined(USE_WINDOWS_GDIPLUS)
  184     // It appears that GDI+ ignores the data.
  185     ARGB bpp64ArgbPixels[] = {
  186         0x00000000,
  187         0x00000000,
  188         0x00000000,
  189     };
  190     assertEqualInt (status, Ok);
  191     verifyBitmap (bitmap, memoryBmpRawFormat, PixelFormat64bppARGB, 1, 2, ImageFlagsHasAlpha, 0, TRUE);
  192     verifyPixels (bitmap, bpp64ArgbPixels);
  193     GdipDisposeImage ((GpImage *) bitmap);
  194 #else
  195     assertEqualInt (status, NotImplemented);
  196 #endif
  197 
  198     // No scan0 - PixelFormat64bppPARGB.
  199     status = GdipCreateBitmapFromScan0 (1, 2, 0, PixelFormat64bppPARGB, NULL, &bitmap);
  200 #if defined(USE_WINDOWS_GDIPLUS)
  201     assertEqualInt (status, Ok);
  202     verifyBitmap (bitmap, memoryBmpRawFormat, PixelFormat64bppPARGB, 1, 2, ImageFlagsHasAlpha, 0, TRUE);
  203     verifyPixels (bitmap, emptyPixelsWithAlpha);
  204     GdipDisposeImage ((GpImage *) bitmap);
  205 #else
  206     assertEqualInt (status, NotImplemented);
  207 #endif
  208     
  209     // Has scan0 - PixelFormat64bppPARGB.
  210     BYTE bpp64PArgbData[] = {
  211         0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF,
  212         0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x80,
  213         0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00,
  214     };
  215     status = GdipCreateBitmapFromScan0 (1, 2, 8, PixelFormat64bppPARGB, bpp64PArgbData, &bitmap);
  216 #if defined(USE_WINDOWS_GDIPLUS)
  217     // It appears that GDI+ ignores the data.
  218     ARGB bpp64PArgbPixels[] = {
  219         0x00000000,
  220         0x00000000,
  221         0x00000000,
  222     };
  223     assertEqualInt (status, Ok);
  224     verifyBitmap (bitmap, memoryBmpRawFormat, PixelFormat64bppPARGB, 1, 2, ImageFlagsHasAlpha, 0, TRUE);
  225     verifyPixels (bitmap, bpp64PArgbPixels);
  226     GdipDisposeImage ((GpImage *) bitmap);
  227 #else
  228     assertEqualInt (status, NotImplemented);
  229 #endif
  230 
  231     // No scan0 - PixelFormat48bppRGB.
  232     status = GdipCreateBitmapFromScan0 (1, 2, 0, PixelFormat48bppRGB, NULL, &bitmap);
  233 #if defined(USE_WINDOWS_GDIPLUS)
  234     assertEqualInt (status, Ok);
  235     verifyBitmap (bitmap, memoryBmpRawFormat, PixelFormat48bppRGB, 1, 2, 0, 0, TRUE);
  236     verifyPixels (bitmap, emptyPixelsWithNoAlpha);
  237     GdipDisposeImage ((GpImage *) bitmap);
  238 #else
  239     assertEqualInt (status, NotImplemented);
  240 #endif
  241 
  242     // Has scan0 - PixelFormat48bppRGB.
  243     BYTE bpp48RgbData[] = {
  244         0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  245         0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
  246         0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00,
  247     };
  248     status = GdipCreateBitmapFromScan0 (1, 2, 8, PixelFormat48bppRGB, bpp48RgbData, &bitmap);
  249 #if defined(USE_WINDOWS_GDIPLUS)
  250     // It appears that GDI+ ignores the data.
  251     ARGB bpp48RgbPixels[] = {
  252         0xFF000000,
  253         0xFF000000,
  254         0xFF000000,
  255     };
  256     assertEqualInt (status, Ok);
  257     verifyBitmap (bitmap, memoryBmpRawFormat, PixelFormat48bppRGB, 1, 2, 0, 0, TRUE);
  258     verifyPixels (bitmap, bpp48RgbPixels);
  259     GdipDisposeImage ((GpImage *) bitmap);
  260 #else
  261     assertEqualInt (status, NotImplemented);
  262 #endif
  263 
  264     // No scan0 - PixelFormat32bppARGB.
  265     status = GdipCreateBitmapFromScan0 (1, 2, 0, PixelFormat32bppARGB, NULL, &bitmap);
  266     assertEqualInt (status, Ok);
  267     verifyBitmap (bitmap, memoryBmpRawFormat, PixelFormat32bppARGB, 1, 2, ImageFlagsHasAlpha, 0, TRUE);
  268     verifyPixels (bitmap, emptyPixelsWithAlpha);
  269     GdipDisposeImage ((GpImage *) bitmap);
  270 
  271     // Has scan0 - PixelFormat32bppARGB.
  272     BYTE bpp32ArgbData[] = {
  273         0xFF, 0x00, 0x00, 0xFF,
  274         0x00, 0xFF, 0x00, 0x80,
  275         0x00, 0x00, 0xFF, 0x00
  276     };
  277     ARGB bpp32ArgbPixels[] = {
  278         0xFF0000FF,
  279         0x8000FF00,
  280         0x00FF0000,
  281     };
  282     status = GdipCreateBitmapFromScan0 (1, 2, 4, PixelFormat32bppARGB, bpp32ArgbData, &bitmap);
  283     assertEqualInt (status, Ok);
  284     verifyBitmap (bitmap, memoryBmpRawFormat, PixelFormat32bppARGB, 1, 2, ImageFlagsHasAlpha, 0, TRUE);
  285     verifyPixels (bitmap, bpp32ArgbPixels);
  286     
  287     // Holds a reference to the original data.
  288     ARGB bpp32ArgbPixelsModified[] = {
  289         0xFF000000,
  290         0x8000FF00,
  291         0x00FF0000
  292     };
  293     bpp32ArgbData[0] = 0x00;
  294     verifyPixels (bitmap, bpp32ArgbPixelsModified);
  295     GdipDisposeImage ((GpImage *) bitmap);
  296 
  297     // No scan0 - PixelFormat32bppPARGB.
  298     status = GdipCreateBitmapFromScan0 (1, 2, 0, PixelFormat32bppPARGB, NULL, &bitmap);
  299     assertEqualInt (status, Ok);
  300     verifyBitmap (bitmap, memoryBmpRawFormat, PixelFormat32bppPARGB, 1, 2, ImageFlagsHasAlpha, 0, TRUE);
  301     verifyPixels (bitmap, emptyPixelsWithAlpha);
  302     GdipDisposeImage ((GpImage *) bitmap);
  303 
  304     // Has scan0 - PixelFormat32bppPARGB.
  305     BYTE bpp32PArgbData[] = {
  306         0xFF, 0x00, 0x00, 0xFF,
  307         0x00, 0xFF, 0x00, 0x80,
  308         0x00, 0x00, 0xFF, 0x00
  309     };
  310     ARGB bpp32PArgbPixels[] = {
  311         0xFF0000FF,
  312         0x8000FF00,
  313         0x00FF0000
  314     };
  315     status = GdipCreateBitmapFromScan0 (1, 2, 4, PixelFormat32bppPARGB, bpp32PArgbData, &bitmap);
  316     assertEqualInt (status, Ok);
  317     verifyBitmap (bitmap, memoryBmpRawFormat, PixelFormat32bppPARGB, 1, 2, ImageFlagsHasAlpha, 0, TRUE);
  318     verifyPixels (bitmap, bpp32PArgbPixels);
  319     
  320     // Holds a reference to the original data.
  321     ARGB bpp32PArgbPixelsModified[] = {
  322         0xFF000000,
  323         0x8000FF00,
  324         0x00FF0000
  325     };
  326     bpp32PArgbData[0] = 0x00;
  327     verifyPixels (bitmap, bpp32PArgbPixelsModified);
  328     GdipDisposeImage ((GpImage *) bitmap);
  329 
  330     // No scan0 - PixelFormat32bppRGB.
  331     status = GdipCreateBitmapFromScan0 (1, 2, 0, PixelFormat32bppRGB, NULL, &bitmap);
  332     assertEqualInt (status, Ok);
  333     verifyBitmap (bitmap, memoryBmpRawFormat, PixelFormat32bppRGB, 1, 2, 0, 0, TRUE);
  334     GdipDisposeImage ((GpImage *) bitmap);
  335 
  336     // Has scan0 - PixelFormat32bppRGB.
  337     BYTE bpp32RgbData[] = {
  338         0xFF, 0x00, 0x00, 0x00,
  339         0x00, 0xFF, 0x00, 0x00,
  340         0x00, 0x00, 0xFF, 0x00
  341     };
  342     ARGB bpp32RgbPixels[] = {
  343         0xFF0000FF,
  344         0xFF00FF00,
  345         0xFFFF0000
  346     };
  347     status = GdipCreateBitmapFromScan0 (1, 2, 4, PixelFormat32bppRGB, bpp32RgbData, &bitmap);
  348     assertEqualInt (status, Ok);
  349     verifyBitmap (bitmap, memoryBmpRawFormat, PixelFormat32bppRGB, 1, 2, 0, 0, TRUE);
  350     verifyPixels (bitmap, bpp32RgbPixels);
  351     
  352     // Holds a reference to the original data.
  353     ARGB bpp32RgbPixelsModified[] = {
  354         0xFF000000,
  355         0xFF00FF00,
  356         0xFFFF0000
  357     };
  358     bpp32RgbData[0] = 0x00;
  359     verifyPixels (bitmap, bpp32RgbPixelsModified);
  360     GdipDisposeImage ((GpImage *) bitmap);
  361 
  362     // No scan0 - PixelFormat32bppCMYK.
  363     status = GdipCreateBitmapFromScan0 (1, 2, 0, PixelFormat32bppCMYK, NULL, &bitmap);
  364 #if defined(USE_WINDOWS_GDIPLUS)
  365     assertEqualInt (status, Ok);
  366     verifyBitmap (bitmap, memoryBmpRawFormat, PixelFormat32bppCMYK, 1, 2, 0, 0, TRUE);
  367     // Don't verify the image pixel data as a bug in GDI+ means that we read uninitialized memory.
  368     GdipDisposeImage ((GpImage *) bitmap);
  369 #else
  370     assertEqualInt (status, NotImplemented);
  371 #endif
  372     
  373     BYTE bpp32CMYKData[] = {
  374         0xFF, 0x00, 0x00, 0x00,
  375         0x00, 0xFF, 0x00, 0x00,
  376         0x00, 0x00, 0xFF, 0x00
  377     };
  378     status = GdipCreateBitmapFromScan0 (1, 2, 4, PixelFormat32bppCMYK, bpp32CMYKData, &bitmap);
  379 #if defined(USE_WINDOWS_GDIPLUS)
  380     assertEqualInt (status, Ok);
  381     verifyBitmap (bitmap, memoryBmpRawFormat, PixelFormat32bppCMYK, 1, 2, 0, 0, TRUE);
  382     // Don't verify the image pixel data as a bug in GDI+ means that we read uninitialized memory.
  383     GdipDisposeImage ((GpImage *) bitmap);
  384 #else
  385     assertEqualInt (status, NotImplemented);
  386 #endif
  387 
  388     // No scan0 - PixelFormat24bppRGB.
  389     status = GdipCreateBitmapFromScan0 (1, 2, 0, PixelFormat24bppRGB, NULL, &bitmap);
  390     assertEqualInt (status, Ok);
  391     verifyBitmap (bitmap, memoryBmpRawFormat, PixelFormat24bppRGB, 1, 2, 0, 0, TRUE);
  392     verifyPixels (bitmap, emptyPixelsWithNoAlpha);
  393     GdipDisposeImage ((GpImage *) bitmap);
  394     
  395     // Has scan0 - PixelFormat24bppRGB.
  396     BYTE bpp24RgbData[] = {
  397         0xFF, 0x00, 0x00, 0x00,
  398         0x00, 0xFF, 0x00, 0x00,
  399         0x00, 0x00, 0xFF, 0x00
  400     };
  401     ARGB bpp24RgbPixels[] = {
  402         0xFF0000FF,
  403         0xFF00FF00,
  404         0xFFFF0000
  405     };
  406     status = GdipCreateBitmapFromScan0 (1, 2, 4, PixelFormat24bppRGB, bpp24RgbData, &bitmap);
  407     assertEqualInt (status, Ok);
  408     verifyBitmap (bitmap, memoryBmpRawFormat, PixelFormat24bppRGB, 1, 2, 0, 0, TRUE);
  409     verifyPixels (bitmap, bpp24RgbPixels);
  410     
  411     // Holds a reference to the original data.
  412     ARGB bpp24RgbPixelsModified[] = {
  413         0xFF000000,
  414         0xFF00FF00,
  415         0xFFFF0000
  416     };
  417     bpp24RgbData[0] = 0x00;
  418     verifyPixels (bitmap, bpp24RgbPixelsModified);
  419     GdipDisposeImage ((GpImage *) bitmap);
  420 
  421     // No scan0 - PixelFormat16bppRGB555.
  422     status = GdipCreateBitmapFromScan0 (1, 2, 0, PixelFormat16bppRGB555, NULL, &bitmap);
  423     assertEqualInt (status, Ok);
  424     verifyBitmap (bitmap, memoryBmpRawFormat, PixelFormat16bppRGB555, 1, 2, 0, 0, TRUE);
  425     verifyPixels (bitmap, emptyPixelsWithNoAlpha);
  426     GdipDisposeImage ((GpImage *) bitmap);
  427 
  428     // Has scan0 - PixelFormat16bppRGB555.
  429     BYTE bpp16rgb555Data[] = {
  430         0x1F, 0x00, 0x00, 0x00,
  431         0xE0, 0x03, 0x00, 0x00,
  432         0x00, 0x7C, 0x00, 0x00
  433     };
  434     ARGB bpp16rgb555Pixels[] = {
  435         0xFF0000FF,
  436         0xFF00FF00,
  437         0xFFFF0000,
  438     };
  439     status = GdipCreateBitmapFromScan0 (1, 2, 4, PixelFormat16bppRGB555, bpp16rgb555Data, &bitmap);
  440     assertEqualInt (status, Ok);
  441     verifyBitmap (bitmap, memoryBmpRawFormat, PixelFormat16bppRGB555, 1, 2, 0, 0, TRUE);
  442     verifyPixels (bitmap, bpp16rgb555Pixels);
  443 
  444     // Holds a reference to the original data.
  445     ARGB bpp16rgb555PixelsModified[] = {
  446         0xFF0000FF,
  447         0xFF00FF00,
  448         0xFF000000
  449     };
  450     bpp16rgb555Data[9] = 0x00;
  451     verifyPixels (bitmap, bpp16rgb555PixelsModified);
  452     GdipDisposeImage ((GpImage *) bitmap);
  453 
  454     // No scan0 - PixelFormat16bppRGB565.
  455     status = GdipCreateBitmapFromScan0 (1, 2, 0, PixelFormat16bppRGB565, NULL, &bitmap);
  456     assertEqualInt (status, Ok);
  457     verifyBitmap (bitmap, memoryBmpRawFormat, PixelFormat16bppRGB565, 1, 2, 0, 0, TRUE);
  458     verifyPixels (bitmap, emptyPixelsWithNoAlpha);
  459     GdipDisposeImage ((GpImage *) bitmap);
  460 
  461     // Has scan0 - PixelFormat16bppRGB565.
  462     BYTE bpp16rgb565Data[] = {
  463         0x1F, 0x00, 0x00, 0x00,
  464         0xE0, 0x07, 0x00, 0x00,
  465         0x00, 0xF8, 0x00, 0x00
  466     };
  467     ARGB bpp16rgb565Pixels[] = {
  468         0xFF0000FF,
  469         0xFF00FF00,
  470         0xFFFF0000
  471     };
  472     status = GdipCreateBitmapFromScan0 (1, 2, 4, PixelFormat16bppRGB565, bpp16rgb565Data, &bitmap);
  473     assertEqualInt (status, Ok);
  474     verifyBitmap (bitmap, memoryBmpRawFormat, PixelFormat16bppRGB565, 1, 2, 0, 0, TRUE);
  475     verifyPixels (bitmap, bpp16rgb565Pixels);
  476     
  477     // Holds a reference to the original data.
  478     ARGB bpp16rgb565PixelsModified[] = {
  479         0xFF0000FF,
  480         0xFF00FF00,
  481         0xFF000000
  482     };
  483     bpp16rgb565Data[9] = 0x00;
  484     verifyPixels (bitmap, bpp16rgb565PixelsModified);
  485     GdipDisposeImage ((GpImage *) bitmap);
  486     
  487     // No scan0 - PixelFormat16bppARGB1555.
  488     status = GdipCreateBitmapFromScan0 (1, 2, 0, PixelFormat16bppARGB1555, NULL, &bitmap);
  489 #if defined(USE_WINDOWS_GDIPLUS)
  490     assertEqualInt (status, Ok);
  491     verifyBitmap (bitmap, memoryBmpRawFormat, PixelFormat16bppARGB1555, 1, 2, ImageFlagsHasAlpha, 0, TRUE);
  492     verifyPixels (bitmap, emptyPixelsWithAlpha);
  493     GdipDisposeImage ((GpImage *) bitmap);
  494 #else
  495     assertEqualInt (status, NotImplemented);
  496 #endif
  497 
  498     // Has scan0 - PixelFormat16bppARGB1555.
  499     BYTE bpp16argb555Data[] = {
  500         0x1F, 0x80, 0x00, 0x00,
  501         0xE0, 0x03, 0x00, 0x00,
  502         0x00, 0x7C, 0x00, 0x00
  503     };
  504     status = GdipCreateBitmapFromScan0 (1, 2, 4, PixelFormat16bppARGB1555, bpp16argb555Data, &bitmap);
  505 #if defined(USE_WINDOWS_GDIPLUS)
  506     ARGB bpp16argb555Pixels[] = {
  507         0xFF0000FF,
  508         0x0000FF00,
  509         0x00FF0000
  510     };
  511     assertEqualInt (status, Ok);
  512     verifyBitmap (bitmap, memoryBmpRawFormat, PixelFormat16bppARGB1555, 1, 2, ImageFlagsHasAlpha, 0, TRUE);
  513     verifyPixels (bitmap, bpp16argb555Pixels);
  514 
  515     // Holds a reference to the original data.
  516     ARGB bpp16argb555PixelsModified[] = {
  517         0xFF0000FF,
  518         0x0000FF00,
  519         0x00000000
  520     };
  521     bpp16argb555Data[9] = 0x00;
  522     verifyPixels (bitmap, bpp16argb555PixelsModified);
  523     GdipDisposeImage ((GpImage *) bitmap);
  524 #else
  525     assertEqualInt (status, NotImplemented);
  526 #endif
  527     
  528     // No scan0 - PixelFormat16bppGrayScale.
  529     status = GdipCreateBitmapFromScan0 (1, 2, 0, PixelFormat16bppGrayScale, NULL, &bitmap);
  530 #if defined(USE_WINDOWS_GDIPLUS)
  531     assertEqualInt (status, Ok);
  532     verifyBitmap (bitmap, memoryBmpRawFormat, PixelFormat16bppGrayScale, 1, 2, 0, 0, TRUE);
  533     // Don't verify the image pixel data as a bug in GDI+ means that we read uninitialized memory.
  534     GdipDisposeImage ((GpImage *) bitmap);
  535 #else
  536     assertEqualInt (status, NotImplemented);
  537 #endif
  538     
  539     // Has scan0 - PixelFormat16bppGrayScale.
  540     BYTE bpp16grayscaleData[] = {
  541         0x1F, 0x80, 0x00, 0x00,
  542         0xE0, 0x03, 0x00, 0x00,
  543         0x00, 0x7C, 0x00, 0x00
  544     };
  545     status = GdipCreateBitmapFromScan0 (1, 2, 4, PixelFormat16bppGrayScale, bpp16grayscaleData, &bitmap);
  546 #if defined(USE_WINDOWS_GDIPLUS)
  547     assertEqualInt (status, Ok);
  548     verifyBitmap (bitmap, memoryBmpRawFormat, PixelFormat16bppGrayScale, 1, 2, 0, 0, TRUE);
  549     // Don't verify the image pixel data as a bug in GDI+ means that we read uninitialized memory.
  550     GdipDisposeImage ((GpImage *) bitmap);
  551 #else
  552     assertEqualInt (status, NotImplemented);
  553 #endif
  554 
  555     // No scan0 - PixelFormat8bppIndexed.
  556     status = GdipCreateBitmapFromScan0 (1, 2, 0, PixelFormat8bppIndexed, NULL, &bitmap);
  557     assertEqualInt (status, Ok);
  558     verifyBitmap (bitmap, memoryBmpRawFormat, PixelFormat8bppIndexed, 1, 2, ImageFlagsHasAlpha, 0, TRUE);
  559     verifyPixels (bitmap, emptyPixelsWithNoAlpha);
  560     GdipDisposeImage ((GpImage *) bitmap);
  561     
  562     // Has scan0 - PixelFormat8bppIndexed.
  563     BYTE bpp8indexedData[] = {
  564         0x0C, 0x00, 0x00, 0x00,
  565         0x0A, 0x00, 0x00, 0x00,
  566         0x09, 0x00, 0x00, 0x00
  567     };
  568     status = GdipCreateBitmapFromScan0 (1, 2, 4, PixelFormat8bppIndexed, bpp8indexedData, &bitmap);
  569     ARGB bpp8indexedPixels[] = {
  570         0xFF0000FF,
  571         0xFF00FF00,
  572         0xFFFF0000
  573     };
  574     assertEqualInt (status, Ok);
  575     verifyBitmap (bitmap, memoryBmpRawFormat, PixelFormat8bppIndexed, 1, 2, ImageFlagsHasAlpha, 0, TRUE);
  576     verifyPixels (bitmap, bpp8indexedPixels);
  577     
  578     // Holds a reference to the original data.
  579     ARGB bpp8indexedPixelsModified[] = {
  580         0xFFFF0000,
  581         0xFF00FF00,
  582         0xFFFF0000
  583     };
  584     bpp8indexedData[0] = 0x09;
  585     verifyPixels (bitmap, bpp8indexedPixelsModified);
  586     GdipDisposeImage ((GpImage *) bitmap);
  587     
  588     // No scan0 - PixelFormat4bppIndexed.
  589     status = GdipCreateBitmapFromScan0 (1, 2, 0, PixelFormat4bppIndexed, NULL, &bitmap);
  590     assertEqualInt (status, Ok);
  591     verifyBitmap (bitmap, memoryBmpRawFormat, PixelFormat4bppIndexed, 1, 2, ImageFlagsHasAlpha, 0, TRUE);
  592     verifyPixels (bitmap, emptyPixelsWithNoAlpha);
  593     GdipDisposeImage ((GpImage *) bitmap);
  594     
  595     // Has scan0 - PixelFormat4bppIndexed.
  596     BYTE bpp4indexedData[] = {
  597         0xC0, 0x00, 0x00, 0x00,
  598         0xA0, 0x00, 0x00, 0x00,
  599         0x90, 0x00, 0x00, 0x00
  600     };
  601     status = GdipCreateBitmapFromScan0 (1, 2, 4, PixelFormat4bppIndexed, bpp4indexedData, &bitmap);
  602     ARGB bpp4indexedPixels[] = {
  603         0xFF0000FF,
  604         0xFF00FF00,
  605         0xFFFF0000
  606     };
  607     assertEqualInt (status, Ok);
  608     verifyBitmap (bitmap, memoryBmpRawFormat, PixelFormat4bppIndexed, 1, 2, ImageFlagsHasAlpha, 0, TRUE);
  609     verifyPixels (bitmap, bpp4indexedPixels);
  610     
  611     // Holds a reference to the original data.
  612     ARGB bpp4indexedPixelsModified[] = {
  613         0xFFFF0000,
  614         0xFF00FF00,
  615         0xFFFF0000
  616     };
  617     bpp4indexedData[0] = 0x90;
  618     verifyPixels (bitmap, bpp4indexedPixelsModified);
  619     GdipDisposeImage ((GpImage *) bitmap);
  620     
  621     // No scan0 - PixelFormat1bppIndexed.
  622     status = GdipCreateBitmapFromScan0 (1, 2, 0, PixelFormat1bppIndexed, NULL, &bitmap);
  623     assertEqualInt (status, Ok);
  624     verifyBitmap (bitmap, memoryBmpRawFormat, PixelFormat1bppIndexed, 1, 2, ImageFlagsHasAlpha, 0, TRUE);
  625     verifyPixels (bitmap, emptyPixelsWithNoAlpha);
  626     GdipDisposeImage ((GpImage *) bitmap);
  627     
  628     // Has scan0 - PixelFormat1bppIndexed.
  629     BYTE bpp1indexedData[] = {
  630         0x00, 0x00, 0x00, 0x00,
  631         0x80, 0x00, 0x00, 0x00,
  632         0x80, 0x00, 0x00, 0x00
  633     };
  634     status = GdipCreateBitmapFromScan0 (1, 2, 4, PixelFormat1bppIndexed, bpp1indexedData, &bitmap);
  635     ARGB bpp1indexedPixels[] = {
  636         0xFF000000,
  637         0xFFFFFFFF,
  638         0xFFFFFFFF
  639     };
  640     assertEqualInt (status, Ok);
  641     verifyBitmap (bitmap, memoryBmpRawFormat, PixelFormat1bppIndexed, 1, 2, ImageFlagsHasAlpha, 0, TRUE);
  642     verifyPixels (bitmap, bpp1indexedPixels);
  643 
  644     // Holds a reference to the original data.
  645     ARGB bpp1indexedPixelsModified[] = {
  646         0xFF000000,
  647         0xFFFFFFFF,
  648         0xFF000000
  649     };
  650     bpp1indexedData[8] = 0x00;
  651     verifyPixels (bitmap, bpp1indexedPixelsModified);
  652     GdipDisposeImage ((GpImage *) bitmap);
  653 
  654     // Negative tests.
  655     status = GdipCreateBitmapFromScan0 (0, 2, 0, PixelFormat32bppRGB, NULL, &bitmap);
  656     assertEqualInt (status, InvalidParameter);
  657     
  658     status = GdipCreateBitmapFromScan0 (-1, 2, 0, PixelFormat32bppRGB, NULL, &bitmap);
  659     assertEqualInt (status, InvalidParameter);
  660     
  661     status = GdipCreateBitmapFromScan0 (1, 0, 0, PixelFormat32bppRGB, NULL, &bitmap);
  662     assertEqualInt (status, InvalidParameter);
  663     
  664     status = GdipCreateBitmapFromScan0 (1, -1, 0, PixelFormat32bppRGB, NULL, &bitmap);
  665     assertEqualInt (status, InvalidParameter);
  666 
  667     status = GdipCreateBitmapFromScan0 (1, 2, -1, PixelFormat32bppRGB, bpp32RgbData, &bitmap);
  668     assertEqualInt (status, InvalidParameter);
  669     
  670     status = GdipCreateBitmapFromScan0 (1, 2, 0, PixelFormat32bppRGB, bpp32RgbData, &bitmap);
  671     assertEqualInt (status, InvalidParameter);
  672     
  673     status = GdipCreateBitmapFromScan0 (1, 2, 3, PixelFormat32bppRGB, bpp32RgbData, &bitmap);
  674     assertEqualInt (status, InvalidParameter);
  675 
  676     status = GdipCreateBitmapFromScan0 (1, 2, 0, PixelFormatIndexed, NULL, &bitmap);
  677     assertEqualInt (status, InvalidParameter);
  678     
  679     status = GdipCreateBitmapFromScan0 (1, 2, 0, PixelFormatGDI, NULL, &bitmap);
  680     assertEqualInt (status, InvalidParameter);
  681     
  682     status = GdipCreateBitmapFromScan0 (1, 2, 0, PixelFormatAlpha, NULL, &bitmap);
  683     assertEqualInt (status, InvalidParameter);
  684     
  685     status = GdipCreateBitmapFromScan0 (1, 2, 0, PixelFormatPAlpha, NULL, &bitmap);
  686     assertEqualInt (status, InvalidParameter);
  687     
  688     status = GdipCreateBitmapFromScan0 (1, 2, 0, PixelFormatExtended, NULL, &bitmap);
  689     assertEqualInt (status, InvalidParameter);
  690     
  691     status = GdipCreateBitmapFromScan0 (1, 2, 0, PixelFormatCanonical, NULL, &bitmap);
  692     assertEqualInt (status, InvalidParameter);
  693     
  694     status = GdipCreateBitmapFromScan0 (1, 2, 0, PixelFormatUndefined, NULL, &bitmap);
  695     assertEqualInt (status, InvalidParameter);
  696 }
  697 
  698 static void test_createBitmapFromGraphics ()
  699 {
  700     GpStatus status;
  701     GpBitmap *source;
  702     GpBitmap *sourceWithResolution;
  703     GpGraphics *graphics;
  704     GpGraphics *graphicsWithResolution;
  705     GpBitmap *bitmap;
  706     GpGraphics *bitmapGraphics;
  707     REAL dpiX;
  708     REAL dpiY;
  709 
  710     GdipCreateBitmapFromScan0 (10, 10, 0, PixelFormat24bppRGB, NULL, &source);
  711     GdipCreateBitmapFromScan0 (10, 10, 0, PixelFormat24bppRGB, NULL, &sourceWithResolution);
  712     GdipBitmapSetResolution (sourceWithResolution, 100, 124);
  713 
  714     GdipGetImageGraphicsContext ((GpImage *) source, &graphics);
  715     GdipGetImageGraphicsContext ((GpImage *) sourceWithResolution, &graphicsWithResolution);
  716 
  717     status = GdipCreateBitmapFromGraphics (24, 32, graphics, &bitmap);
  718     assertEqualInt (status, Ok);
  719     verifyBitmap (bitmap, memoryBmpRawFormat, PixelFormat32bppPARGB, 24, 32, ImageFlagsHasAlpha, 0, TRUE);
  720     GdipDisposeImage ((GpImage *) bitmap);
  721 
  722     status = GdipCreateBitmapFromGraphics (24, 32, graphicsWithResolution, &bitmap);
  723     assertEqualInt (status, Ok);
  724     verifyBitmap (bitmap, memoryBmpRawFormat, PixelFormat32bppPARGB, 24, 32, ImageFlagsHasAlpha, 0, TRUE);
  725     
  726     // Verify the DPI.
  727     GdipGetImageGraphicsContext ((GpImage *) bitmap, &bitmapGraphics);
  728     GdipGetDpiX (bitmapGraphics, &dpiX);
  729     GdipGetDpiY (bitmapGraphics, &dpiY);
  730     assertEqualFloat (dpiX, 100);
  731     assertEqualFloat (dpiY, 124);
  732 
  733     GdipDisposeImage ((GpImage *) bitmap);
  734     GdipDeleteGraphics (bitmapGraphics);
  735 
  736     // Negative tests.
  737     status = GdipCreateBitmapFromGraphics (0, 32, graphics, &bitmap);
  738     assertEqualInt (status, InvalidParameter);
  739 
  740     status = GdipCreateBitmapFromGraphics (-1, 32, graphics, &bitmap);
  741     assertEqualInt (status, InvalidParameter);
  742 
  743     status = GdipCreateBitmapFromGraphics (24, 0, graphics, &bitmap);
  744     assertEqualInt (status, InvalidParameter);
  745 
  746     status = GdipCreateBitmapFromGraphics (24, -1, graphics, &bitmap);
  747     assertEqualInt (status, InvalidParameter);
  748 
  749     status = GdipCreateBitmapFromGraphics (24, 32, NULL, &bitmap);
  750     assertEqualInt (status, InvalidParameter);
  751 
  752     status = GdipCreateBitmapFromGraphics (24, 32, graphics, NULL);
  753     assertEqualInt (status, InvalidParameter);
  754 
  755     GdipDisposeImage ((GpImage *) source);
  756     GdipDisposeImage ((GpImage *) sourceWithResolution);
  757     GdipDeleteGraphics (graphics);
  758     GdipDeleteGraphics (graphicsWithResolution);
  759 }
  760 
  761 static void test_bitmapLockBits ()
  762 {
  763     GpStatus status;
  764     GpBitmap *image;
  765     GpBitmap *indexedImage;
  766     BitmapData data;
  767     memset (&data, 0, sizeof (data));
  768     
  769     GdipCreateBitmapFromScan0 (3, 4, 0, PixelFormat32bppRGB, NULL, &image);
  770     GdipCreateBitmapFromScan0 (3, 4, 0, PixelFormat32bppRGB, NULL, &indexedImage);
  771 
  772     // Negative tests.
  773     status = GdipBitmapLockBits (NULL, NULL, 0, PixelFormat32bppARGB, &data);
  774     assertEqualInt (status, InvalidParameter);
  775 
  776     Rect negativeX = {-1, 0, 3, 4};
  777     status = GdipBitmapLockBits (image, &negativeX, 0, PixelFormat32bppRGB, &data);
  778     assertEqualInt (status, InvalidParameter);
  779     
  780     status = GdipBitmapLockBits (indexedImage, &negativeX, 0, PixelFormat8bppIndexed, &data);
  781     assertEqualInt (status, InvalidParameter);
  782 
  783     Rect negativeY = {0, -1, 3, 4};
  784     status = GdipBitmapLockBits (image, &negativeY, 0, PixelFormat32bppRGB, &data);
  785     assertEqualInt (status, InvalidParameter);
  786     
  787     status = GdipBitmapLockBits (indexedImage, &negativeY, 0, PixelFormat8bppIndexed, &data);
  788     assertEqualInt (status, InvalidParameter);
  789 
  790     Rect negativeWidth = {0, 0, -1, 4};
  791     status = GdipBitmapLockBits (image, &negativeWidth, 0, PixelFormat32bppRGB, &data);
  792     assertEqualInt (status, InvalidParameter);
  793     
  794     status = GdipBitmapLockBits (indexedImage, &negativeWidth, 0, PixelFormat8bppIndexed, &data);
  795     assertEqualInt (status, InvalidParameter);
  796 
  797     Rect zeroWidth = {0, 0, 0, 4};
  798     status = GdipBitmapLockBits (image, &zeroWidth, 0, PixelFormat32bppRGB, &data);
  799     assertEqualInt (status, InvalidParameter);
  800     
  801     status = GdipBitmapLockBits (indexedImage, &zeroWidth, 0, PixelFormat8bppIndexed, &data);
  802     assertEqualInt (status, InvalidParameter);
  803 
  804     Rect largeWidth = {0, 0, 4, 4};
  805     status = GdipBitmapLockBits (image, &largeWidth, 0, PixelFormat32bppRGB, &data);
  806     assertEqualInt (status, InvalidParameter);
  807     
  808     status = GdipBitmapLockBits (indexedImage, &largeWidth, 0, PixelFormat8bppIndexed, &data);
  809     assertEqualInt (status, InvalidParameter);
  810 
  811     Rect negativeHeight = {0, 0, 3, -1};
  812     status = GdipBitmapLockBits (image, &negativeHeight, 0, PixelFormat32bppRGB, &data);
  813     assertEqualInt (status, InvalidParameter);
  814     
  815     status = GdipBitmapLockBits (indexedImage, &negativeHeight, 0, PixelFormat8bppIndexed, &data);
  816     assertEqualInt (status, InvalidParameter);
  817 
  818     Rect zeroHeight = {0, 0, 3, 0};
  819     status = GdipBitmapLockBits (image, &zeroHeight, 0, PixelFormat32bppRGB, &data);
  820     assertEqualInt (status, InvalidParameter);
  821     
  822     status = GdipBitmapLockBits (indexedImage, &zeroHeight, 0, PixelFormat8bppIndexed, &data);
  823     assertEqualInt (status, InvalidParameter);
  824 
  825     Rect largeHeight = {0, 0, 3, 5};
  826     status = GdipBitmapLockBits (image, &largeHeight, 0, PixelFormat32bppRGB, &data);
  827     assertEqualInt (status, InvalidParameter);
  828     
  829     status = GdipBitmapLockBits (indexedImage, &largeHeight, 0, PixelFormat8bppIndexed, &data);
  830     assertEqualInt (status, InvalidParameter);
  831 
  832     status = GdipBitmapLockBits (image, NULL, 0, PixelFormat32bppCMYK, &data);
  833     assertEqualInt (status, InvalidParameter);
  834 
  835     Rect invalidXWidth = {2, 0, 2, 4};
  836     status = GdipBitmapLockBits (image, &invalidXWidth, 0, PixelFormat32bppRGB, &data);
  837     assertEqualInt (status, InvalidParameter);
  838     
  839     status = GdipBitmapLockBits (indexedImage, &invalidXWidth, 0, PixelFormat8bppIndexed, &data);
  840     assertEqualInt (status, InvalidParameter);
  841 
  842     Rect invalidYHeight = {0, 2, 3, 3};
  843     status = GdipBitmapLockBits (image, &invalidYHeight, 0, PixelFormat32bppRGB, &data);
  844     assertEqualInt (status, InvalidParameter);
  845     
  846     status = GdipBitmapLockBits (indexedImage, &invalidYHeight, 0, PixelFormat8bppIndexed, &data);
  847     assertEqualInt (status, InvalidParameter);
  848 
  849     status = GdipBitmapLockBits (image, NULL, 0, PixelFormat32bppCMYK, &data);
  850     assertEqualInt (status, InvalidParameter);
  851     
  852     status = GdipBitmapLockBits (image, NULL, 0, PixelFormatIndexed, &data);
  853     assertEqualInt (status, InvalidParameter);
  854     
  855     status = GdipBitmapLockBits (image, NULL, 0, PixelFormatGDI, &data);
  856     assertEqualInt (status, InvalidParameter);
  857     
  858     status = GdipBitmapLockBits (image, NULL, 0, PixelFormatAlpha, &data);
  859     assertEqualInt (status, InvalidParameter);
  860     
  861     status = GdipBitmapLockBits (image, NULL, 0, PixelFormatPAlpha, &data);
  862     assertEqualInt (status, InvalidParameter);
  863     
  864     status = GdipBitmapLockBits (image, NULL, 0, PixelFormatExtended, &data);
  865     assertEqualInt (status, InvalidParameter);
  866     
  867     status = GdipBitmapLockBits (image, NULL, 0, PixelFormatCanonical, &data);
  868     assertEqualInt (status, InvalidParameter);
  869     
  870     status = GdipBitmapLockBits (image, NULL, 0, PixelFormatUndefined, &data);
  871     assertEqualInt (status, InvalidParameter);
  872     
  873     status = GdipBitmapLockBits (image, NULL, 0, -10, &data);
  874     assertEqualInt (status, InvalidParameter);
  875     
  876     status = GdipBitmapLockBits (image, NULL, 0, PixelFormat32bppARGB, NULL);
  877     assertEqualInt (status, InvalidParameter);
  878     
  879     // Locked.
  880     status = GdipBitmapLockBits (image, NULL, 0, PixelFormat32bppARGB, &data);
  881     assertEqualInt (status, Ok);
  882     
  883     status = GdipBitmapLockBits (image, NULL, 0, PixelFormat32bppARGB, &data);
  884     assertEqualInt (status, WrongState);
  885     
  886     status = GdipBitmapLockBits (image, NULL, 0, PixelFormat32bppARGB, NULL);
  887     assertEqualInt (status, InvalidParameter);
  888     
  889     status = GdipBitmapLockBits (image, NULL, 0, PixelFormat32bppCMYK, &data);
  890     assertEqualInt (status, WrongState);
  891     
  892     status = GdipBitmapLockBits (image, NULL, 0, -10, &data);
  893     assertEqualInt (status, WrongState);
  894 
  895     status = GdipBitmapUnlockBits (image, &data);
  896     assertEqualInt (status, Ok);
  897 
  898     GdipDisposeImage ((GpImage *) image);
  899     GdipDisposeImage ((GpImage *) indexedImage);
  900 }
  901 
  902 static void test_bitmapUnlockBits ()
  903 {
  904     GpStatus status;
  905     GpBitmap *image;
  906     BYTE scan0[] = {
  907         0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x02, 0x03, 0x04,
  908         0x7F, 0xFF, 0x00, 0x80, 0x7F, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0x80, 0x01, 0x02, 0x03, 0x04,
  909         0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0x01, 0x02, 0x03, 0x04,
  910     };
  911     BitmapData data;
  912     memset (&data, 0, sizeof (data));
  913     
  914     GdipCreateBitmapFromScan0 (3, 4, 16, PixelFormat32bppARGB, scan0, &image);
  915 
  916     // Negative tests.
  917     status = GdipBitmapUnlockBits (NULL, &data);
  918     assertEqualInt (status, InvalidParameter);
  919 
  920     status = GdipBitmapUnlockBits (image, NULL);
  921     assertEqualInt (status, InvalidParameter);
  922     
  923     status = GdipBitmapUnlockBits (image, &data);
  924     assertEqualInt (status, Win32Error);
  925 
  926     GdipDisposeImage ((GpImage *) image);
  927 }
  928 
  929 int
  930 main(int argc, char**argv)
  931 {
  932     STARTUP;
  933 
  934     test_createBitmapFromStream ();
  935     test_createBitmapFromFile ();
  936     test_createBitmapFromStreamICM ();
  937     test_createBitmapFromFileICM ();
  938     test_createBitmapFromScan0 ();
  939     test_createBitmapFromGraphics ();
  940     test_bitmapLockBits ();
  941     test_bitmapUnlockBits ();
  942 
  943     SHUTDOWN;
  944     return 0;
  945 }