~ubuntu-branches/ubuntu/precise/wine1.3/precise

« back to all changes in this revision

Viewing changes to dlls/gdi32/tests/bitmap.c

  • Committer: Package Import Robot
  • Author(s): Scott Ritchie
  • Date: 2012-01-17 09:00:34 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20120117090034-eyhpp02jawlvrrkc
Tags: 1.3.37-0ubuntu1
* New upstream release
  - Many changes
* Convert to 3.0 source format
* debian/control:
  - Remove pre-multiarch amd64 build depends
  - Remove quilt build depends
  - Recommend proper gecko versions
* debian/rules:
  - Remove manual dh_quilt patch and unpatch
  - No need to uuencode/uudecode anymore with new source format

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
#include "wine/test.h"
34
34
 
35
35
static BOOL (WINAPI *pGdiAlphaBlend)(HDC,int,int,int,int,HDC,int,int,int,int,BLENDFUNCTION);
 
36
static BOOL (WINAPI *pGdiGradientFill)(HDC,TRIVERTEX*,ULONG,void*,ULONG,ULONG);
36
37
static DWORD (WINAPI *pSetLayout)(HDC hdc, DWORD layout);
37
38
 
38
 
#define expect_eq(expr, value, type, format) { type ret = (expr); ok((value) == ret, #expr " expected " format " got " format "\n", value, ret); }
39
 
 
40
 
static INT BITMAP_GetWidthBytes( INT bmWidth, INT bpp )
41
 
{
42
 
    switch(bpp)
43
 
    {
44
 
    case 1:
45
 
        return 2 * ((bmWidth+15) >> 4);
46
 
 
47
 
    case 24:
48
 
        bmWidth *= 3; /* fall through */
49
 
    case 8:
50
 
        return bmWidth + (bmWidth & 1);
51
 
 
52
 
    case 32:
53
 
        return bmWidth * 4;
54
 
 
55
 
    case 16:
56
 
    case 15:
57
 
        return bmWidth * 2;
58
 
 
59
 
    case 4:
60
 
        return 2 * ((bmWidth+3) >> 2);
61
 
 
62
 
    default:
63
 
        trace("Unknown depth %d, please report.\n", bpp );
64
 
        assert(0);
65
 
    }
66
 
    return -1;
 
39
static inline int get_bitmap_stride( int width, int bpp )
 
40
{
 
41
    return ((width * bpp + 15) >> 3) & ~1;
 
42
}
 
43
 
 
44
static inline int get_dib_stride( int width, int bpp )
 
45
{
 
46
    return ((width * bpp + 31) >> 3) & ~3;
 
47
}
 
48
 
 
49
static inline int get_dib_image_size( const BITMAPINFO *info )
 
50
{
 
51
    return get_dib_stride( info->bmiHeader.biWidth, info->bmiHeader.biBitCount )
 
52
        * abs( info->bmiHeader.biHeight );
67
53
}
68
54
 
69
55
static void test_bitmap_info(HBITMAP hbm, INT expected_depth, const BITMAPINFOHEADER *bmih)
79
65
    ok(bm.bmType == 0, "wrong bm.bmType %d\n", bm.bmType);
80
66
    ok(bm.bmWidth == bmih->biWidth, "wrong bm.bmWidth %d\n", bm.bmWidth);
81
67
    ok(bm.bmHeight == bmih->biHeight, "wrong bm.bmHeight %d\n", bm.bmHeight);
82
 
    width_bytes = BITMAP_GetWidthBytes(bm.bmWidth, bm.bmBitsPixel);
 
68
    width_bytes = get_bitmap_stride(bm.bmWidth, bm.bmBitsPixel);
83
69
    ok(bm.bmWidthBytes == width_bytes, "wrong bm.bmWidthBytes %d != %d\n", bm.bmWidthBytes, width_bytes);
84
70
    ok(bm.bmPlanes == bmih->biPlanes, "wrong bm.bmPlanes %d\n", bm.bmPlanes);
85
71
    ok(bm.bmBitsPixel == expected_depth, "wrong bm.bmBitsPixel %d != %d\n", bm.bmBitsPixel, expected_depth);
253
239
    ReleaseDC(0, hdc);
254
240
}
255
241
 
256
 
static INT DIB_GetWidthBytes( int width, int bpp )
257
 
{
258
 
    return ((width * bpp + 31) / 8) & ~3;
259
 
}
260
 
 
261
242
static void test_dib_info(HBITMAP hbm, const void *bits, const BITMAPINFOHEADER *bmih)
262
243
{
263
244
    BITMAP bm;
273
254
    ok(bm.bmType == 0, "wrong bm.bmType %d\n", bm.bmType);
274
255
    ok(bm.bmWidth == bmih->biWidth, "wrong bm.bmWidth %d\n", bm.bmWidth);
275
256
    ok(bm.bmHeight == abs(bmih->biHeight), "wrong bm.bmHeight %d\n", bm.bmHeight);
276
 
    dib_width_bytes = DIB_GetWidthBytes(bm.bmWidth, bm.bmBitsPixel);
277
 
    bm_width_bytes = BITMAP_GetWidthBytes(bm.bmWidth, bm.bmBitsPixel);
 
257
    dib_width_bytes = get_dib_stride(bm.bmWidth, bm.bmBitsPixel);
 
258
    bm_width_bytes = get_bitmap_stride(bm.bmWidth, bm.bmBitsPixel);
278
259
    if (bm.bmWidthBytes != dib_width_bytes) /* Win2k bug */
279
260
        ok(bm.bmWidthBytes == bm_width_bytes, "wrong bm.bmWidthBytes %d != %d\n", bm.bmWidthBytes, bm_width_bytes);
280
261
    else
358
339
    ok(ret == 0, "%d != 0\n", ret);
359
340
}
360
341
 
361
 
#define test_color_todo(got, exp, txt, todo) \
362
 
    if (!todo && got != exp && screen_depth < 24) { \
363
 
      todo_wine ok(0, #txt " failed at %d-bit screen depth: got 0x%06x expected 0x%06x - skipping DIB tests\n", \
364
 
                   screen_depth, (UINT)got, (UINT)exp); \
365
 
      return; \
366
 
    } else if (todo) todo_wine { ok(got == exp, #txt " failed: got 0x%06x expected 0x%06x\n", (UINT)got, (UINT)exp); } \
367
 
    else ok(got == exp, #txt " failed: got 0x%06x expected 0x%06x\n", (UINT)got, (UINT)exp) \
368
 
 
369
 
#define test_color(hdc, color, exp, todo_setp, todo_getp) \
 
342
#define test_color(hdc, color, exp) \
370
343
{ \
371
344
    COLORREF c; \
372
345
    c = SetPixel(hdc, 0, 0, color); \
373
 
    test_color_todo(c, exp, SetPixel, todo_setp); \
 
346
    ok(c == exp, "SetPixel failed: got 0x%06x expected 0x%06x\n", c, (UINT)exp); \
374
347
    c = GetPixel(hdc, 0, 0); \
375
 
    test_color_todo(c, exp, GetPixel, todo_getp); \
 
348
    ok(c == exp, "GetPixel failed: got 0x%06x expected 0x%06x\n", c, (UINT)exp); \
 
349
    c = GetNearestColor(hdc, color); \
 
350
    ok(c == exp, "GetNearestColor failed: got 0x%06x expected 0x%06x\n", c, (UINT)exp); \
376
351
}
377
352
 
378
353
static void test_dib_bits_access( HBITMAP hdib, void *bits )
442
417
    char bcibuf[sizeof(BITMAPCOREINFO) + 256 * sizeof(RGBTRIPLE)];
443
418
    BITMAPINFO *pbmi = (BITMAPINFO *)bmibuf;
444
419
    BITMAPCOREINFO *pbci = (BITMAPCOREINFO *)bcibuf;
 
420
    RGBQUAD *colors = pbmi->bmiColors;
 
421
    RGBTRIPLE *ccolors = pbci->bmciColors;
445
422
    HBITMAP hcoredib;
446
423
    char coreBits[256];
447
424
    BYTE *bits;
449
426
    int ret;
450
427
    char logpalbuf[sizeof(LOGPALETTE) + 256 * sizeof(PALETTEENTRY)];
451
428
    LOGPALETTE *plogpal = (LOGPALETTE*)logpalbuf;
 
429
    PALETTEENTRY *palent = plogpal->palPalEntry;
452
430
    WORD *index;
453
431
    DWORD *bits32;
454
432
    HPALETTE hpal, oldpal;
455
433
    DIBSECTION dibsec;
456
434
    COLORREF c0, c1;
457
435
    int i;
458
 
    int screen_depth;
459
436
    MEMORY_BASIC_INFORMATION info;
460
437
 
461
438
    hdc = GetDC(0);
462
 
    screen_depth = GetDeviceCaps(hdc, BITSPIXEL) * GetDeviceCaps(hdc, PLANES);
463
439
 
464
440
    memset(pbmi, 0, sizeof(bmibuf));
465
441
    pbmi->bmiHeader.biSize = sizeof(pbmi->bmiHeader);
543
519
    pbmi->bmiHeader.biBitCount = 1;
544
520
    pbmi->bmiHeader.biPlanes = 1;
545
521
    pbmi->bmiHeader.biCompression = BI_RGB;
546
 
    pbmi->bmiColors[0].rgbRed = 0xff;
547
 
    pbmi->bmiColors[0].rgbGreen = 0;
548
 
    pbmi->bmiColors[0].rgbBlue = 0;
549
 
    pbmi->bmiColors[1].rgbRed = 0;
550
 
    pbmi->bmiColors[1].rgbGreen = 0;
551
 
    pbmi->bmiColors[1].rgbBlue = 0xff;
 
522
    colors[0].rgbRed = 0xff;
 
523
    colors[0].rgbGreen = 0;
 
524
    colors[0].rgbBlue = 0;
 
525
    colors[1].rgbRed = 0;
 
526
    colors[1].rgbGreen = 0;
 
527
    colors[1].rgbBlue = 0xff;
552
528
 
553
529
    hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
554
530
    ok(hdib != NULL, "CreateDIBSection failed\n");
569
545
 
570
546
    ret = GetDIBits(hdc, hdib, 0, 16, &coreBits, (BITMAPINFO*) pbci, DIB_RGB_COLORS);
571
547
    ok(ret, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
572
 
    ok((pbci->bmciColors[0].rgbtRed == 0xff) && (pbci->bmciColors[0].rgbtGreen == 0) &&
573
 
        (pbci->bmciColors[0].rgbtBlue == 0) && (pbci->bmciColors[1].rgbtRed == 0) &&
574
 
        (pbci->bmciColors[1].rgbtGreen == 0) && (pbci->bmciColors[1].rgbtBlue == 0xff),
 
548
    ok((ccolors[0].rgbtRed == 0xff) && (ccolors[0].rgbtGreen == 0) &&
 
549
        (ccolors[0].rgbtBlue == 0) && (ccolors[1].rgbtRed == 0) &&
 
550
        (ccolors[1].rgbtGreen == 0) && (ccolors[1].rgbtBlue == 0xff),
575
551
        "The color table has not been translated to the old BITMAPCOREINFO format\n");
576
552
 
577
553
    hcoredib = CreateDIBSection(hdc, (BITMAPINFO*) pbci, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
578
554
    ok(hcoredib != NULL, "CreateDIBSection failed with a BITMAPCOREINFO\n");
579
555
 
580
 
    ZeroMemory(pbci->bmciColors, 256 * sizeof(RGBTRIPLE));
 
556
    ZeroMemory(ccolors, 256 * sizeof(RGBTRIPLE));
581
557
    ret = GetDIBits(hdc, hcoredib, 0, 16, &coreBits, (BITMAPINFO*) pbci, DIB_RGB_COLORS);
582
558
    ok(ret, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
583
 
    ok((pbci->bmciColors[0].rgbtRed == 0xff) && (pbci->bmciColors[0].rgbtGreen == 0) &&
584
 
        (pbci->bmciColors[0].rgbtBlue == 0) && (pbci->bmciColors[1].rgbtRed == 0) &&
585
 
        (pbci->bmciColors[1].rgbtGreen == 0) && (pbci->bmciColors[1].rgbtBlue == 0xff),
 
559
    ok((ccolors[0].rgbtRed == 0xff) && (ccolors[0].rgbtGreen == 0) &&
 
560
        (ccolors[0].rgbtBlue == 0) && (ccolors[1].rgbtRed == 0) &&
 
561
        (ccolors[1].rgbtGreen == 0) && (ccolors[1].rgbtBlue == 0xff),
586
562
        "The color table has not been translated to the old BITMAPCOREINFO format\n");
587
563
 
588
564
    DeleteObject(hcoredib);
597
573
       rgb[0].rgbRed, rgb[0].rgbGreen, rgb[0].rgbBlue, rgb[0].rgbReserved,
598
574
       rgb[1].rgbRed, rgb[1].rgbGreen, rgb[1].rgbBlue, rgb[1].rgbReserved);
599
575
 
600
 
    c0 = RGB(pbmi->bmiColors[0].rgbRed, pbmi->bmiColors[0].rgbGreen, pbmi->bmiColors[0].rgbBlue);
601
 
    c1 = RGB(pbmi->bmiColors[1].rgbRed, pbmi->bmiColors[1].rgbGreen, pbmi->bmiColors[1].rgbBlue);
 
576
    c0 = RGB(colors[0].rgbRed, colors[0].rgbGreen, colors[0].rgbBlue);
 
577
    c1 = RGB(colors[1].rgbRed, colors[1].rgbGreen, colors[1].rgbBlue);
602
578
 
603
 
    test_color(hdcmem, DIBINDEX(0), c0, 0, 1);
604
 
    test_color(hdcmem, DIBINDEX(1), c1, 0, 1);
605
 
    test_color(hdcmem, DIBINDEX(2), c0, 1, 1);
606
 
    test_color(hdcmem, PALETTEINDEX(0), c0, 1, 1);
607
 
    test_color(hdcmem, PALETTEINDEX(1), c0, 1, 1);
608
 
    test_color(hdcmem, PALETTEINDEX(2), c0, 1, 1);
609
 
    test_color(hdcmem, PALETTERGB(pbmi->bmiColors[0].rgbRed, pbmi->bmiColors[0].rgbGreen,
610
 
        pbmi->bmiColors[0].rgbBlue), c0, 1, 1);
611
 
    test_color(hdcmem, PALETTERGB(pbmi->bmiColors[1].rgbRed, pbmi->bmiColors[1].rgbGreen,
612
 
        pbmi->bmiColors[1].rgbBlue), c1, 1, 1);
613
 
    test_color(hdcmem, PALETTERGB(0, 0, 0), c0, 1, 1);
614
 
    test_color(hdcmem, PALETTERGB(0xff, 0xff, 0xff), c0, 1, 1);
615
 
    test_color(hdcmem, PALETTERGB(0, 0, 0xfe), c1, 1, 1);
 
579
    test_color(hdcmem, DIBINDEX(0), c0);
 
580
    test_color(hdcmem, DIBINDEX(1), c1);
 
581
    test_color(hdcmem, DIBINDEX(2), c0);
 
582
    test_color(hdcmem, PALETTEINDEX(0), c0);
 
583
    test_color(hdcmem, PALETTEINDEX(1), c0);
 
584
    test_color(hdcmem, PALETTEINDEX(2), c0);
 
585
    test_color(hdcmem, PALETTERGB(colors[0].rgbRed, colors[0].rgbGreen, colors[0].rgbBlue), c0);
 
586
    test_color(hdcmem, PALETTERGB(colors[1].rgbRed, colors[1].rgbGreen, colors[1].rgbBlue), c1);
 
587
    test_color(hdcmem, PALETTERGB(0, 0, 0), c0);
 
588
    test_color(hdcmem, PALETTERGB(0xff, 0xff, 0xff), c0);
 
589
    test_color(hdcmem, PALETTERGB(0, 0, 0xfe), c1);
616
590
 
617
591
    SelectObject(hdcmem, oldbm);
618
592
    DeleteObject(hdib);
619
593
 
620
 
    pbmi->bmiColors[0].rgbRed = 0xff;
621
 
    pbmi->bmiColors[0].rgbGreen = 0xff;
622
 
    pbmi->bmiColors[0].rgbBlue = 0xff;
623
 
    pbmi->bmiColors[1].rgbRed = 0;
624
 
    pbmi->bmiColors[1].rgbGreen = 0;
625
 
    pbmi->bmiColors[1].rgbBlue = 0;
 
594
    colors[0].rgbRed = 0xff;
 
595
    colors[0].rgbGreen = 0xff;
 
596
    colors[0].rgbBlue = 0xff;
 
597
    colors[1].rgbRed = 0;
 
598
    colors[1].rgbGreen = 0;
 
599
    colors[1].rgbBlue = 0;
626
600
 
627
601
    hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
628
602
    ok(hdib != NULL, "CreateDIBSection failed\n");
633
607
 
634
608
    ret = GetDIBColorTable(hdcmem, 0, 2, rgb);
635
609
    ok(ret == 2, "GetDIBColorTable returned %d\n", ret);
636
 
    ok(!memcmp(rgb, pbmi->bmiColors, 2 * sizeof(RGBQUAD)),
 
610
    ok(!memcmp(rgb, colors, 2 * sizeof(RGBQUAD)),
637
611
       "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
638
612
       rgb[0].rgbRed, rgb[0].rgbGreen, rgb[0].rgbBlue, rgb[0].rgbReserved,
639
613
       rgb[1].rgbRed, rgb[1].rgbGreen, rgb[1].rgbBlue, rgb[1].rgbReserved);
644
618
 
645
619
    pbmi->bmiHeader.biBitCount = 4;
646
620
    for (i = 0; i < 16; i++) {
647
 
        pbmi->bmiColors[i].rgbRed = i;
648
 
        pbmi->bmiColors[i].rgbGreen = 16-i;
649
 
        pbmi->bmiColors[i].rgbBlue = 0;
 
621
        colors[i].rgbRed = i;
 
622
        colors[i].rgbGreen = 16-i;
 
623
        colors[i].rgbBlue = 0;
650
624
    }
651
625
    hdib = CreateDIBSection(hdcmem, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
652
626
    ok(hdib != NULL, "CreateDIBSection failed\n");
659
633
    pbmi->bmiHeader.biBitCount = 8;
660
634
 
661
635
    for (i = 0; i < 128; i++) {
662
 
        pbmi->bmiColors[i].rgbRed = 255 - i * 2;
663
 
        pbmi->bmiColors[i].rgbGreen = i * 2;
664
 
        pbmi->bmiColors[i].rgbBlue = 0;
665
 
        pbmi->bmiColors[255 - i].rgbRed = 0;
666
 
        pbmi->bmiColors[255 - i].rgbGreen = i * 2;
667
 
        pbmi->bmiColors[255 - i].rgbBlue = 255 - i * 2;
 
636
        colors[i].rgbRed = 255 - i * 2;
 
637
        colors[i].rgbGreen = i * 2;
 
638
        colors[i].rgbBlue = 0;
 
639
        colors[255 - i].rgbRed = 0;
 
640
        colors[255 - i].rgbGreen = i * 2;
 
641
        colors[255 - i].rgbBlue = 255 - i * 2;
668
642
    }
669
643
    hdib = CreateDIBSection(hdcmem, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
670
644
    ok(hdib != NULL, "CreateDIBSection failed\n");
675
649
    oldbm = SelectObject(hdcmem, hdib);
676
650
 
677
651
    for (i = 0; i < 256; i++) {
678
 
        test_color(hdcmem, DIBINDEX(i), 
679
 
            RGB(pbmi->bmiColors[i].rgbRed, pbmi->bmiColors[i].rgbGreen, pbmi->bmiColors[i].rgbBlue), 0, 0);
680
 
        test_color(hdcmem, PALETTERGB(pbmi->bmiColors[i].rgbRed, pbmi->bmiColors[i].rgbGreen, pbmi->bmiColors[i].rgbBlue), 
681
 
            RGB(pbmi->bmiColors[i].rgbRed, pbmi->bmiColors[i].rgbGreen, pbmi->bmiColors[i].rgbBlue), 0, 0);
 
652
        test_color(hdcmem, DIBINDEX(i), RGB(colors[i].rgbRed, colors[i].rgbGreen, colors[i].rgbBlue));
 
653
        test_color(hdcmem, PALETTERGB(colors[i].rgbRed, colors[i].rgbGreen, colors[i].rgbBlue),
 
654
                   RGB(colors[i].rgbRed, colors[i].rgbGreen, colors[i].rgbBlue));
682
655
    }
683
656
 
684
657
    SelectObject(hdcmem, oldbm);
691
664
    memset(plogpal, 0, sizeof(logpalbuf));
692
665
    plogpal->palVersion = 0x300;
693
666
    plogpal->palNumEntries = 2;
694
 
    plogpal->palPalEntry[0].peRed = 0xff;
695
 
    plogpal->palPalEntry[0].peBlue = 0xff;
696
 
    plogpal->palPalEntry[1].peGreen = 0xff;
 
667
    palent[0].peRed = 0xff;
 
668
    palent[0].peBlue = 0xff;
 
669
    palent[1].peGreen = 0xff;
697
670
 
698
671
    index = (WORD*)pbmi->bmiColors;
699
672
    *index++ = 0;
721
694
       rgb[0].rgbRed, rgb[0].rgbGreen, rgb[0].rgbBlue, rgb[0].rgbReserved,
722
695
       rgb[1].rgbRed, rgb[1].rgbGreen, rgb[1].rgbBlue, rgb[1].rgbReserved);
723
696
 
724
 
    c0 = RGB(plogpal->palPalEntry[0].peRed, plogpal->palPalEntry[0].peGreen, plogpal->palPalEntry[0].peBlue);
725
 
    c1 = RGB(plogpal->palPalEntry[1].peRed, plogpal->palPalEntry[1].peGreen, plogpal->palPalEntry[1].peBlue);
 
697
    c0 = RGB(palent[0].peRed, palent[0].peGreen, palent[0].peBlue);
 
698
    c1 = RGB(palent[1].peRed, palent[1].peGreen, palent[1].peBlue);
726
699
 
727
 
    test_color(hdcmem, DIBINDEX(0), c0, 0, 1);
728
 
    test_color(hdcmem, DIBINDEX(1), c1, 0, 1);
729
 
    test_color(hdcmem, DIBINDEX(2), c0, 1, 1);
730
 
    test_color(hdcmem, PALETTEINDEX(0), c0, 0, 1);
731
 
    test_color(hdcmem, PALETTEINDEX(1), c1, 0, 1);
732
 
    test_color(hdcmem, PALETTEINDEX(2), c0, 1, 1);
733
 
    test_color(hdcmem, PALETTERGB(plogpal->palPalEntry[0].peRed, plogpal->palPalEntry[0].peGreen,
734
 
        plogpal->palPalEntry[0].peBlue), c0, 1, 1);
735
 
    test_color(hdcmem, PALETTERGB(plogpal->palPalEntry[1].peRed, plogpal->palPalEntry[1].peGreen,
736
 
        plogpal->palPalEntry[1].peBlue), c1, 1, 1);
737
 
    test_color(hdcmem, PALETTERGB(0, 0, 0), c1, 1, 1);
738
 
    test_color(hdcmem, PALETTERGB(0xff, 0xff, 0xff), c0, 1, 1);
739
 
    test_color(hdcmem, PALETTERGB(0, 0, 0xfe), c0, 1, 1);
740
 
    test_color(hdcmem, PALETTERGB(0, 1, 0), c1, 1, 1);
741
 
    test_color(hdcmem, PALETTERGB(0x3f, 0, 0x3f), c1, 1, 1);
742
 
    test_color(hdcmem, PALETTERGB(0x40, 0, 0x40), c0, 1, 1);
 
700
    test_color(hdcmem, DIBINDEX(0), c0);
 
701
    test_color(hdcmem, DIBINDEX(1), c1);
 
702
    test_color(hdcmem, DIBINDEX(2), c0);
 
703
    test_color(hdcmem, PALETTEINDEX(0), c0);
 
704
    test_color(hdcmem, PALETTEINDEX(1), c1);
 
705
    test_color(hdcmem, PALETTEINDEX(2), c0);
 
706
    test_color(hdcmem, PALETTERGB(palent[0].peRed, palent[0].peGreen, palent[0].peBlue), c0);
 
707
    test_color(hdcmem, PALETTERGB(palent[1].peRed, palent[1].peGreen, palent[1].peBlue), c1);
 
708
    test_color(hdcmem, PALETTERGB(0, 0, 0), c1);
 
709
    test_color(hdcmem, PALETTERGB(0xff, 0xff, 0xff), c0);
 
710
    test_color(hdcmem, PALETTERGB(0, 0, 0xfe), c0);
 
711
    test_color(hdcmem, PALETTERGB(0, 1, 0), c1);
 
712
    test_color(hdcmem, PALETTERGB(0x3f, 0, 0x3f), c1);
 
713
    test_color(hdcmem, PALETTERGB(0x40, 0, 0x40), c0);
743
714
 
744
715
    /* Bottom and 2nd row from top green, everything else magenta */
745
716
    bits[0] = bits[1] = 0xff;
776
747
    plogpal->palNumEntries = 256;
777
748
 
778
749
    for (i = 0; i < 128; i++) {
779
 
        plogpal->palPalEntry[i].peRed = 255 - i * 2;
780
 
        plogpal->palPalEntry[i].peBlue = i * 2;
781
 
        plogpal->palPalEntry[i].peGreen = 0;
782
 
        plogpal->palPalEntry[255 - i].peRed = 0;
783
 
        plogpal->palPalEntry[255 - i].peGreen = i * 2;
784
 
        plogpal->palPalEntry[255 - i].peBlue = 255 - i * 2;
 
750
        palent[i].peRed = 255 - i * 2;
 
751
        palent[i].peBlue = i * 2;
 
752
        palent[i].peGreen = 0;
 
753
        palent[255 - i].peRed = 0;
 
754
        palent[255 - i].peGreen = i * 2;
 
755
        palent[255 - i].peBlue = 255 - i * 2;
785
756
    }
786
757
 
787
758
    index = (WORD*)pbmi->bmiColors;
806
777
    ret = GetDIBColorTable(hdcmem, 0, 256, rgb);
807
778
    ok(ret == 256, "GetDIBColorTable returned %d\n", ret);
808
779
    for (i = 0; i < 256; i++) {
809
 
        ok(rgb[i].rgbRed == plogpal->palPalEntry[i].peRed && 
810
 
            rgb[i].rgbBlue == plogpal->palPalEntry[i].peBlue && 
811
 
            rgb[i].rgbGreen == plogpal->palPalEntry[i].peGreen, 
 
780
        ok(rgb[i].rgbRed == palent[i].peRed && 
 
781
            rgb[i].rgbBlue == palent[i].peBlue && 
 
782
            rgb[i].rgbGreen == palent[i].peGreen, 
812
783
            "GetDIBColorTable returns table %d: r%02x g%02x b%02x res%02x\n",
813
784
            i, rgb[i].rgbRed, rgb[i].rgbGreen, rgb[i].rgbBlue, rgb[i].rgbReserved);
814
785
    }
815
786
 
816
787
    for (i = 0; i < 256; i++) {
817
 
        test_color(hdcmem, DIBINDEX(i), 
818
 
            RGB(plogpal->palPalEntry[i].peRed, plogpal->palPalEntry[i].peGreen, plogpal->palPalEntry[i].peBlue), 0, 0);
819
 
        test_color(hdcmem, PALETTEINDEX(i), 
820
 
            RGB(plogpal->palPalEntry[i].peRed, plogpal->palPalEntry[i].peGreen, plogpal->palPalEntry[i].peBlue), 0, 0);
821
 
        test_color(hdcmem, PALETTERGB(plogpal->palPalEntry[i].peRed, plogpal->palPalEntry[i].peGreen, plogpal->palPalEntry[i].peBlue), 
822
 
            RGB(plogpal->palPalEntry[i].peRed, plogpal->palPalEntry[i].peGreen, plogpal->palPalEntry[i].peBlue), 0, 0);
 
788
        test_color(hdcmem, DIBINDEX(i), RGB(palent[i].peRed, palent[i].peGreen, palent[i].peBlue));
 
789
        test_color(hdcmem, PALETTEINDEX(i), RGB(palent[i].peRed, palent[i].peGreen, palent[i].peBlue));
 
790
        test_color(hdcmem, PALETTERGB(palent[i].peRed, palent[i].peGreen, palent[i].peBlue), 
 
791
                   RGB(palent[i].peRed, palent[i].peGreen, palent[i].peBlue));
823
792
    }
824
793
 
825
794
    SelectPalette(hdcmem, oldpal, TRUE);
827
796
    DeleteObject(hdib);
828
797
    DeleteObject(hpal);
829
798
 
 
799
    plogpal->palNumEntries = 37;
 
800
    hpal = CreatePalette(plogpal);
 
801
    ok(hpal != NULL, "CreatePalette failed\n");
 
802
    oldpal = SelectPalette(hdc, hpal, TRUE);
 
803
    pbmi->bmiHeader.biClrUsed = 142;
 
804
    hdib = CreateDIBSection(hdc, pbmi, DIB_PAL_COLORS, (void**)&bits, NULL, 0);
 
805
    ok(hdib != NULL, "CreateDIBSection failed\n");
 
806
    ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIB Section\n");
 
807
    ok(dibsec.dsBmih.biClrUsed == 256, "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec.dsBmih.biClrUsed, 256);
 
808
 
 
809
    test_dib_info(hdib, bits, &pbmi->bmiHeader);
 
810
 
 
811
    SelectPalette(hdc, oldpal, TRUE);
 
812
    oldbm = SelectObject(hdcmem, hdib);
 
813
 
 
814
    memset( rgb, 0xcc, sizeof(rgb) );
 
815
    ret = GetDIBColorTable(hdcmem, 0, 256, rgb);
 
816
    ok(ret == 256, "GetDIBColorTable returned %d\n", ret);
 
817
    for (i = 0; i < 256; i++)
 
818
    {
 
819
        if (i < pbmi->bmiHeader.biClrUsed)
 
820
        {
 
821
            ok(rgb[i].rgbRed == palent[i % 37].peRed &&
 
822
               rgb[i].rgbBlue == palent[i % 37].peBlue &&
 
823
               rgb[i].rgbGreen == palent[i % 37].peGreen,
 
824
               "GetDIBColorTable returns table %d: r %02x g %02x b %02x res%02x\n",
 
825
               i, rgb[i].rgbRed, rgb[i].rgbGreen, rgb[i].rgbBlue, rgb[i].rgbReserved);
 
826
            test_color(hdcmem, DIBINDEX(i),
 
827
                       RGB(palent[i % 37].peRed, palent[i % 37].peGreen, palent[i % 37].peBlue));
 
828
        }
 
829
        else
 
830
        {
 
831
            ok(rgb[i].rgbRed == 0 && rgb[i].rgbBlue == 0 && rgb[i].rgbGreen == 0,
 
832
               "GetDIBColorTable returns table %d: r %02x g %02x b %02x res%02x\n",
 
833
               i, rgb[i].rgbRed, rgb[i].rgbGreen, rgb[i].rgbBlue, rgb[i].rgbReserved);
 
834
            test_color(hdcmem, DIBINDEX(i), 0 );
 
835
        }
 
836
    }
 
837
    pbmi->bmiHeader.biClrUsed = 173;
 
838
    memset( pbmi->bmiColors, 0xcc, 256 * sizeof(RGBQUAD) );
 
839
    GetDIBits( hdc, hdib, 0, 1, bits, pbmi, DIB_RGB_COLORS );
 
840
    ok( pbmi->bmiHeader.biClrUsed == 0, "wrong colors %u\n", pbmi->bmiHeader.biClrUsed );
 
841
    for (i = 0; i < 256; i++)
 
842
    {
 
843
        if (i < 142)
 
844
            ok(colors[i].rgbRed == palent[i % 37].peRed &&
 
845
               colors[i].rgbBlue == palent[i % 37].peBlue &&
 
846
               colors[i].rgbGreen == palent[i % 37].peGreen,
 
847
               "GetDIBits returns table %d: r %02x g %02x b %02x res%02x\n",
 
848
               i, colors[i].rgbRed, colors[i].rgbGreen, colors[i].rgbBlue, colors[i].rgbReserved);
 
849
        else
 
850
            ok(colors[i].rgbRed == 0 && colors[i].rgbBlue == 0 && colors[i].rgbGreen == 0,
 
851
               "GetDIBits returns table %d: r %02x g %02x b %02x res%02x\n",
 
852
               i, colors[i].rgbRed, colors[i].rgbGreen, colors[i].rgbBlue, colors[i].rgbReserved);
 
853
    }
 
854
 
 
855
    SelectObject(hdcmem, oldbm);
 
856
    DeleteObject(hdib);
 
857
    DeleteObject(hpal);
 
858
 
 
859
    /* ClrUsed ignored on > 8bpp */
 
860
    pbmi->bmiHeader.biBitCount = 16;
 
861
    pbmi->bmiHeader.biClrUsed = 37;
 
862
    hdib = CreateDIBSection(hdc, pbmi, DIB_PAL_COLORS, (void**)&bits, NULL, 0);
 
863
    ok(hdib != NULL, "CreateDIBSection failed\n");
 
864
    ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIB Section\n");
 
865
    ok(dibsec.dsBmih.biClrUsed == 0, "created DIBSection: wrong biClrUsed field: %u\n", dibsec.dsBmih.biClrUsed);
 
866
    oldbm = SelectObject(hdcmem, hdib);
 
867
    ret = GetDIBColorTable(hdcmem, 0, 256, rgb);
 
868
    ok(ret == 0, "GetDIBColorTable returned %d\n", ret);
 
869
    SelectObject(hdcmem, oldbm);
 
870
    DeleteObject(hdib);
 
871
 
830
872
    DeleteDC(hdcmem);
831
873
    DeleteDC(hdcmem2);
832
874
    ReleaseDC(0, hdc);
834
876
 
835
877
static void test_dib_formats(void)
836
878
{
837
 
    char buffer[FIELD_OFFSET( BITMAPINFO, bmiColors[256])];
838
 
    BITMAPINFO *bi = (BITMAPINFO *)buffer;
 
879
    BITMAPINFO *bi;
839
880
    char data[256];
840
881
    void *bits;
841
 
    int planes, bpp, compr;
 
882
    int planes, bpp, compr, format;
842
883
    HBITMAP hdib, hbmp;
843
884
    HDC hdc, memdc;
844
885
    UINT ret;
845
 
    BOOL expect_ok, todo;
 
886
    BOOL format_ok, expect_ok;
846
887
 
 
888
    bi = HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO, bmiColors[256] ) );
847
889
    hdc = GetDC( 0 );
848
890
    memdc = CreateCompatibleDC( 0 );
849
891
    hbmp = CreateCompatibleBitmap( hdc, 10, 10 );
856
898
        {
857
899
            for (compr = 0; compr < 8; compr++)
858
900
            {
859
 
                switch (bpp)
860
 
                {
861
 
                case 1:
862
 
                case 4:
863
 
                case 8:
864
 
                case 24: expect_ok = (compr == BI_RGB); break;
865
 
                case 16:
866
 
                case 32: expect_ok = (compr == BI_RGB || compr == BI_BITFIELDS); break;
867
 
                default: expect_ok = FALSE; break;
868
 
                }
869
 
                todo = (compr == BI_BITFIELDS);  /* wine doesn't like strange bitfields */
870
 
 
871
 
                memset( bi, 0, sizeof(bi->bmiHeader) );
872
 
                bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
873
 
                bi->bmiHeader.biWidth = 2;
874
 
                bi->bmiHeader.biHeight = 2;
875
 
                bi->bmiHeader.biPlanes = planes;
876
 
                bi->bmiHeader.biBitCount = bpp;
877
 
                bi->bmiHeader.biCompression = compr;
878
 
                bi->bmiHeader.biSizeImage = 0;
879
 
                memset( bi->bmiColors, 0xaa, sizeof(RGBQUAD) * 256 );
880
 
                ret = GetDIBits(hdc, hbmp, 0, 0, data, bi, DIB_RGB_COLORS);
881
 
                if (expect_ok || (!bpp && compr != BI_JPEG && compr != BI_PNG) ||
882
 
                    (bpp == 4 && compr == BI_RLE4) || (bpp == 8 && compr == BI_RLE8))
883
 
                    ok( ret, "GetDIBits failed for %u/%u/%u\n", bpp, planes, compr );
884
 
                else
885
 
                    ok( !ret || broken(!bpp && (compr == BI_JPEG || compr == BI_PNG)), /* nt4 */
886
 
                        "GetDIBits succeeded for %u/%u/%u\n", bpp, planes, compr );
887
 
 
888
 
                /* all functions check planes except GetDIBits with 0 lines */
889
 
                if (!planes) expect_ok = FALSE;
890
 
                memset( bi, 0, sizeof(bi->bmiHeader) );
891
 
                bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
892
 
                bi->bmiHeader.biWidth = 2;
893
 
                bi->bmiHeader.biHeight = 2;
894
 
                bi->bmiHeader.biPlanes = planes;
895
 
                bi->bmiHeader.biBitCount = bpp;
896
 
                bi->bmiHeader.biCompression = compr;
897
 
                bi->bmiHeader.biSizeImage = 0;
898
 
                memset( bi->bmiColors, 0xaa, sizeof(RGBQUAD) * 256 );
899
 
 
900
 
                hdib = CreateDIBSection(hdc, bi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
901
 
                if (expect_ok && (planes == 1 || planes * bpp <= 16))
902
 
                    ok( hdib != NULL, "CreateDIBSection failed for %u/%u/%u\n", bpp, planes, compr );
903
 
                else
904
 
                    ok( hdib == NULL, "CreateDIBSection succeeded for %u/%u/%u\n", bpp, planes, compr );
905
 
                if (hdib) DeleteObject( hdib );
906
 
 
907
 
                hdib = CreateDIBitmap( hdc, &bi->bmiHeader, 0, data, bi, DIB_RGB_COLORS );
908
 
                /* no sanity checks in CreateDIBitmap except compression */
909
 
                if (compr == BI_JPEG || compr == BI_PNG)
910
 
                    ok( hdib == NULL || broken(hdib != NULL), /* nt4 */
911
 
                        "CreateDIBitmap succeeded for %u/%u/%u\n", bpp, planes, compr );
912
 
                else
913
 
                    ok( hdib != NULL, "CreateDIBitmap failed for %u/%u/%u\n", bpp, planes, compr );
914
 
                if (hdib) DeleteObject( hdib );
915
 
 
916
 
                /* RLE needs a size */
917
 
                bi->bmiHeader.biSizeImage = 0;
918
 
                ret = SetDIBits(hdc, hbmp, 0, 1, data, bi, DIB_RGB_COLORS);
919
 
                if (expect_ok)
920
 
                {
921
 
                    if (todo)
922
 
                        todo_wine ok( ret, "SetDIBits failed for %u/%u/%u\n", bpp, planes, compr );
923
 
                    else
924
 
                        ok( ret, "SetDIBits failed for %u/%u/%u\n", bpp, planes, compr );
925
 
                }
926
 
                else
927
 
                    ok( !ret ||
928
 
                        broken((bpp == 4 && compr == BI_RLE4) || (bpp == 8 && compr == BI_RLE8)), /* nt4 */
929
 
                        "SetDIBits succeeded for %u/%u/%u\n", bpp, planes, compr );
930
 
                ret = SetDIBitsToDevice( memdc, 0, 0, 1, 1, 0, 0, 0, 1, data, bi, DIB_RGB_COLORS );
931
 
                if (expect_ok)
932
 
                {
933
 
                    if (todo)
934
 
                        todo_wine ok( ret, "SetDIBitsToDevice failed for %u/%u/%u\n", bpp, planes, compr );
935
 
                    else
936
 
                        ok( ret, "SetDIBitsToDevice failed for %u/%u/%u\n", bpp, planes, compr );
937
 
                }
938
 
                else
939
 
                    ok( !ret ||
940
 
                        broken((bpp == 4 && compr == BI_RLE4) || (bpp == 8 && compr == BI_RLE8)), /* nt4 */
941
 
                        "SetDIBitsToDevice succeeded for %u/%u/%u\n", bpp, planes, compr );
942
 
                ret = StretchDIBits( memdc, 0, 0, 1, 1, 0, 0, 1, 1, data, bi, DIB_RGB_COLORS, SRCCOPY );
943
 
                if (expect_ok)
944
 
                {
945
 
                    if (todo)
946
 
                        todo_wine ok( ret, "StretchDIBits failed for %u/%u/%u\n", bpp, planes, compr );
947
 
                    else
948
 
                        ok( ret, "StretchDIBits failed for %u/%u/%u\n", bpp, planes, compr );
949
 
                }
950
 
                else
951
 
                    ok( !ret ||
952
 
                        broken((bpp == 4 && compr == BI_RLE4) || (bpp == 8 && compr == BI_RLE8)), /* nt4 */
953
 
                        "StretchDIBits succeeded for %u/%u/%u\n", bpp, planes, compr );
954
 
 
955
 
                ret = GetDIBits(hdc, hbmp, 0, 2, data, bi, DIB_RGB_COLORS);
956
 
                if (expect_ok)
957
 
                    ok( ret, "GetDIBits failed for %u/%u/%u\n", bpp, planes, compr );
958
 
                else
959
 
                    ok( !ret, "GetDIBits succeeded for %u/%u/%u\n", bpp, planes, compr );
960
 
                ok( bi->bmiHeader.biBitCount == bpp, "GetDIBits modified bpp %u/%u\n",
961
 
                    bpp, bi->bmiHeader.biBitCount );
962
 
 
963
 
                bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
964
 
                bi->bmiHeader.biWidth = 2;
965
 
                bi->bmiHeader.biHeight = 2;
966
 
                bi->bmiHeader.biPlanes = planes;
967
 
                bi->bmiHeader.biBitCount = bpp;
968
 
                bi->bmiHeader.biCompression = compr;
969
 
                bi->bmiHeader.biSizeImage = 1;
970
 
                memset( bi->bmiColors, 0xaa, sizeof(RGBQUAD) * 256 );
971
 
                /* RLE allowed with valid biSizeImage */
972
 
                if ((bpp == 4 && compr == BI_RLE4) || (bpp == 8 && compr == BI_RLE8)) expect_ok = TRUE;
973
 
 
974
 
                ret = SetDIBits(hdc, hbmp, 0, 1, data, bi, DIB_RGB_COLORS);
975
 
                if (expect_ok)
976
 
                {
977
 
                    if (todo)
978
 
                        todo_wine ok( ret, "SetDIBits failed for %u/%u/%u\n", bpp, planes, compr );
979
 
                    else
980
 
                        ok( ret, "SetDIBits failed for %u/%u/%u\n", bpp, planes, compr );
981
 
                }
982
 
                else
983
 
                    ok( !ret, "SetDIBits succeeded for %u/%u/%u\n", bpp, planes, compr );
984
 
                ret = SetDIBitsToDevice( memdc, 0, 0, 1, 1, 0, 0, 0, 1, data, bi, DIB_RGB_COLORS );
985
 
                if (expect_ok)
986
 
                {
987
 
                    if (todo)
988
 
                        todo_wine ok( ret, "SetDIBitsToDevice failed for %u/%u/%u\n", bpp, planes, compr );
989
 
                    else
990
 
                        ok( ret, "SetDIBitsToDevice failed for %u/%u/%u\n", bpp, planes, compr );
991
 
                }
992
 
                else
993
 
                    ok( !ret, "SetDIBitsToDevice succeeded for %u/%u/%u\n", bpp, planes, compr );
994
 
                ret = StretchDIBits( memdc, 0, 0, 1, 1, 0, 0, 1, 1, data, bi, DIB_RGB_COLORS, SRCCOPY );
995
 
                if (expect_ok)
996
 
                {
997
 
                    if (todo)
998
 
                        todo_wine ok( ret, "StretchDIBits failed for %u/%u/%u\n", bpp, planes, compr );
999
 
                    else
1000
 
                        ok( ret, "StretchDIBits failed for %u/%u/%u\n", bpp, planes, compr );
1001
 
                }
1002
 
                else
1003
 
                    ok( !ret, "StretchDIBits succeeded for %u/%u/%u\n", bpp, planes, compr );
1004
 
 
1005
 
                bi->bmiHeader.biSizeImage = 0;
1006
 
                ret = GetDIBits(hdc, hbmp, 0, 2, NULL, bi, DIB_RGB_COLORS);
1007
 
                if (expect_ok || !bpp)
1008
 
                    ok( ret, "GetDIBits failed for %u/%u/%u\n", bpp, planes, compr );
1009
 
                else
1010
 
                    ok( !ret, "GetDIBits succeeded for %u/%u/%u\n", bpp, planes, compr );
 
901
                for (format = DIB_RGB_COLORS; format <= DIB_PAL_COLORS; format++)
 
902
                {
 
903
                    switch (bpp)
 
904
                    {
 
905
                    case 1:
 
906
                    case 4:
 
907
                    case 8:
 
908
                    case 24: expect_ok = (compr == BI_RGB); break;
 
909
                    case 16:
 
910
                    case 32: expect_ok = (compr == BI_RGB || compr == BI_BITFIELDS); break;
 
911
                    default: expect_ok = FALSE; break;
 
912
                    }
 
913
 
 
914
                    memset( bi, 0, sizeof(bi->bmiHeader) );
 
915
                    bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
 
916
                    bi->bmiHeader.biWidth = 2;
 
917
                    bi->bmiHeader.biHeight = 2;
 
918
                    bi->bmiHeader.biPlanes = planes;
 
919
                    bi->bmiHeader.biBitCount = bpp;
 
920
                    bi->bmiHeader.biCompression = compr;
 
921
                    bi->bmiHeader.biSizeImage = 0;
 
922
                    memset( bi->bmiColors, 0xaa, sizeof(RGBQUAD) * 256 );
 
923
                    ret = GetDIBits(hdc, hbmp, 0, 0, data, bi, format);
 
924
                    if (expect_ok || (!bpp && compr != BI_JPEG && compr != BI_PNG) ||
 
925
                        (bpp == 4 && compr == BI_RLE4) || (bpp == 8 && compr == BI_RLE8))
 
926
                        ok( ret, "GetDIBits failed for %u/%u/%u/%u\n", bpp, planes, compr, format );
 
927
                    else
 
928
                        ok( !ret || broken(!bpp && (compr == BI_JPEG || compr == BI_PNG)), /* nt4 */
 
929
                            "GetDIBits succeeded for %u/%u/%u/%u\n", bpp, planes, compr, format );
 
930
 
 
931
                    /* all functions check planes except GetDIBits with 0 lines */
 
932
                    format_ok = expect_ok;
 
933
                    if (!planes) expect_ok = FALSE;
 
934
                    memset( bi, 0, sizeof(bi->bmiHeader) );
 
935
                    bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
 
936
                    bi->bmiHeader.biWidth = 2;
 
937
                    bi->bmiHeader.biHeight = 2;
 
938
                    bi->bmiHeader.biPlanes = planes;
 
939
                    bi->bmiHeader.biBitCount = bpp;
 
940
                    bi->bmiHeader.biCompression = compr;
 
941
                    bi->bmiHeader.biSizeImage = 0;
 
942
                    memset( bi->bmiColors, 0xaa, sizeof(RGBQUAD) * 256 );
 
943
 
 
944
                    hdib = CreateDIBSection(hdc, bi, format, &bits, NULL, 0);
 
945
                    if (expect_ok && (planes == 1 || planes * bpp <= 16) &&
 
946
                        (compr != BI_BITFIELDS || format != DIB_PAL_COLORS))
 
947
                        ok( hdib != NULL, "CreateDIBSection failed for %u/%u/%u/%u\n", bpp, planes, compr, format );
 
948
                    else
 
949
                        ok( hdib == NULL, "CreateDIBSection succeeded for %u/%u/%u/%u\n", bpp, planes, compr, format );
 
950
                    if (hdib) DeleteObject( hdib );
 
951
 
 
952
                    hdib = CreateDIBitmap( hdc, &bi->bmiHeader, 0, data, bi, format );
 
953
                    /* no sanity checks in CreateDIBitmap except compression */
 
954
                    if (compr == BI_JPEG || compr == BI_PNG)
 
955
                        ok( hdib == NULL || broken(hdib != NULL), /* nt4 */
 
956
                            "CreateDIBitmap succeeded for %u/%u/%u/%u\n", bpp, planes, compr, format );
 
957
                    else
 
958
                        ok( hdib != NULL, "CreateDIBitmap failed for %u/%u/%u/%u\n", bpp, planes, compr, format );
 
959
                    if (hdib) DeleteObject( hdib );
 
960
 
 
961
                    /* RLE needs a size */
 
962
                    bi->bmiHeader.biSizeImage = 0;
 
963
                    ret = SetDIBits(hdc, hbmp, 0, 1, data, bi, format);
 
964
                    if (expect_ok)
 
965
                        ok( ret, "SetDIBits failed for %u/%u/%u/%u\n", bpp, planes, compr, format );
 
966
                    else
 
967
                        ok( !ret ||
 
968
                            broken((bpp == 4 && compr == BI_RLE4) || (bpp == 8 && compr == BI_RLE8)), /* nt4 */
 
969
                            "SetDIBits succeeded for %u/%u/%u/%u\n", bpp, planes, compr, format );
 
970
                    ret = SetDIBitsToDevice( memdc, 0, 0, 1, 1, 0, 0, 0, 1, data, bi, format );
 
971
                    if (expect_ok)
 
972
                        ok( ret, "SetDIBitsToDevice failed for %u/%u/%u/%u\n", bpp, planes, compr, format );
 
973
                    else
 
974
                        ok( !ret ||
 
975
                            broken((bpp == 4 && compr == BI_RLE4) || (bpp == 8 && compr == BI_RLE8)), /* nt4 */
 
976
                            "SetDIBitsToDevice succeeded for %u/%u/%u/%u\n", bpp, planes, compr, format );
 
977
                    ret = StretchDIBits( memdc, 0, 0, 1, 1, 0, 0, 1, 1, data, bi, format, SRCCOPY );
 
978
                    if (expect_ok)
 
979
                        ok( ret, "StretchDIBits failed for %u/%u/%u/%u\n", bpp, planes, compr, format );
 
980
                    else
 
981
                        ok( !ret ||
 
982
                            broken((bpp == 4 && compr == BI_RLE4) || (bpp == 8 && compr == BI_RLE8)), /* nt4 */
 
983
                            "StretchDIBits succeeded for %u/%u/%u/%u\n", bpp, planes, compr, format );
 
984
 
 
985
                    ret = GetDIBits(hdc, hbmp, 0, 2, data, bi, format);
 
986
                    if (expect_ok)
 
987
                        ok( ret, "GetDIBits failed for %u/%u/%u/%u\n", bpp, planes, compr, format );
 
988
                    else
 
989
                        ok( !ret, "GetDIBits succeeded for %u/%u/%u/%u\n", bpp, planes, compr, format );
 
990
                    ok( bi->bmiHeader.biBitCount == bpp, "GetDIBits modified bpp %u/%u\n",
 
991
                        bpp, bi->bmiHeader.biBitCount );
 
992
 
 
993
                    bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
 
994
                    bi->bmiHeader.biWidth = 2;
 
995
                    bi->bmiHeader.biHeight = 2;
 
996
                    bi->bmiHeader.biPlanes = planes;
 
997
                    bi->bmiHeader.biBitCount = bpp;
 
998
                    bi->bmiHeader.biCompression = compr;
 
999
                    bi->bmiHeader.biSizeImage = 1;
 
1000
                    memset( bi->bmiColors, 0xaa, sizeof(RGBQUAD) * 256 );
 
1001
                    /* RLE allowed with valid biSizeImage */
 
1002
                    if ((bpp == 4 && compr == BI_RLE4) || (bpp == 8 && compr == BI_RLE8)) expect_ok = TRUE;
 
1003
 
 
1004
                    ret = SetDIBits(hdc, hbmp, 0, 1, data, bi, format);
 
1005
                    if (expect_ok)
 
1006
                        ok( ret, "SetDIBits failed for %u/%u/%u/%u\n", bpp, planes, compr, format );
 
1007
                    else
 
1008
                        ok( !ret, "SetDIBits succeeded for %u/%u/%u/%u\n", bpp, planes, compr, format );
 
1009
                    ret = SetDIBitsToDevice( memdc, 0, 0, 1, 1, 0, 0, 0, 1, data, bi, format );
 
1010
                    if (expect_ok)
 
1011
                        ok( ret, "SetDIBitsToDevice failed for %u/%u/%u/%u\n", bpp, planes, compr, format );
 
1012
                    else
 
1013
                        ok( !ret, "SetDIBitsToDevice succeeded for %u/%u/%u/%u\n", bpp, planes, compr, format );
 
1014
                    ret = StretchDIBits( memdc, 0, 0, 1, 1, 0, 0, 1, 1, data, bi, format, SRCCOPY );
 
1015
                    if (expect_ok)
 
1016
                        ok( ret, "StretchDIBits failed for %u/%u/%u/%u\n", bpp, planes, compr, format );
 
1017
                    else
 
1018
                        ok( !ret, "StretchDIBits succeeded for %u/%u/%u/%u\n", bpp, planes, compr, format );
 
1019
 
 
1020
                    bi->bmiHeader.biSizeImage = 0;
 
1021
                    ret = GetDIBits(hdc, hbmp, 0, 2, NULL, bi, format);
 
1022
                    if (expect_ok || !bpp)
 
1023
                        ok( ret, "GetDIBits failed for %u/%u/%u/%u\n", bpp, planes, compr, format );
 
1024
                    else
 
1025
                        ok( !ret || broken(format_ok && !planes),  /* nt4 */
 
1026
                            "GetDIBits succeeded for %u/%u/%u/%u\n", bpp, planes, compr, format );
 
1027
                }
1011
1028
            }
1012
1029
        }
1013
1030
    }
1024
1041
    *(DWORD *)&bi->bmiColors[1] = 0;
1025
1042
    *(DWORD *)&bi->bmiColors[2] = 0;
1026
1043
 
1027
 
    hdib = CreateDIBSection(hdc, bi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
 
1044
    hdib = CreateDIBSection(hdc, bi, DIB_RGB_COLORS, &bits, NULL, 0);
1028
1045
    ok( hdib == NULL, "CreateDIBSection succeeded with null bitfields\n" );
1029
1046
    ret = SetDIBits(hdc, hbmp, 0, 1, data, bi, DIB_RGB_COLORS);
1030
1047
    ok( !ret, "SetDIBits succeeded with null bitfields\n" );
1033
1050
    ok( hdib != NULL, "CreateDIBitmap failed with null bitfields\n" );
1034
1051
    DeleteObject( hdib );
1035
1052
    ret = SetDIBitsToDevice( memdc, 0, 0, 1, 1, 0, 0, 0, 1, data, bi, DIB_RGB_COLORS );
1036
 
    todo_wine ok( ret, "SetDIBitsToDevice failed with null bitfields\n" );
 
1053
    ok( ret, "SetDIBitsToDevice failed with null bitfields\n" );
1037
1054
    ret = StretchDIBits( memdc, 0, 0, 1, 1, 0, 0, 1, 1, data, bi, DIB_RGB_COLORS, SRCCOPY );
1038
 
    todo_wine ok( ret, "StretchDIBits failed with null bitfields\n" );
 
1055
    ok( ret, "StretchDIBits failed with null bitfields\n" );
1039
1056
    ret = GetDIBits(hdc, hbmp, 0, 2, data, bi, DIB_RGB_COLORS);
1040
1057
    ok( ret, "GetDIBits failed with null bitfields\n" );
1041
1058
    bi->bmiHeader.biPlanes = 1;
1052
1069
    *(DWORD *)&bi->bmiColors[0] = 3;
1053
1070
    *(DWORD *)&bi->bmiColors[1] = 0;
1054
1071
    *(DWORD *)&bi->bmiColors[2] = 7;
1055
 
    hdib = CreateDIBSection(hdc, bi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
 
1072
    hdib = CreateDIBSection(hdc, bi, DIB_RGB_COLORS, &bits, NULL, 0);
1056
1073
    ok( hdib == NULL, "CreateDIBSection succeeded with null bitfields\n" );
1057
1074
    ret = SetDIBits(hdc, hbmp, 0, 1, data, bi, DIB_RGB_COLORS);
1058
1075
    ok( !ret, "SetDIBits succeeded with null bitfields\n" );
1061
1078
    *(DWORD *)&bi->bmiColors[0] = 0x55;
1062
1079
    *(DWORD *)&bi->bmiColors[1] = 0x44;
1063
1080
    *(DWORD *)&bi->bmiColors[2] = 0x33;
1064
 
    hdib = CreateDIBSection(hdc, bi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
 
1081
    hdib = CreateDIBSection(hdc, bi, DIB_RGB_COLORS, &bits, NULL, 0);
1065
1082
    ok( hdib != NULL, "CreateDIBSection failed with bad bitfields\n" );
1066
1083
    if (hdib) DeleteObject( hdib );
1067
1084
    ret = SetDIBits(hdc, hbmp, 0, 1, data, bi, DIB_RGB_COLORS);
1068
 
    todo_wine ok( ret, "SetDIBits failed with bad bitfields\n" );
 
1085
    ok( ret, "SetDIBits failed with bad bitfields\n" );
1069
1086
 
1070
1087
    bi->bmiHeader.biWidth = -2;
1071
1088
    bi->bmiHeader.biHeight = 2;
1072
1089
    bi->bmiHeader.biBitCount = 32;
1073
1090
    bi->bmiHeader.biCompression = BI_RGB;
1074
 
    hdib = CreateDIBSection(hdc, bi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
 
1091
    hdib = CreateDIBSection(hdc, bi, DIB_RGB_COLORS, &bits, NULL, 0);
1075
1092
    ok( hdib == NULL, "CreateDIBSection succeeded with negative width\n" );
1076
1093
    hdib = CreateDIBitmap( hdc, &bi->bmiHeader, 0, bits, bi, DIB_RGB_COLORS );
1077
1094
    ok( hdib == NULL, "CreateDIBitmap succeeded with negative width\n" );
1094
1111
    bi->bmiHeader.biHeight = 2;
1095
1112
    bi->bmiHeader.biBitCount = 32;
1096
1113
    bi->bmiHeader.biCompression = BI_RGB;
1097
 
    hdib = CreateDIBSection(hdc, bi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
 
1114
    hdib = CreateDIBSection(hdc, bi, DIB_RGB_COLORS, &bits, NULL, 0);
1098
1115
    ok( hdib == NULL, "CreateDIBSection succeeded with zero width\n" );
1099
1116
    hdib = CreateDIBitmap( hdc, &bi->bmiHeader, 0, bits, bi, DIB_RGB_COLORS );
1100
1117
    ok( hdib != NULL, "CreateDIBitmap failed with zero width\n" );
1118
1135
    bi->bmiHeader.biHeight = 0;
1119
1136
    bi->bmiHeader.biBitCount = 32;
1120
1137
    bi->bmiHeader.biCompression = BI_RGB;
1121
 
    hdib = CreateDIBSection(hdc, bi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
 
1138
    hdib = CreateDIBSection(hdc, bi, DIB_RGB_COLORS, &bits, NULL, 0);
1122
1139
    ok( hdib == NULL, "CreateDIBSection succeeded with zero height\n" );
1123
1140
    hdib = CreateDIBitmap( hdc, &bi->bmiHeader, 0, bits, bi, DIB_RGB_COLORS );
1124
1141
    ok( hdib != NULL, "CreateDIBitmap failed with zero height\n" );
1138
1155
    ret = GetDIBits(hdc, hbmp, 0, 2, NULL, bi, DIB_RGB_COLORS);
1139
1156
    ok( !ret || broken(ret), /* nt4 */ "GetDIBits succeeded with zero height\n" );
1140
1157
 
 
1158
    /* some functions accept DIB_PAL_COLORS+1, but not beyond */
 
1159
 
 
1160
    bi->bmiHeader.biWidth = 2;
 
1161
    bi->bmiHeader.biHeight = 2;
 
1162
    bi->bmiHeader.biBitCount = 1;
 
1163
    bi->bmiHeader.biCompression = BI_RGB;
 
1164
    hdib = CreateDIBSection(hdc, bi, DIB_PAL_COLORS+1, &bits, NULL, 0);
 
1165
    ok( hdib == NULL, "CreateDIBSection succeeded with DIB_PAL_COLORS+1\n" );
 
1166
    hdib = CreateDIBitmap( hdc, &bi->bmiHeader, 0, bits, bi, DIB_PAL_COLORS+1 );
 
1167
    ok( hdib != NULL, "CreateDIBitmap failed with DIB_PAL_COLORS+1\n" );
 
1168
    DeleteObject( hdib );
 
1169
    ret = SetDIBits(hdc, hbmp, 0, 1, data, bi, DIB_PAL_COLORS+1);
 
1170
    ok( !ret, "SetDIBits succeeded with DIB_PAL_COLORS+1\n" );
 
1171
    ret = SetDIBitsToDevice( memdc, 0, 0, 1, 1, 0, 0, 0, 1, data, bi, DIB_PAL_COLORS+1 );
 
1172
    ok( ret, "SetDIBitsToDevice failed with DIB_PAL_COLORS+1\n" );
 
1173
    ret = StretchDIBits( memdc, 0, 0, 1, 1, 0, 0, 1, 1, data, bi, DIB_PAL_COLORS+1, SRCCOPY );
 
1174
    ok( ret, "StretchDIBits failed with DIB_PAL_COLORS+1\n" );
 
1175
    ret = GetDIBits(hdc, hbmp, 0, 2, data, bi, DIB_PAL_COLORS+1);
 
1176
    ok( !ret, "GetDIBits succeeded with DIB_PAL_COLORS+1\n" );
 
1177
    bi->bmiHeader.biWidth = 2;
 
1178
    bi->bmiHeader.biHeight = 2;
 
1179
    bi->bmiHeader.biBitCount = 1;
 
1180
    bi->bmiHeader.biCompression = BI_RGB;
 
1181
    ret = GetDIBits(hdc, hbmp, 0, 0, NULL, bi, DIB_PAL_COLORS+1);
 
1182
    ok( !ret, "GetDIBits succeeded with DIB_PAL_COLORS+1\n" );
 
1183
 
 
1184
    bi->bmiHeader.biWidth = 2;
 
1185
    bi->bmiHeader.biHeight = 2;
 
1186
    bi->bmiHeader.biBitCount = 1;
 
1187
    bi->bmiHeader.biCompression = BI_RGB;
 
1188
    hdib = CreateDIBSection(hdc, bi, DIB_PAL_COLORS+2, &bits, NULL, 0);
 
1189
    ok( hdib == NULL, "CreateDIBSection succeeded with DIB_PAL_COLORS+2\n" );
 
1190
    hdib = CreateDIBitmap( hdc, &bi->bmiHeader, 0, bits, bi, DIB_PAL_COLORS+2 );
 
1191
    ok( hdib == NULL, "CreateDIBitmap succeeded with DIB_PAL_COLORS+2\n" );
 
1192
    DeleteObject( hdib );
 
1193
    ret = SetDIBits(hdc, hbmp, 0, 1, data, bi, DIB_PAL_COLORS+2);
 
1194
    ok( !ret, "SetDIBits succeeded with DIB_PAL_COLORS+2\n" );
 
1195
    ret = SetDIBitsToDevice( memdc, 0, 0, 1, 1, 0, 0, 0, 1, data, bi, DIB_PAL_COLORS+2 );
 
1196
    ok( !ret, "SetDIBitsToDevice succeeded with DIB_PAL_COLORS+2\n" );
 
1197
    ret = StretchDIBits( memdc, 0, 0, 1, 1, 0, 0, 1, 1, data, bi, DIB_PAL_COLORS+2, SRCCOPY );
 
1198
    ok( !ret, "StretchDIBits succeeded with DIB_PAL_COLORS+2\n" );
 
1199
    ret = GetDIBits(hdc, hbmp, 0, 2, data, bi, DIB_PAL_COLORS+2);
 
1200
    ok( !ret, "GetDIBits succeeded with DIB_PAL_COLORS+2\n" );
 
1201
    bi->bmiHeader.biWidth = 2;
 
1202
    bi->bmiHeader.biHeight = 2;
 
1203
    bi->bmiHeader.biBitCount = 1;
 
1204
    bi->bmiHeader.biCompression = BI_RGB;
 
1205
    ret = GetDIBits(hdc, hbmp, 0, 0, NULL, bi, DIB_PAL_COLORS+2);
 
1206
    ok( !ret, "GetDIBits succeeded with DIB_PAL_COLORS+2\n" );
 
1207
 
1141
1208
    DeleteDC( memdc );
1142
1209
    DeleteObject( hbmp );
1143
1210
    ReleaseDC( 0, hdc );
 
1211
    HeapFree( GetProcessHeap(), 0, bi );
1144
1212
}
1145
1213
 
1146
1214
static void test_mono_dibsection(void)
1149
1217
    HBITMAP old_bm, mono_ds;
1150
1218
    char bmibuf[sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD)];
1151
1219
    BITMAPINFO *pbmi = (BITMAPINFO *)bmibuf;
 
1220
    RGBQUAD *colors = pbmi->bmiColors;
1152
1221
    BYTE bits[10 * 4];
1153
1222
    BYTE *ds_bits;
1154
1223
    int num;
1164
1233
    pbmi->bmiHeader.biBitCount = 1;
1165
1234
    pbmi->bmiHeader.biPlanes = 1;
1166
1235
    pbmi->bmiHeader.biCompression = BI_RGB;
1167
 
    pbmi->bmiColors[0].rgbRed = 0xff;
1168
 
    pbmi->bmiColors[0].rgbGreen = 0xff;
1169
 
    pbmi->bmiColors[0].rgbBlue = 0xff;
1170
 
    pbmi->bmiColors[1].rgbRed = 0x0;
1171
 
    pbmi->bmiColors[1].rgbGreen = 0x0;
1172
 
    pbmi->bmiColors[1].rgbBlue = 0x0;
 
1236
    colors[0].rgbRed = 0xff;
 
1237
    colors[0].rgbGreen = 0xff;
 
1238
    colors[0].rgbBlue = 0xff;
 
1239
    colors[1].rgbRed = 0x0;
 
1240
    colors[1].rgbGreen = 0x0;
 
1241
    colors[1].rgbBlue = 0x0;
1173
1242
 
1174
1243
    /*
1175
1244
     * First dib section is 'inverted' ie color[0] is white, color[1] is black
1194
1263
 
1195
1264
    /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
1196
1265
 
1197
 
    pbmi->bmiColors[0].rgbRed = 0x0;
1198
 
    pbmi->bmiColors[0].rgbGreen = 0x0;
1199
 
    pbmi->bmiColors[0].rgbBlue = 0x0;
1200
 
    pbmi->bmiColors[1].rgbRed = 0xff;
1201
 
    pbmi->bmiColors[1].rgbGreen = 0xff;
1202
 
    pbmi->bmiColors[1].rgbBlue = 0xff;
 
1266
    colors[0].rgbRed = 0x0;
 
1267
    colors[0].rgbGreen = 0x0;
 
1268
    colors[0].rgbBlue = 0x0;
 
1269
    colors[1].rgbRed = 0xff;
 
1270
    colors[1].rgbGreen = 0xff;
 
1271
    colors[1].rgbBlue = 0xff;
1203
1272
 
1204
1273
    SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
1205
1274
    ok(ds_bits[0] == 0x55, "out_bits %02x\n", ds_bits[0]);
1211
1280
     * Next dib section is 'normal' ie color[0] is black, color[1] is white
1212
1281
     */
1213
1282
 
1214
 
    pbmi->bmiColors[0].rgbRed = 0x0;
1215
 
    pbmi->bmiColors[0].rgbGreen = 0x0;
1216
 
    pbmi->bmiColors[0].rgbBlue = 0x0;
1217
 
    pbmi->bmiColors[1].rgbRed = 0xff;
1218
 
    pbmi->bmiColors[1].rgbGreen = 0xff;
1219
 
    pbmi->bmiColors[1].rgbBlue = 0xff;
 
1283
    colors[0].rgbRed = 0x0;
 
1284
    colors[0].rgbGreen = 0x0;
 
1285
    colors[0].rgbBlue = 0x0;
 
1286
    colors[1].rgbRed = 0xff;
 
1287
    colors[1].rgbGreen = 0xff;
 
1288
    colors[1].rgbBlue = 0xff;
1220
1289
 
1221
1290
    mono_ds = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&ds_bits, NULL, 0);
1222
1291
    ok(mono_ds != NULL, "CreateDIBSection rets NULL\n");
1234
1303
 
1235
1304
    /* SetDIBitsToDevice with a inverted bmi -> normal dib section */
1236
1305
 
1237
 
    pbmi->bmiColors[0].rgbRed = 0xff;
1238
 
    pbmi->bmiColors[0].rgbGreen = 0xff;
1239
 
    pbmi->bmiColors[0].rgbBlue = 0xff;
1240
 
    pbmi->bmiColors[1].rgbRed = 0x0;
1241
 
    pbmi->bmiColors[1].rgbGreen = 0x0;
1242
 
    pbmi->bmiColors[1].rgbBlue = 0x0;
 
1306
    colors[0].rgbRed = 0xff;
 
1307
    colors[0].rgbGreen = 0xff;
 
1308
    colors[0].rgbBlue = 0xff;
 
1309
    colors[1].rgbRed = 0x0;
 
1310
    colors[1].rgbGreen = 0x0;
 
1311
    colors[1].rgbBlue = 0x0;
1243
1312
 
1244
1313
    SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
1245
1314
    ok(ds_bits[0] == 0x55, "out_bits %02x\n", ds_bits[0]);
1248
1317
     * Take that 'normal' dibsection and change its colour table to an 'inverted' one
1249
1318
     */
1250
1319
 
1251
 
    pbmi->bmiColors[0].rgbRed = 0xff;
1252
 
    pbmi->bmiColors[0].rgbGreen = 0xff;
1253
 
    pbmi->bmiColors[0].rgbBlue = 0xff;
1254
 
    pbmi->bmiColors[1].rgbRed = 0x0;
1255
 
    pbmi->bmiColors[1].rgbGreen = 0x0;
1256
 
    pbmi->bmiColors[1].rgbBlue = 0x0;
1257
 
    num = SetDIBColorTable(memdc, 0, 2, pbmi->bmiColors);
 
1320
    colors[0].rgbRed = 0xff;
 
1321
    colors[0].rgbGreen = 0xff;
 
1322
    colors[0].rgbBlue = 0xff;
 
1323
    colors[1].rgbRed = 0x0;
 
1324
    colors[1].rgbGreen = 0x0;
 
1325
    colors[1].rgbBlue = 0x0;
 
1326
    num = SetDIBColorTable(memdc, 0, 2, colors);
1258
1327
    ok(num == 2, "num = %d\n", num);
1259
1328
 
1260
1329
    /* black border, white interior */
1272
1341
 
1273
1342
    /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
1274
1343
 
1275
 
    pbmi->bmiColors[0].rgbRed = 0x0;
1276
 
    pbmi->bmiColors[0].rgbGreen = 0x0;
1277
 
    pbmi->bmiColors[0].rgbBlue = 0x0;
1278
 
    pbmi->bmiColors[1].rgbRed = 0xff;
1279
 
    pbmi->bmiColors[1].rgbGreen = 0xff;
1280
 
    pbmi->bmiColors[1].rgbBlue = 0xff;
 
1344
    colors[0].rgbRed = 0x0;
 
1345
    colors[0].rgbGreen = 0x0;
 
1346
    colors[0].rgbBlue = 0x0;
 
1347
    colors[1].rgbRed = 0xff;
 
1348
    colors[1].rgbGreen = 0xff;
 
1349
    colors[1].rgbBlue = 0xff;
1281
1350
 
1282
1351
    SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
1283
1352
    ok(ds_bits[0] == 0x55, "out_bits %02x\n", ds_bits[0]);
1289
1358
     * Now a dib section with a strange colour map just for fun.  This behaves just like an inverted one.
1290
1359
     */
1291
1360
 
1292
 
    pbmi->bmiColors[0].rgbRed = 0xff;
1293
 
    pbmi->bmiColors[0].rgbGreen = 0x0;
1294
 
    pbmi->bmiColors[0].rgbBlue = 0x0;
1295
 
    pbmi->bmiColors[1].rgbRed = 0xfe;
1296
 
    pbmi->bmiColors[1].rgbGreen = 0x0;
1297
 
    pbmi->bmiColors[1].rgbBlue = 0x0;
 
1361
    colors[0].rgbRed = 0xff;
 
1362
    colors[0].rgbGreen = 0x0;
 
1363
    colors[0].rgbBlue = 0x0;
 
1364
    colors[1].rgbRed = 0xfe;
 
1365
    colors[1].rgbGreen = 0x0;
 
1366
    colors[1].rgbBlue = 0x0;
1298
1367
 
1299
1368
    mono_ds = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&ds_bits, NULL, 0);
1300
1369
    ok(mono_ds != NULL, "CreateDIBSection rets NULL\n");
1307
1376
 
1308
1377
    /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
1309
1378
 
1310
 
    pbmi->bmiColors[0].rgbRed = 0x0;
1311
 
    pbmi->bmiColors[0].rgbGreen = 0x0;
1312
 
    pbmi->bmiColors[0].rgbBlue = 0x0;
1313
 
    pbmi->bmiColors[1].rgbRed = 0xff;
1314
 
    pbmi->bmiColors[1].rgbGreen = 0xff;
1315
 
    pbmi->bmiColors[1].rgbBlue = 0xff;
 
1379
    colors[0].rgbRed = 0x0;
 
1380
    colors[0].rgbGreen = 0x0;
 
1381
    colors[0].rgbBlue = 0x0;
 
1382
    colors[1].rgbRed = 0xff;
 
1383
    colors[1].rgbGreen = 0xff;
 
1384
    colors[1].rgbBlue = 0xff;
1316
1385
 
1317
1386
    SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
1318
1387
    ok(ds_bits[0] == 0x55, "out_bits %02x\n", ds_bits[0]);
1319
1388
 
1320
1389
    /* SetDIBitsToDevice with a inverted bmi -> inverted dib section */
1321
1390
 
1322
 
    pbmi->bmiColors[0].rgbRed = 0xff;
1323
 
    pbmi->bmiColors[0].rgbGreen = 0xff;
1324
 
    pbmi->bmiColors[0].rgbBlue = 0xff;
1325
 
    pbmi->bmiColors[1].rgbRed = 0x0;
1326
 
    pbmi->bmiColors[1].rgbGreen = 0x0;
1327
 
    pbmi->bmiColors[1].rgbBlue = 0x0;
 
1391
    colors[0].rgbRed = 0xff;
 
1392
    colors[0].rgbGreen = 0xff;
 
1393
    colors[0].rgbBlue = 0xff;
 
1394
    colors[1].rgbRed = 0x0;
 
1395
    colors[1].rgbGreen = 0x0;
 
1396
    colors[1].rgbBlue = 0x0;
1328
1397
 
1329
1398
    SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
1330
1399
    ok(ds_bits[0] == 0xaa, "out_bits %02x\n", ds_bits[0]);
1466
1535
static void test_GetDIBits_selected_DIB(UINT bpp)
1467
1536
{
1468
1537
    HBITMAP dib;
1469
 
    char bmibuf[FIELD_OFFSET( BITMAPINFO, bmiColors[256] )];
1470
 
    char bmibuf2[FIELD_OFFSET( BITMAPINFO, bmiColors[256] )];
1471
 
    BITMAPINFO *info = (BITMAPINFO *)bmibuf;
1472
 
    BITMAPINFO *info2 = (BITMAPINFO *)bmibuf2;
 
1538
    BITMAPINFO *info;
 
1539
    BITMAPINFO *info2;
1473
1540
    void * bits;
1474
1541
    void * bits2;
1475
1542
    UINT dib_size, dib32_size;
1479
1546
    UINT i;
1480
1547
    int res;
1481
1548
 
 
1549
    info = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(BITMAPINFO, bmiColors[256]));
 
1550
    info2 = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(BITMAPINFO, bmiColors[256]));
 
1551
 
1482
1552
    /* Create a DIB section with a color table */
1483
1553
 
1484
1554
    info->bmiHeader.biSize          = sizeof(info->bmiHeader);
1567
1637
    SelectObject(dib_dc, old_bmp);
1568
1638
    DeleteDC(dib_dc);
1569
1639
    DeleteObject(dib);
 
1640
    HeapFree(GetProcessHeap(), 0, info2);
 
1641
    HeapFree(GetProcessHeap(), 0, info);
1570
1642
}
1571
1643
 
1572
1644
static void test_GetDIBits_selected_DDB(BOOL monochrome)
1573
1645
{
1574
1646
    HBITMAP ddb;
1575
 
    char bmibuf[FIELD_OFFSET( BITMAPINFO, bmiColors[256] )];
1576
 
    char bmibuf2[FIELD_OFFSET( BITMAPINFO, bmiColors[256] )];
1577
 
    BITMAPINFO *info = (BITMAPINFO *)bmibuf;
1578
 
    BITMAPINFO *info2 = (BITMAPINFO *)bmibuf2;
 
1647
    BITMAPINFO *info;
 
1648
    BITMAPINFO *info2;
1579
1649
    void * bits;
1580
1650
    void * bits2;
1581
1651
    HDC ddb_dc, dc;
1585
1655
    UINT i, j;
1586
1656
    int res;
1587
1657
 
 
1658
    info = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(BITMAPINFO, bmiColors[256]));
 
1659
    info2 = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(BITMAPINFO, bmiColors[256]));
 
1660
 
1588
1661
    width = height = 16;
1589
1662
 
1590
1663
    /* Create a DDB (device-dependent bitmap) */
1677
1750
    SelectObject(ddb_dc, old_bmp);
1678
1751
    DeleteDC(ddb_dc);
1679
1752
    DeleteObject(ddb);
 
1753
    HeapFree(GetProcessHeap(), 0, info2);
 
1754
    HeapFree(GetProcessHeap(), 0, info);
1680
1755
}
1681
1756
 
1682
1757
static void test_GetDIBits(void)
1776
1851
    BYTE buf[1024];
1777
1852
    char bi_buf[sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256];
1778
1853
    BITMAPINFO *bi = (BITMAPINFO *)bi_buf;
 
1854
    RGBQUAD *colors = bi->bmiColors;
1779
1855
    PALETTEENTRY pal_ents[20];
1780
1856
 
1781
1857
    hdc = GetDC(0);
1809
1885
    bi->bmiHeader.biPlanes = 1;
1810
1886
    bi->bmiHeader.biBitCount = 1;
1811
1887
    bi->bmiHeader.biCompression = BI_RGB;
 
1888
    bi->bmiHeader.biClrUsed = 37;
1812
1889
    bi->bmiHeader.biSizeImage = 0;
1813
 
    memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
 
1890
    memset(colors, 0xAA, sizeof(RGBQUAD) * 256);
1814
1891
    SetLastError(0xdeadbeef);
1815
1892
    lines = GetDIBits(0, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1816
1893
    ok(lines == 0, "GetDIBits copied %d lines with hdc = 0\n", lines);
1818
1895
       broken(GetLastError() == 0xdeadbeef), /* winnt */
1819
1896
       "wrong error %u\n", GetLastError());
1820
1897
    ok(bi->bmiHeader.biSizeImage == 0, "expected 0, got %u\n", bi->bmiHeader.biSizeImage);
 
1898
    ok(bi->bmiHeader.biClrUsed == 37 || broken(bi->bmiHeader.biClrUsed == 0),
 
1899
       "wrong biClrUsed %u\n", bi->bmiHeader.biClrUsed);
1821
1900
 
1822
1901
    memset(buf, 0xAA, sizeof(buf));
1823
1902
    SetLastError(0xdeadbeef);
1825
1904
    ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %u\n",
1826
1905
       lines, bm.bmHeight, GetLastError());
1827
1906
    ok(bi->bmiHeader.biSizeImage == sizeof(dib_bits_1), "expected 16*4, got %u\n", bi->bmiHeader.biSizeImage);
 
1907
    ok(bi->bmiHeader.biClrUsed == 0, "wrong biClrUsed %u\n", bi->bmiHeader.biClrUsed);
1828
1908
 
1829
1909
    /* the color table consists of black and white */
1830
 
    ok(bi->bmiColors[0].rgbRed == 0 && bi->bmiColors[0].rgbGreen == 0 &&
1831
 
       bi->bmiColors[0].rgbBlue == 0 && bi->bmiColors[0].rgbReserved == 0,
 
1910
    ok(colors[0].rgbRed == 0 && colors[0].rgbGreen == 0 &&
 
1911
       colors[0].rgbBlue == 0 && colors[0].rgbReserved == 0,
1832
1912
       "expected bmiColors[0] 0,0,0,0 - got %x %x %x %x\n",
1833
 
       bi->bmiColors[0].rgbRed, bi->bmiColors[0].rgbGreen,
1834
 
       bi->bmiColors[0].rgbBlue, bi->bmiColors[0].rgbReserved);
1835
 
    ok(bi->bmiColors[1].rgbRed == 0xff && bi->bmiColors[1].rgbGreen == 0xff &&
1836
 
       bi->bmiColors[1].rgbBlue == 0xff && bi->bmiColors[1].rgbReserved == 0,
 
1913
       colors[0].rgbRed, colors[0].rgbGreen, colors[0].rgbBlue, colors[0].rgbReserved);
 
1914
    ok(colors[1].rgbRed == 0xff && colors[1].rgbGreen == 0xff &&
 
1915
       colors[1].rgbBlue == 0xff && colors[1].rgbReserved == 0,
1837
1916
       "expected bmiColors[0] 0xff,0xff,0xff,0 - got %x %x %x %x\n",
1838
 
       bi->bmiColors[1].rgbRed, bi->bmiColors[1].rgbGreen,
1839
 
       bi->bmiColors[1].rgbBlue, bi->bmiColors[1].rgbReserved);
 
1917
       colors[1].rgbRed, colors[1].rgbGreen, colors[1].rgbBlue, colors[1].rgbReserved);
1840
1918
    for (i = 2; i < 256; i++)
1841
1919
    {
1842
 
        ok(bi->bmiColors[i].rgbRed == 0xAA && bi->bmiColors[i].rgbGreen == 0xAA &&
1843
 
           bi->bmiColors[i].rgbBlue == 0xAA && bi->bmiColors[i].rgbReserved == 0xAA,
 
1920
        ok(colors[i].rgbRed == 0xAA && colors[i].rgbGreen == 0xAA &&
 
1921
           colors[i].rgbBlue == 0xAA && colors[i].rgbReserved == 0xAA,
1844
1922
           "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i,
1845
 
           bi->bmiColors[i].rgbRed, bi->bmiColors[i].rgbGreen,
1846
 
           bi->bmiColors[i].rgbBlue, bi->bmiColors[i].rgbReserved);
 
1923
           colors[i].rgbRed, colors[i].rgbGreen, colors[i].rgbBlue, colors[i].rgbReserved);
1847
1924
    }
1848
1925
 
1849
1926
    /* returned bits are DWORD aligned and upside down */
1850
1927
    ok(!memcmp(buf, dib_bits_1, sizeof(dib_bits_1)), "DIB bits don't match\n");
1851
1928
 
1852
1929
    /* Test the palette indices */
1853
 
    memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
 
1930
    memset(colors, 0xAA, sizeof(RGBQUAD) * 256);
1854
1931
    SetLastError(0xdeadbeef);
1855
1932
    lines = GetDIBits(hdc, hbmp, 0, 0, NULL, bi, DIB_PAL_COLORS);
1856
 
    ok(((WORD*)bi->bmiColors)[0] == 0, "Color 0 is %d\n", ((WORD*)bi->bmiColors)[0]);
1857
 
    ok(((WORD*)bi->bmiColors)[1] == 1, "Color 1 is %d\n", ((WORD*)bi->bmiColors)[1]);
 
1933
    ok(((WORD*)colors)[0] == 0, "Color 0 is %d\n", ((WORD*)colors)[0]);
 
1934
    ok(((WORD*)colors)[1] == 1, "Color 1 is %d\n", ((WORD*)colors)[1]);
1858
1935
    for (i = 2; i < 256; i++)
1859
 
        ok(((WORD*)bi->bmiColors)[i] == 0xAAAA, "Color %d is %d\n", i, ((WORD*)bi->bmiColors)[1]);
 
1936
        ok(((WORD*)colors)[i] == 0xAAAA, "Color %d is %d\n", i, ((WORD*)colors)[1]);
1860
1937
 
1861
1938
    /* retrieve 24-bit DIB data */
1862
1939
    memset(bi, 0, sizeof(*bi));
1866
1943
    bi->bmiHeader.biPlanes = 1;
1867
1944
    bi->bmiHeader.biBitCount = 24;
1868
1945
    bi->bmiHeader.biCompression = BI_RGB;
 
1946
    bi->bmiHeader.biClrUsed = 37;
1869
1947
    bi->bmiHeader.biSizeImage = 0;
1870
 
    memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
 
1948
    memset(colors, 0xAA, sizeof(RGBQUAD) * 256);
1871
1949
    memset(buf, 0xAA, sizeof(buf));
1872
1950
    SetLastError(0xdeadbeef);
1873
1951
    lines = GetDIBits(hdc, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1874
1952
    ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %u\n",
1875
1953
       lines, bm.bmHeight, GetLastError());
1876
1954
    ok(bi->bmiHeader.biSizeImage == sizeof(dib_bits_24), "expected 16*16*3, got %u\n", bi->bmiHeader.biSizeImage);
 
1955
    ok(bi->bmiHeader.biClrUsed == 0, "wrong biClrUsed %u\n", bi->bmiHeader.biClrUsed);
1877
1956
 
1878
1957
    /* the color table doesn't exist for 24-bit images */
1879
1958
    for (i = 0; i < 256; i++)
1880
1959
    {
1881
 
        ok(bi->bmiColors[i].rgbRed == 0xAA && bi->bmiColors[i].rgbGreen == 0xAA &&
1882
 
           bi->bmiColors[i].rgbBlue == 0xAA && bi->bmiColors[i].rgbReserved == 0xAA,
 
1960
        ok(colors[i].rgbRed == 0xAA && colors[i].rgbGreen == 0xAA &&
 
1961
           colors[i].rgbBlue == 0xAA && colors[i].rgbReserved == 0xAA,
1883
1962
           "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i,
1884
 
           bi->bmiColors[i].rgbRed, bi->bmiColors[i].rgbGreen,
1885
 
           bi->bmiColors[i].rgbBlue, bi->bmiColors[i].rgbReserved);
 
1963
           colors[i].rgbRed, colors[i].rgbGreen, colors[i].rgbBlue, colors[i].rgbReserved);
1886
1964
    }
1887
1965
 
1888
1966
    /* returned bits are DWORD aligned and upside down */
1904
1982
    ok(bm.bmType == 0, "wrong bmType %d\n", bm.bmType);
1905
1983
    ok(bm.bmWidth == 16, "wrong bmWidth %d\n", bm.bmWidth);
1906
1984
    ok(bm.bmHeight == 16, "wrong bmHeight %d\n", bm.bmHeight);
1907
 
    ok(bm.bmWidthBytes == BITMAP_GetWidthBytes(bm.bmWidth, bm.bmBitsPixel), "wrong bmWidthBytes %d\n", bm.bmWidthBytes);
 
1985
    ok(bm.bmWidthBytes == get_bitmap_stride(bm.bmWidth, bm.bmBitsPixel), "wrong bmWidthBytes %d\n", bm.bmWidthBytes);
1908
1986
    ok(bm.bmPlanes == GetDeviceCaps(hdc, PLANES), "wrong bmPlanes %u\n", bm.bmPlanes);
1909
1987
    ok(bm.bmBitsPixel == GetDeviceCaps(hdc, BITSPIXEL), "wrong bmBitsPixel %d\n", bm.bmBitsPixel);
1910
1988
    ok(!bm.bmBits, "wrong bmBits %p\n", bm.bmBits);
1923
2001
    bi->bmiHeader.biPlanes = 1;
1924
2002
    bi->bmiHeader.biBitCount = 1;
1925
2003
    bi->bmiHeader.biCompression = BI_RGB;
 
2004
    bi->bmiHeader.biClrUsed = 37;
1926
2005
    bi->bmiHeader.biSizeImage = 0;
1927
 
    memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
 
2006
    memset(colors, 0xAA, sizeof(RGBQUAD) * 256);
1928
2007
    memset(buf, 0xAA, sizeof(buf));
1929
2008
    SetLastError(0xdeadbeef);
1930
2009
    lines = GetDIBits(hdc, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1931
2010
    ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %u\n",
1932
2011
       lines, bm.bmHeight, GetLastError());
1933
2012
    ok(bi->bmiHeader.biSizeImage == sizeof(dib_bits_1), "expected 16*4, got %u\n", bi->bmiHeader.biSizeImage);
 
2013
    ok(bi->bmiHeader.biClrUsed == 0, "wrong biClrUsed %u\n", bi->bmiHeader.biClrUsed);
1934
2014
 
1935
2015
    /* the color table consists of black and white */
1936
 
    ok(bi->bmiColors[0].rgbRed == 0 && bi->bmiColors[0].rgbGreen == 0 &&
1937
 
       bi->bmiColors[0].rgbBlue == 0 && bi->bmiColors[0].rgbReserved == 0,
 
2016
    ok(colors[0].rgbRed == 0 && colors[0].rgbGreen == 0 &&
 
2017
       colors[0].rgbBlue == 0 && colors[0].rgbReserved == 0,
1938
2018
       "expected bmiColors[0] 0,0,0,0 - got %x %x %x %x\n",
1939
 
       bi->bmiColors[0].rgbRed, bi->bmiColors[0].rgbGreen,
1940
 
       bi->bmiColors[0].rgbBlue, bi->bmiColors[0].rgbReserved);
1941
 
    ok(bi->bmiColors[1].rgbRed == 0xff && bi->bmiColors[1].rgbGreen == 0xff &&
1942
 
       bi->bmiColors[1].rgbBlue == 0xff && bi->bmiColors[1].rgbReserved == 0,
 
2019
       colors[0].rgbRed, colors[0].rgbGreen, colors[0].rgbBlue, colors[0].rgbReserved);
 
2020
    ok(colors[1].rgbRed == 0xff && colors[1].rgbGreen == 0xff &&
 
2021
       colors[1].rgbBlue == 0xff && colors[1].rgbReserved == 0,
1943
2022
       "expected bmiColors[0] 0xff,0xff,0xff,0 - got %x %x %x %x\n",
1944
 
       bi->bmiColors[1].rgbRed, bi->bmiColors[1].rgbGreen,
1945
 
       bi->bmiColors[1].rgbBlue, bi->bmiColors[1].rgbReserved);
 
2023
       colors[1].rgbRed, colors[1].rgbGreen, colors[1].rgbBlue, colors[1].rgbReserved);
1946
2024
    for (i = 2; i < 256; i++)
1947
2025
    {
1948
 
        ok(bi->bmiColors[i].rgbRed == 0xAA && bi->bmiColors[i].rgbGreen == 0xAA &&
1949
 
           bi->bmiColors[i].rgbBlue == 0xAA && bi->bmiColors[i].rgbReserved == 0xAA,
 
2026
        ok(colors[i].rgbRed == 0xAA && colors[i].rgbGreen == 0xAA &&
 
2027
           colors[i].rgbBlue == 0xAA && colors[i].rgbReserved == 0xAA,
1950
2028
           "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i,
1951
 
           bi->bmiColors[i].rgbRed, bi->bmiColors[i].rgbGreen,
1952
 
           bi->bmiColors[i].rgbBlue, bi->bmiColors[i].rgbReserved);
 
2029
           colors[i].rgbRed, colors[i].rgbGreen, colors[i].rgbBlue, colors[i].rgbReserved);
1953
2030
    }
1954
2031
 
1955
2032
    /* returned bits are DWORD aligned and upside down */
1956
2033
    ok(!memcmp(buf, dib_bits_1, sizeof(dib_bits_1)), "DIB bits don't match\n");
1957
2034
 
1958
2035
    /* Test the palette indices */
1959
 
    memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
 
2036
    memset(colors, 0xAA, sizeof(RGBQUAD) * 256);
1960
2037
    SetLastError(0xdeadbeef);
1961
2038
    lines = GetDIBits(hdc, hbmp, 0, 0, NULL, bi, DIB_PAL_COLORS);
1962
 
    ok(((WORD*)bi->bmiColors)[0] == 0, "Color 0 is %d\n", ((WORD*)bi->bmiColors)[0]);
1963
 
    ok(((WORD*)bi->bmiColors)[1] == 1, "Color 1 is %d\n", ((WORD*)bi->bmiColors)[1]);
 
2039
    ok(((WORD*)colors)[0] == 0, "Color 0 is %d\n", ((WORD*)colors)[0]);
 
2040
    ok(((WORD*)colors)[1] == 1, "Color 1 is %d\n", ((WORD*)colors)[1]);
1964
2041
    for (i = 2; i < 256; i++)
1965
 
        ok(((WORD*)bi->bmiColors)[i] == 0xAAAA, "Color %d is %d\n", i, ((WORD*)bi->bmiColors)[i]);
 
2042
        ok(((WORD*)colors)[i] == 0xAAAA, "Color %d is %d\n", i, ((WORD*)colors)[i]);
1966
2043
 
1967
2044
    /* retrieve 4-bit DIB data */
1968
2045
    memset(bi, 0, sizeof(*bi));
1972
2049
    bi->bmiHeader.biPlanes = 1;
1973
2050
    bi->bmiHeader.biBitCount = 4;
1974
2051
    bi->bmiHeader.biCompression = BI_RGB;
 
2052
    bi->bmiHeader.biClrUsed = 37;
1975
2053
    bi->bmiHeader.biSizeImage = 0;
1976
 
    memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
 
2054
    memset(colors, 0xAA, sizeof(RGBQUAD) * 256);
1977
2055
    memset(buf, 0xAA, sizeof(buf));
1978
2056
    SetLastError(0xdeadbeef);
1979
2057
    lines = GetDIBits(hdc, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1980
2058
    ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %u\n",
1981
2059
       lines, bm.bmHeight, GetLastError());
 
2060
    ok(bi->bmiHeader.biClrUsed == 0, "wrong biClrUsed %u\n", bi->bmiHeader.biClrUsed);
1982
2061
 
1983
2062
    GetPaletteEntries( GetStockObject(DEFAULT_PALETTE), 0, 20, pal_ents );
1984
2063
 
1995
2074
        expect.rgbBlue  = pal_ents[entry].peBlue;
1996
2075
        expect.rgbReserved = 0;
1997
2076
 
1998
 
        ok(!memcmp(bi->bmiColors + i, &expect, sizeof(expect)),
 
2077
        ok(!memcmp(colors + i, &expect, sizeof(expect)),
1999
2078
           "expected bmiColors[%d] %x %x %x %x - got %x %x %x %x\n", i,
2000
2079
           expect.rgbRed, expect.rgbGreen, expect.rgbBlue, expect.rgbReserved,
2001
 
           bi->bmiColors[i].rgbRed, bi->bmiColors[i].rgbGreen,
2002
 
           bi->bmiColors[i].rgbBlue, bi->bmiColors[i].rgbReserved);
 
2080
           colors[i].rgbRed, colors[i].rgbGreen, colors[i].rgbBlue, colors[i].rgbReserved);
2003
2081
    }
2004
2082
 
2005
2083
    /* retrieve 8-bit DIB data */
2010
2088
    bi->bmiHeader.biPlanes = 1;
2011
2089
    bi->bmiHeader.biBitCount = 8;
2012
2090
    bi->bmiHeader.biCompression = BI_RGB;
 
2091
    bi->bmiHeader.biClrUsed = 37;
2013
2092
    bi->bmiHeader.biSizeImage = 0;
2014
 
    memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
 
2093
    memset(colors, 0xAA, sizeof(RGBQUAD) * 256);
2015
2094
    memset(buf, 0xAA, sizeof(buf));
2016
2095
    SetLastError(0xdeadbeef);
2017
2096
    lines = GetDIBits(hdc, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
2018
2097
    ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %u\n",
2019
2098
       lines, bm.bmHeight, GetLastError());
 
2099
    ok(bi->bmiHeader.biClrUsed == 0, "wrong biClrUsed %u\n", bi->bmiHeader.biClrUsed);
2020
2100
 
2021
2101
    GetPaletteEntries( GetStockObject(DEFAULT_PALETTE), 0, 20, pal_ents );
2022
2102
 
2039
2119
        }
2040
2120
        expect.rgbReserved = 0;
2041
2121
 
2042
 
        ok(!memcmp(bi->bmiColors + i, &expect, sizeof(expect)),
 
2122
        ok(!memcmp(colors + i, &expect, sizeof(expect)),
2043
2123
           "expected bmiColors[%d] %x %x %x %x - got %x %x %x %x\n", i,
2044
2124
           expect.rgbRed, expect.rgbGreen, expect.rgbBlue, expect.rgbReserved,
2045
 
           bi->bmiColors[i].rgbRed, bi->bmiColors[i].rgbGreen,
2046
 
           bi->bmiColors[i].rgbBlue, bi->bmiColors[i].rgbReserved);
 
2125
           colors[i].rgbRed, colors[i].rgbGreen, colors[i].rgbBlue, colors[i].rgbReserved);
2047
2126
    }
2048
2127
 
2049
2128
    /* retrieve 24-bit DIB data */
2054
2133
    bi->bmiHeader.biPlanes = 1;
2055
2134
    bi->bmiHeader.biBitCount = 24;
2056
2135
    bi->bmiHeader.biCompression = BI_RGB;
 
2136
    bi->bmiHeader.biClrUsed = 37;
2057
2137
    bi->bmiHeader.biSizeImage = 0;
2058
 
    memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
 
2138
    memset(colors, 0xAA, sizeof(RGBQUAD) * 256);
2059
2139
    memset(buf, 0xAA, sizeof(buf));
2060
2140
    SetLastError(0xdeadbeef);
2061
2141
    lines = GetDIBits(hdc, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
2062
2142
    ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %u\n",
2063
2143
       lines, bm.bmHeight, GetLastError());
2064
2144
    ok(bi->bmiHeader.biSizeImage == sizeof(dib_bits_24), "expected 16*16*3, got %u\n", bi->bmiHeader.biSizeImage);
 
2145
    ok(bi->bmiHeader.biClrUsed == 0, "wrong biClrUsed %u\n", bi->bmiHeader.biClrUsed);
2065
2146
 
2066
2147
    /* the color table doesn't exist for 24-bit images */
2067
2148
    for (i = 0; i < 256; i++)
2068
2149
    {
2069
 
        ok(bi->bmiColors[i].rgbRed == 0xAA && bi->bmiColors[i].rgbGreen == 0xAA &&
2070
 
           bi->bmiColors[i].rgbBlue == 0xAA && bi->bmiColors[i].rgbReserved == 0xAA,
 
2150
        ok(colors[i].rgbRed == 0xAA && colors[i].rgbGreen == 0xAA &&
 
2151
           colors[i].rgbBlue == 0xAA && colors[i].rgbReserved == 0xAA,
2071
2152
           "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i,
2072
 
           bi->bmiColors[i].rgbRed, bi->bmiColors[i].rgbGreen,
2073
 
           bi->bmiColors[i].rgbBlue, bi->bmiColors[i].rgbReserved);
 
2153
           colors[i].rgbRed, colors[i].rgbGreen, colors[i].rgbBlue, colors[i].rgbReserved);
2074
2154
    }
2075
2155
 
2076
2156
    /* returned bits are DWORD aligned and upside down */
2378
2458
        ok(bm.bmType == 0, "wrong bmType %d\n", bm.bmType);
2379
2459
        ok(bm.bmWidth == 10, "wrong bmWidth %d\n", bm.bmWidth);
2380
2460
        ok(bm.bmHeight == 10, "wrong bmHeight %d\n", bm.bmHeight);
2381
 
        ok(bm.bmWidthBytes == BITMAP_GetWidthBytes(bm.bmWidth, bm.bmBitsPixel), "wrong bmWidthBytes %d\n", bm.bmWidthBytes);
 
2461
        ok(bm.bmWidthBytes == get_bitmap_stride(bm.bmWidth, bm.bmBitsPixel), "wrong bmWidthBytes %d\n", bm.bmWidthBytes);
2382
2462
        ok(bm.bmPlanes == planes, "wrong bmPlanes %u\n", bm.bmPlanes);
2383
2463
        if(depths[i] == 15) {
2384
2464
            ok(bm.bmBitsPixel == 16, "wrong bmBitsPixel %d(15 bpp special)\n", bm.bmBitsPixel);
2662
2742
    ReleaseDC(NULL, screen_dc);
2663
2743
}
2664
2744
 
2665
 
static BOOL compare_buffers_no_alpha(UINT32 *a, UINT32 *b, int length)
2666
 
{
2667
 
    int i;
2668
 
    for(i = 0; i < length; i++)
2669
 
        if((a[i] & 0x00FFFFFF) != (b[i] & 0x00FFFFFF))
2670
 
            return FALSE;
2671
 
    return TRUE;
2672
 
}
2673
 
 
2674
2745
static void check_BitBlt_pixel(HDC hdcDst, HDC hdcSrc, UINT32 *dstBuffer, UINT32 *srcBuffer,
2675
2746
                               DWORD dwRop, UINT32 expected, int line)
2676
2747
{
2760
2831
        dwRop, expected, *dstBuffer, line);
2761
2832
}
2762
2833
 
2763
 
static void check_StretchBlt_stretch(HDC hdcDst, HDC hdcSrc, UINT32 *dstBuffer, UINT32 *srcBuffer,
 
2834
static void check_StretchBlt_stretch(HDC hdcDst, HDC hdcSrc, BITMAPINFO *dst_info, UINT32 *dstBuffer, UINT32 *srcBuffer,
2764
2835
                                     int nXOriginDest, int nYOriginDest, int nWidthDest, int nHeightDest,
2765
2836
                                     int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc,
2766
 
                                     UINT32 expected[4], UINT32 legacy_expected[4], int line)
 
2837
                                     UINT32 *expected, int line)
2767
2838
{
2768
 
    memset(dstBuffer, 0, 16);
 
2839
    int dst_size = get_dib_image_size( dst_info );
 
2840
 
 
2841
    memset(dstBuffer, 0, dst_size);
2769
2842
    StretchBlt(hdcDst, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest,
2770
2843
               hdcSrc, nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc, SRCCOPY);
2771
 
    ok(memcmp(dstBuffer, expected, 16) == 0 ||
2772
 
        broken(compare_buffers_no_alpha(dstBuffer, legacy_expected, 4)),
 
2844
    ok(memcmp(dstBuffer, expected, dst_size) == 0,
2773
2845
        "StretchBlt expected { %08X, %08X, %08X, %08X } got { %08X, %08X, %08X, %08X } "
2774
2846
        "stretching { %d, %d, %d, %d } to { %d, %d, %d, %d } from line %d\n",
2775
2847
        expected[0], expected[1], expected[2], expected[3],
2786
2858
    UINT32 *dstBuffer, *srcBuffer;
2787
2859
    HBRUSH hBrush, hOldBrush;
2788
2860
    BITMAPINFO biDst, biSrc;
2789
 
    UINT32 expected[4], legacy_expected[4];
 
2861
    UINT32 expected[256];
 
2862
    RGBQUAD colors[2];
2790
2863
 
2791
2864
    memset(&biDst, 0, sizeof(BITMAPINFO));
2792
2865
    biDst.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2793
 
    biDst.bmiHeader.biWidth = 2;
2794
 
    biDst.bmiHeader.biHeight = -2;
 
2866
    biDst.bmiHeader.biWidth = 16;
 
2867
    biDst.bmiHeader.biHeight = -16;
2795
2868
    biDst.bmiHeader.biPlanes = 1;
2796
2869
    biDst.bmiHeader.biBitCount = 32;
2797
2870
    biDst.bmiHeader.biCompression = BI_RGB;
2806
2879
        NULL, 0);
2807
2880
    oldDst = SelectObject(hdcDst, bmpDst);
2808
2881
 
2809
 
    bmpSrc = CreateDIBSection(hdcScreen, &biDst, DIB_RGB_COLORS, (void**)&srcBuffer,
 
2882
    bmpSrc = CreateDIBSection(hdcScreen, &biSrc, DIB_RGB_COLORS, (void**)&srcBuffer,
2810
2883
        NULL, 0);
2811
2884
    oldSrc = SelectObject(hdcSrc, bmpSrc);
2812
2885
 
2834
2907
 
2835
2908
    /* Top-down to top-down tests */
2836
2909
    srcBuffer[0] = 0xCAFED00D, srcBuffer[1] = 0xFEEDFACE;
2837
 
    srcBuffer[2] = 0xFEDCBA98, srcBuffer[3] = 0x76543210;
 
2910
    srcBuffer[16] = 0xFEDCBA98, srcBuffer[17] = 0x76543210;
2838
2911
 
 
2912
    memset( expected, 0, get_dib_image_size( &biDst ) );
2839
2913
    expected[0] = 0xCAFED00D, expected[1] = 0xFEEDFACE;
2840
 
    expected[2] = 0xFEDCBA98, expected[3] = 0x76543210;
2841
 
    check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2842
 
                             0, 0, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
 
2914
    expected[16] = 0xFEDCBA98, expected[17] = 0x76543210;
 
2915
    check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
 
2916
                             0, 0, 2, 2, 0, 0, 2, 2, expected, __LINE__);
2843
2917
 
2844
2918
    expected[0] = 0xCAFED00D, expected[1] = 0x00000000;
2845
 
    expected[2] = 0x00000000, expected[3] = 0x00000000;
2846
 
    check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2847
 
                             0, 0, 1, 1, 0, 0, 1, 1, expected, expected, __LINE__);
 
2919
    expected[16] = 0x00000000, expected[17] = 0x00000000;
 
2920
    check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
 
2921
                             0, 0, 1, 1, 0, 0, 1, 1, expected, __LINE__);
2848
2922
 
2849
2923
    expected[0] = 0xCAFED00D, expected[1] = 0xCAFED00D;
2850
 
    expected[2] = 0xCAFED00D, expected[3] = 0xCAFED00D;
2851
 
    check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2852
 
                             0, 0, 2, 2, 0, 0, 1, 1, expected, expected, __LINE__);
2853
 
 
2854
 
    expected[0] = 0xCAFED00D, expected[1] = 0x00000000;
2855
 
    expected[2] = 0x00000000, expected[3] = 0x00000000;
2856
 
    check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2857
 
                             0, 0, 1, 1, 0, 0, 2, 2, expected, expected, __LINE__);
2858
 
 
2859
 
    expected[0] = 0x76543210, expected[1] = 0xFEDCBA98;
2860
 
    expected[2] = 0xFEEDFACE, expected[3] = 0xCAFED00D;
2861
 
    check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2862
 
                             0, 0, 2, 2, 1, 1, -2, -2, expected, expected, __LINE__);
2863
 
 
2864
 
    expected[0] = 0x76543210, expected[1] = 0xFEDCBA98;
2865
 
    expected[2] = 0xFEEDFACE, expected[3] = 0xCAFED00D;
2866
 
    check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2867
 
                             1, 1, -2, -2, 0, 0, 2, 2, expected, expected, __LINE__);
2868
 
 
2869
 
    /* This result seems broken. One might expect the following result:
2870
 
     * 0xCAFED00D 0xFEEDFACE
2871
 
     * 0xFEDCBA98 0x76543210
2872
 
     */
2873
 
    expected[0] = 0xCAFED00D, expected[1] = 0x00000000;
2874
 
    expected[2] = 0xFEDCBA98, expected[3] = 0x76543210;
2875
 
    legacy_expected[0] = 0xCAFED00D, legacy_expected[1] = 0x00000000;
2876
 
    legacy_expected[2] = 0x00000000, legacy_expected[3] = 0x00000000;
2877
 
    todo_wine check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2878
 
                                       1, 1, -2, -2, 1, 1, -2, -2, expected,
2879
 
                                       legacy_expected, __LINE__);
 
2924
    expected[16] = 0xCAFED00D, expected[17] = 0xCAFED00D;
 
2925
    check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
 
2926
                             0, 0, 2, 2, 0, 0, 1, 1, expected, __LINE__);
 
2927
 
 
2928
    /* This is an example of the dst width (height) == 1 exception, explored below */
 
2929
    expected[0] = 0xCAFED00D, expected[1] = 0x00000000;
 
2930
    expected[16] = 0x00000000, expected[17] = 0x00000000;
 
2931
    check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
 
2932
                             0, 0, 1, 1, 0, 0, 2, 2, expected, __LINE__);
 
2933
 
 
2934
    expected[0] = 0x76543210, expected[1] = 0xFEDCBA98;
 
2935
    expected[16] = 0xFEEDFACE, expected[17] = 0xCAFED00D;
 
2936
    check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
 
2937
                             0, 0, 2, 2, 1, 1, -2, -2, expected, __LINE__);
 
2938
 
 
2939
    expected[0] = 0x76543210, expected[1] = 0xFEDCBA98;
 
2940
    expected[16] = 0xFEEDFACE, expected[17] = 0xCAFED00D;
 
2941
    check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
 
2942
                             1, 1, -2, -2, 0, 0, 2, 2, expected, __LINE__);
 
2943
 
 
2944
    expected[0] = 0xCAFED00D, expected[1] = 0x00000000;
 
2945
    expected[16] = 0x00000000, expected[17] = 0x00000000;
 
2946
    todo_wine check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
 
2947
                                       1, 1, -2, -2, 1, 1, -2, -2, expected, __LINE__);
2880
2948
 
2881
2949
    expected[0] = 0x00000000, expected[1] = 0x00000000;
2882
 
    expected[2] = 0x00000000, expected[3] = 0xCAFED00D;
2883
 
    check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2884
 
                             1, 1, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
 
2950
    expected[16] = 0x00000000, expected[17] = 0xCAFED00D, expected[18] = 0xFEEDFACE;
 
2951
    expected[32] = 0x00000000, expected[33] = 0xFEDCBA98, expected[34] = 0x76543210;
 
2952
 
 
2953
    check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
 
2954
                             1, 1, 2, 2, 0, 0, 2, 2, expected, __LINE__);
 
2955
 
 
2956
    /* when dst width is 1 merge src width - 1 pixels */
 
2957
    memset( srcBuffer, 0, get_dib_image_size( &biSrc ) );
 
2958
    srcBuffer[0] = 0x0000ff00, srcBuffer[1] = 0x0000f0f0, srcBuffer[2] = 0x0000cccc, srcBuffer[3] = 0x0000aaaa;
 
2959
    srcBuffer[16] = 0xFEDCBA98, srcBuffer[17] = 0x76543210;
 
2960
 
 
2961
    memset( expected, 0, get_dib_image_size( &biDst ) );
 
2962
    expected[0] = srcBuffer[0];
 
2963
    check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
 
2964
                             0, 0, 1, 1, 0, 0, 2, 1, expected, __LINE__);
 
2965
 
 
2966
    expected[0] = srcBuffer[0] & srcBuffer[1];
 
2967
    check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
 
2968
                             0, 0, 1, 1, 0, 0, 3, 1, expected, __LINE__);
 
2969
 
 
2970
    expected[0] = srcBuffer[0] & srcBuffer[1] & srcBuffer[2];
 
2971
    check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
 
2972
                             0, 0, 1, 1, 0, 0, 4, 1, expected, __LINE__);
 
2973
 
 
2974
    /* this doesn't happen if the src width is -ve */
 
2975
    expected[0] = srcBuffer[1] & srcBuffer[2];
 
2976
    check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
 
2977
                             0, 0, 1, 1, 2, 0, -2, 1, expected, __LINE__);
 
2978
 
 
2979
    /* when dst width > 1 behaviour reverts to what one would expect */
 
2980
    expected[0] = srcBuffer[0] & srcBuffer[1], expected[1] = srcBuffer[2] & srcBuffer[3];
 
2981
    check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
 
2982
                             0, 0, 2, 1, 0, 0, 4, 1, expected, __LINE__);
 
2983
 
 
2984
    /* similarly in the vertical direction */
 
2985
    memset( expected, 0, get_dib_image_size( &biDst ) );
 
2986
    expected[0] = srcBuffer[0];
 
2987
    check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
 
2988
                             0, 0, 1, 1, 0, 0, 1, 2, expected, __LINE__);
 
2989
 
 
2990
    /* check that it's the dst size in device units that needs to be 1 */
 
2991
    SetMapMode( hdcDst, MM_ISOTROPIC );
 
2992
    SetWindowExtEx( hdcDst, 200, 200, NULL );
 
2993
    SetViewportExtEx( hdcDst, 100, 100, NULL );
 
2994
 
 
2995
    expected[0] = srcBuffer[0] & srcBuffer[1] & srcBuffer[2];
 
2996
    check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
 
2997
                             0, 0, 2, 2, 0, 0, 4, 1, expected, __LINE__);
 
2998
    SetMapMode( hdcDst, MM_TEXT );
2885
2999
 
2886
3000
    SelectObject(hdcDst, oldDst);
2887
3001
    DeleteObject(bmpDst);
2888
3002
 
2889
3003
    /* Top-down to bottom-up tests */
2890
 
    biDst.bmiHeader.biHeight = 2;
 
3004
    memset( srcBuffer, 0, get_dib_image_size( &biSrc ) );
 
3005
    srcBuffer[0] = 0xCAFED00D, srcBuffer[1] = 0xFEEDFACE;
 
3006
    srcBuffer[16] = 0xFEDCBA98, srcBuffer[17] = 0x76543210;
 
3007
 
 
3008
    biDst.bmiHeader.biHeight = 16;
2891
3009
    bmpDst = CreateDIBSection(hdcScreen, &biDst, DIB_RGB_COLORS, (void**)&dstBuffer,
2892
3010
        NULL, 0);
2893
3011
    oldDst = SelectObject(hdcDst, bmpDst);
2894
3012
 
2895
 
    expected[0] = 0xFEDCBA98, expected[1] = 0x76543210;
2896
 
    expected[2] = 0xCAFED00D, expected[3] = 0xFEEDFACE;
2897
 
    check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2898
 
                             0, 0, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
2899
 
 
2900
 
    expected[0] = 0xFEEDFACE, expected[1] = 0xCAFED00D;
2901
 
    expected[2] = 0x76543210, expected[3] = 0xFEDCBA98;
2902
 
    check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2903
 
                             0, 0, 2, 2, 1, 1, -2, -2, expected, expected, __LINE__);
 
3013
    memset( expected, 0, get_dib_image_size( &biDst ) );
 
3014
 
 
3015
    expected[224] = 0xFEDCBA98, expected[225] = 0x76543210;
 
3016
    expected[240] = 0xCAFED00D, expected[241] = 0xFEEDFACE;
 
3017
    check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
 
3018
                             0, 0, 2, 2, 0, 0, 2, 2, expected, __LINE__);
 
3019
 
 
3020
    expected[224] = 0xFEEDFACE, expected[225] = 0xCAFED00D;
 
3021
    expected[240] = 0x76543210, expected[241] = 0xFEDCBA98;
 
3022
    check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
 
3023
                             0, 0, 2, 2, 1, 1, -2, -2, expected, __LINE__);
2904
3024
 
2905
3025
    SelectObject(hdcSrc, oldSrc);
2906
3026
    DeleteObject(bmpSrc);
2907
3027
 
2908
3028
    /* Bottom-up to bottom-up tests */
2909
 
    biSrc.bmiHeader.biHeight = 2;
 
3029
    biSrc.bmiHeader.biHeight = 16;
2910
3030
    bmpSrc = CreateDIBSection(hdcScreen, &biSrc, DIB_RGB_COLORS, (void**)&srcBuffer,
2911
3031
        NULL, 0);
2912
 
    srcBuffer[0] = 0xCAFED00D, srcBuffer[1] = 0xFEEDFACE;
2913
 
    srcBuffer[2] = 0xFEDCBA98, srcBuffer[3] = 0x76543210;
 
3032
    srcBuffer[224] = 0xCAFED00D, srcBuffer[225] = 0xFEEDFACE;
 
3033
    srcBuffer[240] = 0xFEDCBA98, srcBuffer[241] = 0x76543210;
2914
3034
    oldSrc = SelectObject(hdcSrc, bmpSrc);
2915
3035
 
2916
 
    expected[0] = 0xCAFED00D, expected[1] = 0xFEEDFACE;
2917
 
    expected[2] = 0xFEDCBA98, expected[3] = 0x76543210;
2918
 
    check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2919
 
                             0, 0, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
2920
 
 
2921
 
    expected[0] = 0x76543210, expected[1] = 0xFEDCBA98;
2922
 
    expected[2] = 0xFEEDFACE, expected[3] = 0xCAFED00D;
2923
 
    check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2924
 
                             0, 0, 2, 2, 1, 1, -2, -2, expected, expected, __LINE__);
 
3036
    memset( expected, 0, get_dib_image_size( &biDst ) );
 
3037
 
 
3038
    expected[224] = 0xCAFED00D, expected[225] = 0xFEEDFACE;
 
3039
    expected[240] = 0xFEDCBA98, expected[241] = 0x76543210;
 
3040
    check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
 
3041
                             0, 0, 2, 2, 0, 0, 2, 2, expected, __LINE__);
 
3042
 
 
3043
    expected[224] = 0x76543210, expected[225] = 0xFEDCBA98;
 
3044
    expected[240] = 0xFEEDFACE, expected[241] = 0xCAFED00D;
 
3045
    check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
 
3046
                             0, 0, 2, 2, 1, 1, -2, -2, expected, __LINE__);
2925
3047
 
2926
3048
    SelectObject(hdcDst, oldDst);
2927
3049
    DeleteObject(bmpDst);
2928
3050
 
2929
3051
    /* Bottom-up to top-down tests */
2930
 
    biDst.bmiHeader.biHeight = -2;
 
3052
    biDst.bmiHeader.biHeight = -16;
2931
3053
    bmpDst = CreateDIBSection(hdcScreen, &biDst, DIB_RGB_COLORS, (void**)&dstBuffer,
2932
3054
        NULL, 0);
2933
3055
    oldDst = SelectObject(hdcDst, bmpDst);
2934
3056
 
 
3057
    memset( expected, 0, get_dib_image_size( &biDst ) );
2935
3058
    expected[0] = 0xFEDCBA98, expected[1] = 0x76543210;
2936
 
    expected[2] = 0xCAFED00D, expected[3] = 0xFEEDFACE;
2937
 
    check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2938
 
                             0, 0, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
2939
 
 
2940
 
    expected[0] = 0xFEEDFACE, expected[1] = 0xCAFED00D;
2941
 
    expected[2] = 0x76543210, expected[3] = 0xFEDCBA98;
2942
 
    check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2943
 
                             0, 0, 2, 2, 1, 1, -2, -2, expected, expected, __LINE__);
2944
 
 
2945
 
    /* Tidy up */
2946
 
    SelectObject(hdcSrc, oldSrc);
2947
 
    DeleteObject(bmpSrc);
 
3059
    expected[16] = 0xCAFED00D, expected[17] = 0xFEEDFACE;
 
3060
    check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
 
3061
                             0, 0, 2, 2, 0, 0, 2, 2, expected, __LINE__);
 
3062
 
 
3063
    expected[0] = 0xFEEDFACE, expected[1] = 0xCAFED00D;
 
3064
    expected[16] = 0x76543210, expected[17] = 0xFEDCBA98;
 
3065
    check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
 
3066
                             0, 0, 2, 2, 1, 1, -2, -2, expected, __LINE__);
 
3067
 
 
3068
    SelectObject(hdcSrc, oldSrc);
 
3069
    DeleteObject(bmpSrc);
 
3070
 
 
3071
    biSrc.bmiHeader.biHeight = -2;
 
3072
    biSrc.bmiHeader.biBitCount = 24;
 
3073
    bmpSrc = CreateDIBSection(hdcScreen, &biSrc, DIB_RGB_COLORS, (void**)&srcBuffer, NULL, 0);
 
3074
    oldSrc = SelectObject(hdcSrc, bmpSrc);
 
3075
 
 
3076
    memset( expected, 0, get_dib_image_size( &biDst ) );
 
3077
    expected[0] = 0xFEEDFACE, expected[1] = 0xCAFED00D;
 
3078
    expected[2] = 0x76543210, expected[3] = 0xFEDCBA98;
 
3079
    memcpy(dstBuffer, expected, 4 * sizeof(*dstBuffer));
 
3080
    StretchBlt(hdcSrc, 0, 0, 4, 1, hdcDst, 0, 0, 4, 1, SRCCOPY );
 
3081
    memset(dstBuffer, 0x55, 4 * sizeof(*dstBuffer));
 
3082
    StretchBlt(hdcDst, 0, 0, 4, 1, hdcSrc, 0, 0, 4, 1, SRCCOPY );
 
3083
    expected[0] = 0x00EDFACE, expected[1] = 0x00FED00D;
 
3084
    expected[2] = 0x00543210, expected[3] = 0x00DCBA98;
 
3085
    ok(!memcmp(dstBuffer, expected, 16),
 
3086
       "StretchBlt expected { %08X, %08X, %08X, %08X } got { %08X, %08X, %08X, %08X }\n",
 
3087
        expected[0], expected[1], expected[2], expected[3],
 
3088
        dstBuffer[0], dstBuffer[1], dstBuffer[2], dstBuffer[3] );
 
3089
 
 
3090
    expected[0] = 0xFEEDFACE, expected[1] = 0xCAFED00D;
 
3091
    expected[2] = 0x76543210, expected[3] = 0xFEDCBA98;
 
3092
    memcpy(srcBuffer, expected, 4 * sizeof(*dstBuffer));
 
3093
    memset(dstBuffer, 0x55, 4 * sizeof(*dstBuffer));
 
3094
    StretchBlt(hdcDst, 0, 0, 4, 1, hdcSrc, 0, 0, 4, 1, SRCCOPY );
 
3095
    expected[0] = 0x00EDFACE, expected[1] = 0x00D00DFE;
 
3096
    expected[2] = 0x0010CAFE, expected[3] = 0x00765432;
 
3097
    ok(!memcmp(dstBuffer, expected, 16),
 
3098
       "StretchBlt expected { %08X, %08X, %08X, %08X } got { %08X, %08X, %08X, %08X }\n",
 
3099
        expected[0], expected[1], expected[2], expected[3],
 
3100
        dstBuffer[0], dstBuffer[1], dstBuffer[2], dstBuffer[3] );
 
3101
 
 
3102
    SelectObject(hdcSrc, oldSrc);
 
3103
    DeleteObject(bmpSrc);
 
3104
 
 
3105
    biSrc.bmiHeader.biBitCount = 1;
 
3106
    bmpSrc = CreateDIBSection(hdcScreen, &biSrc, DIB_RGB_COLORS, (void**)&srcBuffer, NULL, 0);
 
3107
    oldSrc = SelectObject(hdcSrc, bmpSrc);
 
3108
    *((DWORD *)colors + 0) = 0x123456;
 
3109
    *((DWORD *)colors + 1) = 0x335577;
 
3110
    SetDIBColorTable( hdcSrc, 0, 2, colors );
 
3111
    srcBuffer[0] = 0x55555555;
 
3112
    memset(dstBuffer, 0xcc, 4 * sizeof(*dstBuffer));
 
3113
    SetTextColor( hdcDst, 0 );
 
3114
    SetBkColor( hdcDst, 0 );
 
3115
    StretchBlt(hdcDst, 0, 0, 4, 1, hdcSrc, 0, 0, 4, 1, SRCCOPY );
 
3116
    expected[0] = expected[2] = 0x00123456;
 
3117
    expected[1] = expected[3] = 0x00335577;
 
3118
    ok(!memcmp(dstBuffer, expected, 16),
 
3119
       "StretchBlt expected { %08X, %08X, %08X, %08X } got { %08X, %08X, %08X, %08X }\n",
 
3120
        expected[0], expected[1], expected[2], expected[3],
 
3121
        dstBuffer[0], dstBuffer[1], dstBuffer[2], dstBuffer[3] );
 
3122
 
 
3123
    SelectObject(hdcSrc, oldSrc);
 
3124
    DeleteObject(bmpSrc);
 
3125
 
 
3126
    bmpSrc = CreateBitmap( 16, 16, 1, 1, 0 );
 
3127
    oldSrc = SelectObject(hdcSrc, bmpSrc);
 
3128
    SetPixel( hdcSrc, 0, 0, 0 );
 
3129
    SetPixel( hdcSrc, 1, 0, 0xffffff );
 
3130
    SetPixel( hdcSrc, 2, 0, 0xffffff );
 
3131
    SetPixel( hdcSrc, 3, 0, 0 );
 
3132
    memset(dstBuffer, 0xcc, 4 * sizeof(*dstBuffer));
 
3133
    SetTextColor( hdcDst, RGB(0x22,0x44,0x66) );
 
3134
    SetBkColor( hdcDst, RGB(0x65,0x43,0x21) );
 
3135
    StretchBlt(hdcDst, 0, 0, 4, 1, hdcSrc, 0, 0, 4, 1, SRCCOPY );
 
3136
    expected[0] = expected[3] = 0x00224466;
 
3137
    expected[1] = expected[2] = 0x00654321;
 
3138
    ok(!memcmp(dstBuffer, expected, 16),
 
3139
       "StretchBlt expected { %08X, %08X, %08X, %08X } got { %08X, %08X, %08X, %08X }\n",
 
3140
        expected[0], expected[1], expected[2], expected[3],
 
3141
        dstBuffer[0], dstBuffer[1], dstBuffer[2], dstBuffer[3] );
 
3142
 
 
3143
    SelectObject(hdcSrc, oldSrc);
 
3144
    DeleteObject(bmpSrc);
 
3145
 
2948
3146
    DeleteDC(hdcSrc);
2949
3147
 
2950
3148
    SelectObject(hdcDst, oldDst);
2980
3178
static void check_StretchDIBits_stretch(HDC hdcDst, UINT32 *dstBuffer, UINT32 *srcBuffer,
2981
3179
                                        int nXOriginDest, int nYOriginDest, int nWidthDest, int nHeightDest,
2982
3180
                                        int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc,
2983
 
                                        UINT32 expected[4], UINT32 legacy_expected[4], int line)
 
3181
                                        UINT32 expected[4], int line)
2984
3182
{
2985
3183
    BITMAPINFO bitmapInfo;
2986
3184
 
3013
3211
    UINT32 *dstBuffer, srcBuffer[4];
3014
3212
    HBRUSH hBrush, hOldBrush;
3015
3213
    BITMAPINFO biDst;
3016
 
    UINT32 expected[4], legacy_expected[4];
 
3214
    UINT32 expected[4];
3017
3215
 
3018
3216
    memset(&biDst, 0, sizeof(BITMAPINFO));
3019
3217
    biDst.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
3060
3258
    expected[0] = 0xCAFED00D, expected[1] = 0xFEEDFACE;
3061
3259
    expected[2] = 0xFEDCBA98, expected[3] = 0x76543210;
3062
3260
    check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
3063
 
                                0, 0, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
 
3261
                                0, 0, 2, 2, 0, 0, 2, 2, expected, __LINE__);
3064
3262
 
3065
3263
    expected[0] = 0xCAFED00D, expected[1] = 0x00000000;
3066
3264
    expected[2] = 0x00000000, expected[3] = 0x00000000;
3067
 
    legacy_expected[0] = 0xFEDCBA98, legacy_expected[1] = 0x00000000;
3068
 
    legacy_expected[2] = 0x00000000, legacy_expected[3] = 0x00000000;
3069
3265
    check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
3070
 
                                0, 0, 1, 1, 0, 0, 1, 1, expected, legacy_expected, __LINE__);
 
3266
                                0, 0, 1, 1, 0, 0, 1, 1, expected, __LINE__);
3071
3267
 
3072
3268
    expected[0] = 0xFEDCBA98, expected[1] = 0xFEDCBA98;
3073
3269
    expected[2] = 0xFEDCBA98, expected[3] = 0xFEDCBA98;
3074
3270
    check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
3075
 
                                0, 0, 2, 2, 0, 0, 1, 1, expected, expected, __LINE__);
 
3271
                                0, 0, 2, 2, 0, 0, 1, 1, expected, __LINE__);
3076
3272
 
3077
3273
    expected[0] = 0x42441000, expected[1] = 0x00000000;
3078
3274
    expected[2] = 0x00000000, expected[3] = 0x00000000;
3079
 
    legacy_expected[0] = 0x00543210, legacy_expected[1] = 0x00000000;
3080
 
    legacy_expected[2] = 0x00000000, legacy_expected[3] = 0x00000000;
3081
 
    todo_wine check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
3082
 
                                0, 0, 1, 1, 0, 0, 2, 2, expected, legacy_expected, __LINE__);
3083
 
 
3084
 
    expected[0] = 0x00000000, expected[1] = 0x00000000;
3085
 
    expected[2] = 0x00000000, expected[3] = 0x00000000;
3086
 
    check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
3087
 
                                0, 0, 2, 2, 1, 1, -2, -2, expected, expected, __LINE__);
3088
 
 
3089
 
    expected[0] = 0x00000000, expected[1] = 0x00000000;
3090
 
    expected[2] = 0x00000000, expected[3] = 0x00000000;
3091
 
    check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
3092
 
                                0, 0, 2, 2, 1, 1, -2, -2, expected, expected, __LINE__);
3093
 
 
3094
 
    expected[0] = 0x00000000, expected[1] = 0x00000000;
3095
 
    expected[2] = 0x00000000, expected[3] = 0x00000000;
3096
 
    check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
3097
 
                                1, 1, -2, -2, 1, 1, -2, -2, expected, expected, __LINE__);
 
3275
    check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
 
3276
                                0, 0, 1, 1, 0, 0, 2, 2, expected, __LINE__);
 
3277
 
 
3278
    expected[0] = 0x00000000, expected[1] = 0x00000000;
 
3279
    expected[2] = 0x00000000, expected[3] = 0x00000000;
 
3280
    check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
 
3281
                                0, 0, 2, 2, 1, 1, -2, -2, expected, __LINE__);
 
3282
 
 
3283
    expected[0] = 0x00000000, expected[1] = 0x00000000;
 
3284
    expected[2] = 0x00000000, expected[3] = 0x00000000;
 
3285
    check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
 
3286
                                0, 0, 2, 2, 1, 1, -2, -2, expected, __LINE__);
 
3287
 
 
3288
    expected[0] = 0x00000000, expected[1] = 0x00000000;
 
3289
    expected[2] = 0x00000000, expected[3] = 0x00000000;
 
3290
    check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
 
3291
                                1, 1, -2, -2, 1, 1, -2, -2, expected, __LINE__);
3098
3292
 
3099
3293
    expected[0] = 0x00000000, expected[1] = 0x00000000;
3100
3294
    expected[2] = 0x00000000, expected[3] = 0xCAFED00D;
3101
3295
    check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
3102
 
                                1, 1, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
 
3296
                                1, 1, 2, 2, 0, 0, 2, 2, expected, __LINE__);
3103
3297
 
3104
3298
    SelectObject(hdcDst, oldDst);
3105
3299
    DeleteObject(bmpDst);
3113
3307
    expected[0] = 0xFEDCBA98, expected[1] = 0x76543210;
3114
3308
    expected[2] = 0xCAFED00D, expected[3] = 0xFEEDFACE;
3115
3309
    check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
3116
 
                                0, 0, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
 
3310
                                0, 0, 2, 2, 0, 0, 2, 2, expected, __LINE__);
3117
3311
 
3118
3312
    /* Tidy up */
3119
3313
    SelectObject(hdcDst, oldDst);
3125
3319
 
3126
3320
static void test_GdiAlphaBlend(void)
3127
3321
{
3128
 
    /* test out-of-bound parameters for GdiAlphaBlend */
3129
3322
    HDC hdcNull;
3130
 
 
3131
3323
    HDC hdcDst;
3132
3324
    HBITMAP bmpDst;
3133
3325
    HBITMAP oldDst;
3134
 
 
3135
 
    BITMAPINFO bmi;
 
3326
    BITMAPINFO *bmi;
3136
3327
    HDC hdcSrc;
3137
3328
    HBITMAP bmpSrc;
3138
3329
    HBITMAP oldSrc;
3139
3330
    LPVOID bits;
3140
 
 
 
3331
    BOOL ret;
3141
3332
    BLENDFUNCTION blend;
3142
3333
 
3143
3334
    if (!pGdiAlphaBlend)
3151
3342
    bmpDst = CreateCompatibleBitmap(hdcNull, 100, 100);
3152
3343
    hdcSrc = CreateCompatibleDC(hdcNull);
3153
3344
 
3154
 
    memset(&bmi, 0, sizeof(bmi));  /* as of Wine 0.9.44 we require the src to be a DIB section */
3155
 
    bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
3156
 
    bmi.bmiHeader.biHeight = 20;
3157
 
    bmi.bmiHeader.biWidth = 20;
3158
 
    bmi.bmiHeader.biBitCount = 32;
3159
 
    bmi.bmiHeader.biPlanes = 1;
3160
 
    bmi.bmiHeader.biCompression = BI_RGB;
3161
 
    bmpSrc = CreateDIBSection(hdcDst, &bmi, DIB_RGB_COLORS, &bits, NULL, 0);
 
3345
    bmi = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, FIELD_OFFSET( BITMAPINFO, bmiColors[3] ));
 
3346
    bmi->bmiHeader.biSize = sizeof(bmi->bmiHeader);
 
3347
    bmi->bmiHeader.biHeight = 20;
 
3348
    bmi->bmiHeader.biWidth = 20;
 
3349
    bmi->bmiHeader.biBitCount = 32;
 
3350
    bmi->bmiHeader.biPlanes = 1;
 
3351
    bmi->bmiHeader.biCompression = BI_RGB;
 
3352
    bmpSrc = CreateDIBSection(hdcDst, bmi, DIB_RGB_COLORS, &bits, NULL, 0);
3162
3353
    ok(bmpSrc != NULL, "Couldn't create source bitmap\n");
3163
3354
 
3164
3355
    oldDst = SelectObject(hdcDst, bmpDst);
3169
3360
    blend.SourceConstantAlpha = 128;
3170
3361
    blend.AlphaFormat = 0;
3171
3362
 
3172
 
    expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, 0, 20, 20, blend), TRUE, BOOL, "%d");
3173
 
    SetLastError(0xdeadbeef);
3174
 
    expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, -1, 0, 10, 10, blend), FALSE, BOOL, "%d");
3175
 
    expect_eq(GetLastError(), ERROR_INVALID_PARAMETER, int, "%d");
3176
 
    expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, -1, 10, 10, blend), FALSE, BOOL, "%d");
3177
 
    expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 15, 0, 10, 10, blend), FALSE, BOOL, "%d");
3178
 
    expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 10, 10, -2, 3, blend), FALSE, BOOL, "%d");
3179
 
    expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 10, 10, -2, 3, blend), FALSE, BOOL, "%d");
 
3363
    SetLastError(0xdeadbeef);
 
3364
    ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, 0, 20, 20, blend);
 
3365
    ok( ret, "GdiAlphaBlend failed err %u\n", GetLastError() );
 
3366
 
 
3367
    SetLastError(0xdeadbeef);
 
3368
    ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, -1, 0, 10, 10, blend);
 
3369
    ok( !ret, "GdiAlphaBlend succeeded\n" );
 
3370
    ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
 
3371
 
 
3372
    ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, -1, 10, 10, blend);
 
3373
    ok( !ret, "GdiAlphaBlend succeeded\n" );
 
3374
    ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 15, 0, 10, 10, blend);
 
3375
    ok( !ret, "GdiAlphaBlend succeeded\n" );
 
3376
    ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 10, 10, -2, 3, blend);
 
3377
    ok( !ret, "GdiAlphaBlend succeeded\n" );
 
3378
    ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 10, 10, -2, 3, blend);
 
3379
    ok( !ret, "GdiAlphaBlend succeeded\n" );
3180
3380
 
3181
3381
    SetWindowOrgEx(hdcSrc, -10, -10, NULL);
3182
 
    expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, -1, 0, 10, 10, blend), TRUE, BOOL, "%d");
3183
 
    expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, -1, 10, 10, blend), TRUE, BOOL, "%d");
 
3382
    SetLastError(0xdeadbeef);
 
3383
    ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, -1, 0, 10, 10, blend);
 
3384
    ok( ret, "GdiAlphaBlend failed err %u\n", GetLastError() );
 
3385
    SetLastError(0xdeadbeef);
 
3386
    ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, -1, 10, 10, blend);
 
3387
    ok( ret, "GdiAlphaBlend failed err %u\n", GetLastError() );
3184
3388
    SetMapMode(hdcSrc, MM_ANISOTROPIC);
3185
3389
    ScaleWindowExtEx(hdcSrc, 10, 1, 10, 1, NULL);
3186
 
    expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, -1, 0, 30, 30, blend), TRUE, BOOL, "%d");
3187
 
    expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, -1, 30, 30, blend), TRUE, BOOL, "%d");
3188
 
 
3189
 
    SetLastError(0xdeadbeef);
3190
 
    expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, NULL, 0, 0, 20, 20, blend), FALSE, BOOL, "%d");
3191
 
    expect_eq(GetLastError(), 0xdeadbeef, int, "%d");
 
3390
    SetLastError(0xdeadbeef);
 
3391
    ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, -1, 0, 30, 30, blend);
 
3392
    ok( ret, "GdiAlphaBlend failed err %u\n", GetLastError() );
 
3393
    SetLastError(0xdeadbeef);
 
3394
    ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, -1, 30, 30, blend);
 
3395
    ok( ret, "GdiAlphaBlend failed err %u\n", GetLastError() );
 
3396
 
 
3397
    SetLastError(0xdeadbeef);
 
3398
    ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, NULL, 0, 0, 20, 20, blend);
 
3399
    ok( !ret, "GdiAlphaBlend succeeded\n" );
 
3400
    ok( GetLastError() == 0xdeadbeef, "wrong error %u\n", GetLastError() );
 
3401
 
 
3402
    /* overlapping source and dest not allowed */
 
3403
 
 
3404
    SetLastError(0xdeadbeef);
 
3405
    ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcDst, 19, 19, 20, 20, blend);
 
3406
    ok( !ret, "GdiAlphaBlend succeeded\n" );
 
3407
    ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
 
3408
 
 
3409
    SetLastError(0xdeadbeef);
 
3410
    ret = pGdiAlphaBlend(hdcDst, 20, 20, 20, 20, hdcDst, 1, 1, 20, 20, blend);
 
3411
    ok( !ret, "GdiAlphaBlend succeeded\n" );
 
3412
    ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
 
3413
 
 
3414
    SetLastError(0xdeadbeef);
 
3415
    ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcDst, 20, 10, 20, 20, blend);
 
3416
    ok( ret, "GdiAlphaBlend succeeded\n" );
 
3417
    SetLastError(0xdeadbeef);
 
3418
    ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcDst, 10, 20, 20, 20, blend);
 
3419
    ok( ret, "GdiAlphaBlend succeeded\n" );
 
3420
 
 
3421
    /* AC_SRC_ALPHA requires 32-bpp BI_RGB format */
 
3422
 
 
3423
    blend.AlphaFormat = AC_SRC_ALPHA;
 
3424
    SetLastError(0xdeadbeef);
 
3425
    ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, 0, 20, 20, blend);
 
3426
    ok( ret, "GdiAlphaBlend failed err %u\n", GetLastError() );
 
3427
 
 
3428
    bmi->bmiHeader.biCompression = BI_BITFIELDS;
 
3429
    ((DWORD *)bmi->bmiColors)[0] = 0xff0000;
 
3430
    ((DWORD *)bmi->bmiColors)[1] = 0x00ff00;
 
3431
    ((DWORD *)bmi->bmiColors)[2] = 0x0000ff;
 
3432
    bmpSrc = CreateDIBSection(hdcDst, bmi, DIB_RGB_COLORS, &bits, NULL, 0);
 
3433
    ok(bmpSrc != NULL, "Couldn't create source bitmap\n");
 
3434
    oldSrc = SelectObject(hdcSrc, bmpSrc);
 
3435
    DeleteObject( oldSrc );
 
3436
 
 
3437
    SetLastError(0xdeadbeef);
 
3438
    ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, 0, 20, 20, blend);
 
3439
    ok( ret, "GdiAlphaBlend failed err %u\n", GetLastError() );
 
3440
 
 
3441
    bmi->bmiHeader.biCompression = BI_BITFIELDS;
 
3442
    ((DWORD *)bmi->bmiColors)[0] = 0x0000ff;
 
3443
    ((DWORD *)bmi->bmiColors)[1] = 0x00ff00;
 
3444
    ((DWORD *)bmi->bmiColors)[2] = 0xff0000;
 
3445
    bmpSrc = CreateDIBSection(hdcDst, bmi, DIB_RGB_COLORS, &bits, NULL, 0);
 
3446
    ok(bmpSrc != NULL, "Couldn't create source bitmap\n");
 
3447
    oldSrc = SelectObject(hdcSrc, bmpSrc);
 
3448
    DeleteObject( oldSrc );
 
3449
 
 
3450
    SetLastError(0xdeadbeef);
 
3451
    ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, 0, 20, 20, blend);
 
3452
    ok( !ret, "GdiAlphaBlend succeeded\n" );
 
3453
    ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
 
3454
 
 
3455
    bmi->bmiHeader.biBitCount = 24;
 
3456
    bmi->bmiHeader.biCompression = BI_RGB;
 
3457
    bmpSrc = CreateDIBSection(hdcDst, bmi, DIB_RGB_COLORS, &bits, NULL, 0);
 
3458
    ok(bmpSrc != NULL, "Couldn't create source bitmap\n");
 
3459
    oldSrc = SelectObject(hdcSrc, bmpSrc);
 
3460
    DeleteObject( oldSrc );
 
3461
 
 
3462
    SetLastError(0xdeadbeef);
 
3463
    ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, 0, 20, 20, blend);
 
3464
    ok( !ret, "GdiAlphaBlend succeeded\n" );
 
3465
    ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
 
3466
 
 
3467
    bmi->bmiHeader.biBitCount = 1;
 
3468
    bmpSrc = CreateDIBSection(hdcDst, bmi, DIB_RGB_COLORS, &bits, NULL, 0);
 
3469
    ok(bmpSrc != NULL, "Couldn't create source bitmap\n");
 
3470
    oldSrc = SelectObject(hdcSrc, bmpSrc);
 
3471
    DeleteObject( oldSrc );
 
3472
 
 
3473
    SetLastError(0xdeadbeef);
 
3474
    ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, 0, 20, 20, blend);
 
3475
    ok( !ret, "GdiAlphaBlend succeeded\n" );
 
3476
    ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
 
3477
 
 
3478
    bmpSrc = CreateBitmap( 100, 100, 1, 1, NULL );
 
3479
    ok(bmpSrc != NULL, "Couldn't create source bitmap\n");
 
3480
    oldSrc = SelectObject(hdcSrc, bmpSrc);
 
3481
    DeleteObject( oldSrc );
 
3482
 
 
3483
    SetLastError(0xdeadbeef);
 
3484
    ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, 0, 20, 20, blend);
 
3485
    ok( !ret, "GdiAlphaBlend succeeded\n" );
 
3486
    ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
3192
3487
 
3193
3488
    SelectObject(hdcDst, oldDst);
3194
3489
    SelectObject(hdcSrc, oldSrc);
3201
3496
 
3202
3497
}
3203
3498
 
 
3499
static void test_GdiGradientFill(void)
 
3500
{
 
3501
    HDC hdc;
 
3502
    BOOL ret;
 
3503
    HBITMAP bmp;
 
3504
    BITMAPINFO *bmi;
 
3505
    void *bits;
 
3506
    GRADIENT_RECT rect[] = { { 0, 0 }, { 0, 1 }, { 2, 3 } };
 
3507
    GRADIENT_TRIANGLE tri[] = { { 0, 0, 0 }, { 0, 1, 2 }, { 0, 2, 1 }, { 0, 1, 3 } };
 
3508
    TRIVERTEX vt[3] = { { 2,  2,  0xff00, 0x0000, 0x0000, 0x8000 },
 
3509
                        { 10, 10, 0x0000, 0xff00, 0x0000, 0x8000 },
 
3510
                        { 20, 10, 0x0000, 0x0000, 0xff00, 0xff00 } };
 
3511
 
 
3512
    if (!pGdiGradientFill)
 
3513
    {
 
3514
        win_skip( "GdiGradientFill is not implemented\n" );
 
3515
        return;
 
3516
    }
 
3517
 
 
3518
    hdc = CreateCompatibleDC( NULL );
 
3519
    bmi = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, FIELD_OFFSET( BITMAPINFO, bmiColors[3] ));
 
3520
    bmi->bmiHeader.biSize = sizeof(bmi->bmiHeader);
 
3521
    bmi->bmiHeader.biHeight = 20;
 
3522
    bmi->bmiHeader.biWidth = 20;
 
3523
    bmi->bmiHeader.biBitCount = 32;
 
3524
    bmi->bmiHeader.biPlanes = 1;
 
3525
    bmi->bmiHeader.biCompression = BI_RGB;
 
3526
    bmp = CreateDIBSection(hdc, bmi, DIB_RGB_COLORS, &bits, NULL, 0);
 
3527
    ok( bmp != NULL, "couldn't create bitmap\n" );
 
3528
    SelectObject( hdc, bmp );
 
3529
 
 
3530
    SetLastError( 0xdeadbeef );
 
3531
    ret = pGdiGradientFill( hdc, vt, 3, rect, 1, GRADIENT_FILL_RECT_H );
 
3532
    ok( ret, "GdiGradientFill failed err %u\n", GetLastError() );
 
3533
    SetLastError( 0xdeadbeef );
 
3534
    ret = pGdiGradientFill( hdc, vt, 3, rect, 1, 3 );
 
3535
    ok( !ret, "GdiGradientFill succeeded\n" );
 
3536
    ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
 
3537
    SetLastError( 0xdeadbeef );
 
3538
    ret = pGdiGradientFill( (HDC)0xdead, vt, 3, rect, 1, GRADIENT_FILL_RECT_H );
 
3539
    ok( !ret, "GdiGradientFill succeeded\n" );
 
3540
    ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
 
3541
    SetLastError( 0xdeadbeef );
 
3542
    ret = pGdiGradientFill( NULL, NULL, 0, rect, 1, GRADIENT_FILL_RECT_H );
 
3543
    ok( !ret, "GdiGradientFill succeeded\n" );
 
3544
    ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
 
3545
    ret = pGdiGradientFill( hdc, NULL, 0, rect, 1, GRADIENT_FILL_RECT_H );
 
3546
    ok( !ret, "GdiGradientFill succeeded\n" );
 
3547
    ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
 
3548
    SetLastError( 0xdeadbeef );
 
3549
    ret = pGdiGradientFill( hdc, NULL, 3, rect, 1, GRADIENT_FILL_RECT_H );
 
3550
    ok( !ret, "GdiGradientFill succeeded\n" );
 
3551
    ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
 
3552
    SetLastError( 0xdeadbeef );
 
3553
    ret = pGdiGradientFill( hdc, vt, 3, NULL, 0, GRADIENT_FILL_RECT_H );
 
3554
    ok( !ret, "GdiGradientFill succeeded\n" );
 
3555
    ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
 
3556
    SetLastError( 0xdeadbeef );
 
3557
    ret = pGdiGradientFill( hdc, vt, 3, NULL, 1, GRADIENT_FILL_RECT_H );
 
3558
    ok( !ret, "GdiGradientFill succeeded\n" );
 
3559
    ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
 
3560
    SetLastError( 0xdeadbeef );
 
3561
    ret = pGdiGradientFill( hdc, vt, 3, rect, 0, GRADIENT_FILL_RECT_H );
 
3562
    ok( !ret, "GdiGradientFill succeeded\n" );
 
3563
    ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
 
3564
    SetLastError( 0xdeadbeef );
 
3565
    ret = pGdiGradientFill( hdc, vt, 3, rect, 3, GRADIENT_FILL_RECT_H );
 
3566
    ok( !ret, "GdiGradientFill succeeded\n" );
 
3567
    ok( GetLastError() == 0xdeadbeef, "wrong error %u\n", GetLastError() );
 
3568
    rect[2].UpperLeft = rect[2].LowerRight = 1;
 
3569
    SetLastError( 0xdeadbeef );
 
3570
    ret = pGdiGradientFill( hdc, vt, 3, rect, 3, GRADIENT_FILL_RECT_H );
 
3571
    ok( ret, "GdiGradientFill failed err %u\n", GetLastError() );
 
3572
    SetLastError( 0xdeadbeef );
 
3573
    ret = pGdiGradientFill( hdc, vt, 1, rect, 1, GRADIENT_FILL_RECT_H );
 
3574
    ok( ret, "GdiGradientFill failed err %u\n", GetLastError() );
 
3575
    SetLastError( 0xdeadbeef );
 
3576
    ret = pGdiGradientFill( hdc, vt, 1, tri, 0, GRADIENT_FILL_TRIANGLE );
 
3577
    ok( !ret, "GdiGradientFill succeeded\n" );
 
3578
    ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
 
3579
    SetLastError( 0xdeadbeef );
 
3580
    ret = pGdiGradientFill( hdc, vt, 1, tri, 1, GRADIENT_FILL_TRIANGLE );
 
3581
    ok( ret, "GdiGradientFill failed err %u\n", GetLastError() );
 
3582
    SetLastError( 0xdeadbeef );
 
3583
    ret = pGdiGradientFill( hdc, vt, 3, tri, 2, GRADIENT_FILL_TRIANGLE );
 
3584
    ok( ret, "GdiGradientFill failed err %u\n", GetLastError() );
 
3585
    SetLastError( 0xdeadbeef );
 
3586
    ret = pGdiGradientFill( hdc, vt, 3, tri, 3, GRADIENT_FILL_TRIANGLE );
 
3587
    ok( ret, "GdiGradientFill failed err %u\n", GetLastError() );
 
3588
    SetLastError( 0xdeadbeef );
 
3589
    ret = pGdiGradientFill( hdc, vt, 3, tri, 4, GRADIENT_FILL_TRIANGLE );
 
3590
    ok( !ret, "GdiGradientFill succeeded\n" );
 
3591
    ok( GetLastError() == 0xdeadbeef, "wrong error %u\n", GetLastError() );
 
3592
    tri[3].Vertex3 = 1;
 
3593
    SetLastError( 0xdeadbeef );
 
3594
    ret = pGdiGradientFill( hdc, vt, 3, tri, 4, GRADIENT_FILL_TRIANGLE );
 
3595
    ok( !ret, "GdiGradientFill succeeded\n" );
 
3596
    ok( GetLastError() == 0xdeadbeef, "wrong error %u\n", GetLastError() );
 
3597
    tri[3].Vertex3 = 0;
 
3598
    SetLastError( 0xdeadbeef );
 
3599
    ret = pGdiGradientFill( hdc, vt, 3, tri, 4, GRADIENT_FILL_TRIANGLE );
 
3600
    ok( !ret, "GdiGradientFill succeeded\n" );
 
3601
    ok( GetLastError() == 0xdeadbeef, "wrong error %u\n", GetLastError() );
 
3602
    tri[3].Vertex1 = tri[3].Vertex2 = tri[3].Vertex3 = 1;
 
3603
    SetLastError( 0xdeadbeef );
 
3604
    ret = pGdiGradientFill( hdc, vt, 3, tri, 4, GRADIENT_FILL_TRIANGLE );
 
3605
    ok( ret, "GdiGradientFill failed err %u\n", GetLastError() );
 
3606
 
 
3607
    DeleteDC( hdc );
 
3608
    DeleteObject( bmp );
 
3609
}
 
3610
 
3204
3611
static void test_clipping(void)
3205
3612
{
3206
3613
    HBITMAP bmpDst;
3244
3651
    DeleteDC( hdcSrc );
3245
3652
}
3246
3653
 
3247
 
static void test_32bit_bitmap_blt(void)
 
3654
static void test_32bit_ddb(void)
3248
3655
{
3249
 
    BITMAPINFO biDst;
 
3656
    char buffer[sizeof(BITMAPINFOHEADER) + sizeof(DWORD)];
 
3657
    BITMAPINFO *biDst = (BITMAPINFO *)buffer;
3250
3658
    HBITMAP bmpSrc, bmpDst;
3251
3659
    HBITMAP oldSrc, oldDst;
3252
3660
    HDC hdcSrc, hdcDst, hdcScreen;
3253
 
    UINT32 *dstBuffer;
3254
 
    DWORD colorSrc = 0x11223344;
 
3661
    HBRUSH brush;
 
3662
    DWORD *dstBuffer, *data;
 
3663
    DWORD colorSrc = 0x40201008;
3255
3664
 
3256
 
    memset(&biDst, 0, sizeof(BITMAPINFO));
3257
 
    biDst.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
3258
 
    biDst.bmiHeader.biWidth = 2;
3259
 
    biDst.bmiHeader.biHeight = -2;
3260
 
    biDst.bmiHeader.biPlanes = 1;
3261
 
    biDst.bmiHeader.biBitCount = 32;
3262
 
    biDst.bmiHeader.biCompression = BI_RGB;
 
3665
    memset(biDst, 0, sizeof(BITMAPINFOHEADER));
 
3666
    biDst->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
 
3667
    biDst->bmiHeader.biWidth = 1;
 
3668
    biDst->bmiHeader.biHeight = -1;
 
3669
    biDst->bmiHeader.biPlanes = 1;
 
3670
    biDst->bmiHeader.biBitCount = 32;
 
3671
    biDst->bmiHeader.biCompression = BI_RGB;
3263
3672
 
3264
3673
    hdcScreen = CreateCompatibleDC(0);
3265
3674
    if(GetDeviceCaps(hdcScreen, BITSPIXEL) != 32)
3274
3683
    oldSrc = SelectObject(hdcSrc, bmpSrc);
3275
3684
 
3276
3685
    hdcDst = CreateCompatibleDC(hdcScreen);
3277
 
    bmpDst = CreateDIBSection(hdcDst, &biDst, DIB_RGB_COLORS, (void**)&dstBuffer, NULL, 0);
 
3686
    bmpDst = CreateDIBSection(hdcDst, biDst, DIB_RGB_COLORS, (void**)&dstBuffer, NULL, 0);
3278
3687
    oldDst = SelectObject(hdcDst, bmpDst);
3279
3688
 
3280
3689
    StretchBlt(hdcDst, 0, 0, 1, 1, hdcSrc, 0, 0, 1, 1, SRCCOPY);
3281
3690
    ok(dstBuffer[0] == colorSrc, "Expected color=%x, received color=%x\n", colorSrc, dstBuffer[0]);
3282
3691
 
 
3692
    if (pGdiAlphaBlend)
 
3693
    {
 
3694
        BLENDFUNCTION blend;
 
3695
        BOOL ret;
 
3696
 
 
3697
        blend.BlendOp = AC_SRC_OVER;
 
3698
        blend.BlendFlags = 0;
 
3699
        blend.SourceConstantAlpha = 128;
 
3700
        blend.AlphaFormat = 0;
 
3701
        dstBuffer[0] = 0x80808080;
 
3702
        ret = pGdiAlphaBlend( hdcDst, 0, 0, 1, 1, hdcSrc, 0, 0, 1, 1, blend );
 
3703
        ok( ret, "GdiAlphaBlend failed err %u\n", GetLastError() );
 
3704
        ok(dstBuffer[0] == 0x60504844, "wrong color %x\n", dstBuffer[0]);
 
3705
        blend.AlphaFormat = AC_SRC_ALPHA;
 
3706
        dstBuffer[0] = 0x80808080;
 
3707
        ret = pGdiAlphaBlend( hdcDst, 0, 0, 1, 1, hdcSrc, 0, 0, 1, 1, blend );
 
3708
        ok( ret, "GdiAlphaBlend failed err %u\n", GetLastError() );
 
3709
        ok(dstBuffer[0] == 0x90807874, "wrong color %x\n", dstBuffer[0]);
 
3710
    }
 
3711
 
 
3712
    data = (DWORD *)biDst->bmiColors;
 
3713
    data[0] = 0x20304050;
 
3714
    brush = CreateDIBPatternBrushPt( biDst, DIB_RGB_COLORS );
 
3715
    ok( brush != 0, "brush creation failed\n" );
 
3716
    SelectObject( hdcSrc, brush );
 
3717
    PatBlt( hdcSrc, 0, 0, 1, 1, PATCOPY );
 
3718
    BitBlt( hdcDst, 0, 0, 1, 1, hdcSrc, 0, 0, SRCCOPY );
 
3719
    ok(dstBuffer[0] == data[0], "Expected color=%x, received color=%x\n", data[0], dstBuffer[0]);
 
3720
    SelectObject( hdcSrc, GetStockObject(BLACK_BRUSH) );
 
3721
    DeleteObject( brush );
 
3722
 
 
3723
    biDst->bmiHeader.biBitCount = 24;
 
3724
    brush = CreateDIBPatternBrushPt( biDst, DIB_RGB_COLORS );
 
3725
    ok( brush != 0, "brush creation failed\n" );
 
3726
    SelectObject( hdcSrc, brush );
 
3727
    PatBlt( hdcSrc, 0, 0, 1, 1, PATCOPY );
 
3728
    BitBlt( hdcDst, 0, 0, 1, 1, hdcSrc, 0, 0, SRCCOPY );
 
3729
    ok(dstBuffer[0] == (data[0] & ~0xff000000),
 
3730
       "Expected color=%x, received color=%x\n", data[0] & 0xff000000, dstBuffer[0]);
 
3731
    SelectObject( hdcSrc, GetStockObject(BLACK_BRUSH) );
 
3732
    DeleteObject( brush );
 
3733
 
3283
3734
    /* Tidy up */
3284
3735
    SelectObject(hdcDst, oldDst);
3285
3736
    DeleteObject(bmpDst);
3475
3926
 
3476
3927
static void test_GetDIBits_scanlines(void)
3477
3928
{
3478
 
    char bmi_buf[ FIELD_OFFSET( BITMAPINFO, bmiColors[256] ) ];
3479
 
    BITMAPINFO *info = (BITMAPINFO *)bmi_buf;
 
3929
    BITMAPINFO *info;
3480
3930
    DWORD *dib_bits;
3481
3931
    HDC hdc = GetDC( NULL );
3482
3932
    HBITMAP dib;
3483
3933
    DWORD data[128], inverted_bits[64];
3484
3934
    int i, ret;
3485
3935
 
3486
 
    memset( info, 0, sizeof(bmi_buf) );
 
3936
    info = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, FIELD_OFFSET( BITMAPINFO, bmiColors[256] ) );
3487
3937
 
3488
3938
    info->bmiHeader.biSize        = sizeof(info->bmiHeader);
3489
3939
    info->bmiHeader.biWidth       = 8;
3788
4238
    DeleteObject( dib );
3789
4239
 
3790
4240
    ReleaseDC( NULL, hdc );
 
4241
    HeapFree( GetProcessHeap(), 0, info );
3791
4242
}
3792
4243
 
3793
4244
 
3794
4245
static void test_SetDIBits(void)
3795
4246
{
3796
 
    char bmi_buf[ FIELD_OFFSET( BITMAPINFO, bmiColors[256] ) ];
3797
 
    BITMAPINFO *info = (BITMAPINFO *)bmi_buf;
 
4247
    char palbuf[sizeof(LOGPALETTE) + 256 * sizeof(PALETTEENTRY)];
 
4248
    LOGPALETTE *pal = (LOGPALETTE *)palbuf;
 
4249
    PALETTEENTRY *palent = pal->palPalEntry;
 
4250
    HPALETTE palette;
 
4251
    BITMAPINFO *info;
3798
4252
    DWORD *dib_bits;
3799
4253
    HDC hdc = GetDC( NULL );
3800
4254
    DWORD data[128], inverted_data[128];
3801
4255
    HBITMAP dib;
3802
4256
    int i, ret;
3803
4257
 
3804
 
    memset( info, 0, sizeof(bmi_buf) );
 
4258
    info = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, FIELD_OFFSET( BITMAPINFO, bmiColors[256] ) );
3805
4259
 
3806
4260
    info->bmiHeader.biSize        = sizeof(info->bmiHeader);
3807
4261
    info->bmiHeader.biWidth       = 8;
3962
4416
    for (i = 32; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08x\n", i, dib_bits[i] );
3963
4417
    memset( dib_bits, 0xaa, 64 * 4 );
3964
4418
 
 
4419
    /* handling of partial color table */
 
4420
 
 
4421
    info->bmiHeader.biHeight   = -8;
 
4422
    info->bmiHeader.biBitCount = 8;
 
4423
    info->bmiHeader.biClrUsed  = 137;
 
4424
    for (i = 0; i < 256; i++)
 
4425
    {
 
4426
        info->bmiColors[i].rgbRed      = 255 - i;
 
4427
        info->bmiColors[i].rgbGreen    = i * 2;
 
4428
        info->bmiColors[i].rgbBlue     = i;
 
4429
        info->bmiColors[i].rgbReserved = 0;
 
4430
    }
 
4431
    for (i = 0; i < 64; i++) ((BYTE *)data)[i] = i * 4 + 1;
 
4432
    ret = SetDIBits( hdc, dib, 0, 8, data, info, DIB_RGB_COLORS );
 
4433
    ok( ret == 8, "got %d\n", ret );
 
4434
    for (i = 0; i < 64; i++)
 
4435
    {
 
4436
        int idx = i * 4 + 1;
 
4437
        DWORD expect = idx >= info->bmiHeader.biClrUsed ? 0 : (info->bmiColors[idx].rgbRed << 16 |
 
4438
                                                               info->bmiColors[idx].rgbGreen << 8 |
 
4439
                                                               info->bmiColors[idx].rgbBlue);
 
4440
        ok( dib_bits[i] == expect, "%d: got %08x instead of %08x\n", i, dib_bits[i], expect );
 
4441
    }
 
4442
    memset( dib_bits, 0xaa, 64 * 4 );
 
4443
 
 
4444
    /* handling of DIB_PAL_COLORS */
 
4445
 
 
4446
    pal->palVersion = 0x300;
 
4447
    pal->palNumEntries = 137;
 
4448
    info->bmiHeader.biClrUsed = 221;
 
4449
    for (i = 0; i < 256; i++)
 
4450
    {
 
4451
        palent[i].peRed   = i * 2;
 
4452
        palent[i].peGreen = 255 - i;
 
4453
        palent[i].peBlue  = i;
 
4454
    }
 
4455
    palette = CreatePalette( pal );
 
4456
    ok( palette != 0, "palette creation failed\n" );
 
4457
    SelectPalette( hdc, palette, FALSE );
 
4458
    for (i = 0; i < 256; i++) ((WORD *)info->bmiColors)[i] = 255 - i;
 
4459
    ret = SetDIBits( hdc, dib, 0, 8, data, info, DIB_PAL_COLORS );
 
4460
    ok( ret == 8, "got %d\n", ret );
 
4461
    for (i = 0; i < 64; i++)
 
4462
    {
 
4463
        int idx = i * 4 + 1;
 
4464
        int ent = (255 - idx) % pal->palNumEntries;
 
4465
        DWORD expect = idx >= info->bmiHeader.biClrUsed ? 0 :
 
4466
                        (palent[ent].peRed << 16 | palent[ent].peGreen << 8 | palent[ent].peBlue);
 
4467
        ok( dib_bits[i] == expect || broken(dib_bits[i] == 0),  /* various Windows versions get some values wrong */
 
4468
            "%d: got %08x instead of %08x\n", i, dib_bits[i], expect );
 
4469
    }
 
4470
    memset( dib_bits, 0xaa, 64 * 4 );
 
4471
 
 
4472
    ReleaseDC( NULL, hdc );
3965
4473
    DeleteObject( dib );
3966
 
    ReleaseDC( NULL, hdc );
 
4474
    DeleteObject( palette );
 
4475
    HeapFree( GetProcessHeap(), 0, info );
3967
4476
}
3968
4477
 
3969
4478
static void test_SetDIBits_RLE4(void)
3970
4479
{
3971
 
    char bmi_buf[ FIELD_OFFSET( BITMAPINFO, bmiColors[256] ) ];
3972
 
    BITMAPINFO *info = (BITMAPINFO *)bmi_buf;
 
4480
    BITMAPINFO *info;
3973
4481
    DWORD *dib_bits;
3974
4482
    HDC hdc = GetDC( NULL );
3975
4483
    BYTE rle4_data[26] = { 0x03, 0x52, 0x07, 0x68, 0x00, 0x00,     /* 5, 2, 5, 6, 8, 6, 8, 6, (8, 6,) <eol> */
3988
4496
                            0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa,
3989
4497
                            0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa };
3990
4498
 
3991
 
    memset( info, 0, sizeof(bmi_buf) );
 
4499
    info = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, FIELD_OFFSET( BITMAPINFO, bmiColors[256] ) );
3992
4500
 
3993
4501
    info->bmiHeader.biSize        = sizeof(info->bmiHeader);
3994
4502
    info->bmiHeader.biWidth       = 8;
4019
4527
 
4020
4528
    DeleteObject( dib );
4021
4529
    ReleaseDC( NULL, hdc );
 
4530
    HeapFree( GetProcessHeap(), 0, info );
4022
4531
}
4023
4532
 
4024
4533
static void test_SetDIBits_RLE8(void)
4025
4534
{
4026
 
    char bmi_buf[ FIELD_OFFSET( BITMAPINFO, bmiColors[256] ) ];
4027
 
    BITMAPINFO *info = (BITMAPINFO *)bmi_buf;
 
4535
    BITMAPINFO *info;
4028
4536
    DWORD *dib_bits;
4029
4537
    HDC hdc = GetDC( NULL );
4030
4538
    BYTE rle8_data[20] = { 0x03, 0x02, 0x04, 0xf0, 0x00, 0x00,     /* 2, 2, 2, f0, f0, f0, f0, <eol> */
4050
4558
                            0x00040404, 0x00050505, 0x00060606, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa,
4051
4559
                            0x00020202, 0x00020202, 0x00020202, 0x00f0f0f0, 0x00f0f0f0, 0x00f0f0f0, 0x00f0f0f0, 0xaaaaaaaa };
4052
4560
 
4053
 
    memset( info, 0, sizeof(bmi_buf) );
 
4561
    info = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, FIELD_OFFSET( BITMAPINFO, bmiColors[256] ) );
4054
4562
 
4055
4563
    info->bmiHeader.biSize        = sizeof(info->bmiHeader);
4056
4564
    info->bmiHeader.biWidth       = 8;
4168
4676
    memset( dib_bits, 0xaa, 64 * 4 );
4169
4677
 
4170
4678
    DeleteObject( dib );
4171
 
 
4172
4679
    ReleaseDC( NULL, hdc );
 
4680
    HeapFree( GetProcessHeap(), 0, info );
4173
4681
}
4174
4682
 
4175
4683
static void test_SetDIBitsToDevice(void)
4176
4684
{
4177
 
    char bmi_buf[ FIELD_OFFSET( BITMAPINFO, bmiColors[256] ) ];
4178
 
    BITMAPINFO *info = (BITMAPINFO *)bmi_buf;
 
4685
    char palbuf[sizeof(LOGPALETTE) + 256 * sizeof(PALETTEENTRY)];
 
4686
    LOGPALETTE *pal = (LOGPALETTE *)palbuf;
 
4687
    PALETTEENTRY *palent = pal->palPalEntry;
 
4688
    HPALETTE palette;
 
4689
    BITMAPINFO *info;
4179
4690
    DWORD *dib_bits;
4180
4691
    HDC hdc = CreateCompatibleDC( 0 );
4181
4692
    DWORD data[128], inverted_data[128];
4182
4693
    HBITMAP dib;
4183
4694
    int i, ret;
4184
4695
 
4185
 
    memset( info, 0, sizeof(bmi_buf) );
 
4696
    info = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, FIELD_OFFSET( BITMAPINFO, bmiColors[256] ) );
4186
4697
 
4187
4698
    info->bmiHeader.biSize        = sizeof(info->bmiHeader);
4188
4699
    info->bmiHeader.biWidth       = 8;
4533
5044
    for (i = 0; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08x\n", i, dib_bits[i] );
4534
5045
    memset( dib_bits, 0xaa, 64 * 4 );
4535
5046
 
 
5047
    /* handling of partial color table */
 
5048
 
 
5049
    info->bmiHeader.biHeight   = -8;
 
5050
    info->bmiHeader.biBitCount = 8;
 
5051
    info->bmiHeader.biClrUsed  = 137;
 
5052
    for (i = 0; i < 256; i++)
 
5053
    {
 
5054
        info->bmiColors[i].rgbRed      = 255 - i;
 
5055
        info->bmiColors[i].rgbGreen    = i * 2;
 
5056
        info->bmiColors[i].rgbBlue     = i;
 
5057
        info->bmiColors[i].rgbReserved = 0;
 
5058
    }
 
5059
    for (i = 0; i < 64; i++) ((BYTE *)data)[i] = i * 4 + 1;
 
5060
    ret = SetDIBitsToDevice( hdc, 0, 0, 8, 8, 0, 0, 0, 8, data, info, DIB_RGB_COLORS );
 
5061
    ok( ret == 8, "got %d\n", ret );
 
5062
    for (i = 0; i < 64; i++)
 
5063
    {
 
5064
        int idx = i * 4 + 1;
 
5065
        DWORD expect = idx >= info->bmiHeader.biClrUsed ? 0 : (info->bmiColors[idx].rgbRed << 16 |
 
5066
                                                               info->bmiColors[idx].rgbGreen << 8 |
 
5067
                                                               info->bmiColors[idx].rgbBlue);
 
5068
        ok( dib_bits[i] == expect, "%d: got %08x instead of %08x\n", i, dib_bits[i], expect );
 
5069
    }
 
5070
    memset( dib_bits, 0xaa, 64 * 4 );
 
5071
 
 
5072
    /* handling of DIB_PAL_COLORS */
 
5073
 
 
5074
    pal->palVersion = 0x300;
 
5075
    pal->palNumEntries = 137;
 
5076
    info->bmiHeader.biClrUsed = 221;
 
5077
    for (i = 0; i < 256; i++)
 
5078
    {
 
5079
        palent[i].peRed   = i * 2;
 
5080
        palent[i].peGreen = 255 - i;
 
5081
        palent[i].peBlue  = i;
 
5082
    }
 
5083
    palette = CreatePalette( pal );
 
5084
    ok( palette != 0, "palette creation failed\n" );
 
5085
    SelectPalette( hdc, palette, FALSE );
 
5086
    for (i = 0; i < 256; i++) ((WORD *)info->bmiColors)[i] = 255 - i;
 
5087
    ret = SetDIBitsToDevice( hdc, 0, 0, 8, 8, 0, 0, 0, 8, data, info, DIB_PAL_COLORS );
 
5088
    ok( ret == 8, "got %d\n", ret );
 
5089
    for (i = 0; i < 64; i++)
 
5090
    {
 
5091
        int idx = i * 4 + 1;
 
5092
        int ent = (255 - idx) % pal->palNumEntries;
 
5093
        DWORD expect = idx >= info->bmiHeader.biClrUsed ? 0 :
 
5094
                        (palent[ent].peRed << 16 | palent[ent].peGreen << 8 | palent[ent].peBlue);
 
5095
        ok( dib_bits[i] == expect || broken(dib_bits[i] == 0),
 
5096
            "%d: got %08x instead of %08x\n", i, dib_bits[i], expect );
 
5097
    }
 
5098
    memset( dib_bits, 0xaa, 64 * 4 );
 
5099
 
4536
5100
    DeleteDC( hdc );
4537
5101
    DeleteObject( dib );
 
5102
    DeleteObject( palette );
 
5103
    HeapFree( GetProcessHeap(), 0, info );
4538
5104
}
4539
5105
 
4540
5106
static void test_SetDIBitsToDevice_RLE8(void)
4541
5107
{
4542
 
    char bmi_buf[ FIELD_OFFSET( BITMAPINFO, bmiColors[256] ) ];
4543
 
    BITMAPINFO *info = (BITMAPINFO *)bmi_buf;
 
5108
    BITMAPINFO *info;
4544
5109
    DWORD *dib_bits;
4545
5110
    HDC hdc = CreateCompatibleDC( 0 );
4546
5111
    BYTE rle8_data[20] = { 0x04, 0x02, 0x03, 0xf0, 0x00, 0x00,     /* 2, 2, 2, 2, f0, f0, f0, <eol> */
4566
5131
                            0x00040404, 0x00050505, 0x00060606, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa,
4567
5132
                            0x00020202, 0x00020202, 0x00020202, 0x00020202, 0x00f0f0f0, 0x00f0f0f0, 0x00f0f0f0, 0xaaaaaaaa };
4568
5133
 
4569
 
    memset( info, 0, sizeof(bmi_buf) );
 
5134
    info = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, FIELD_OFFSET( BITMAPINFO, bmiColors[256] ) );
4570
5135
 
4571
5136
    info->bmiHeader.biSize        = sizeof(info->bmiHeader);
4572
5137
    info->bmiHeader.biWidth       = 8;
4756
5321
 
4757
5322
    DeleteDC( hdc );
4758
5323
    DeleteObject( dib );
 
5324
    HeapFree( GetProcessHeap(), 0, info );
4759
5325
}
4760
5326
 
4761
5327
START_TEST(bitmap)
4763
5329
    HMODULE hdll;
4764
5330
 
4765
5331
    hdll = GetModuleHandle("gdi32.dll");
4766
 
    pGdiAlphaBlend = (void*)GetProcAddress(hdll, "GdiAlphaBlend");
4767
 
    pSetLayout     = (void*)GetProcAddress(hdll, "SetLayout");
 
5332
    pGdiAlphaBlend   = (void*)GetProcAddress(hdll, "GdiAlphaBlend");
 
5333
    pGdiGradientFill = (void*)GetProcAddress(hdll, "GdiGradientFill");
 
5334
    pSetLayout       = (void*)GetProcAddress(hdll, "SetLayout");
4768
5335
 
4769
5336
    test_createdibitmap();
4770
5337
    test_dibsections();
4785
5352
    test_StretchBlt();
4786
5353
    test_StretchDIBits();
4787
5354
    test_GdiAlphaBlend();
4788
 
    test_32bit_bitmap_blt();
 
5355
    test_GdiGradientFill();
 
5356
    test_32bit_ddb();
4789
5357
    test_bitmapinfoheadersize();
4790
5358
    test_get16dibits();
4791
5359
    test_clipping();