int TestGdiLine(int argc, char* argv[]) { int rc = -1; UINT32 x, i; gdiPalette g; const UINT32 RawFormat = PIXEL_FORMAT_RGB8; const UINT32 colorFormats[] = { PIXEL_FORMAT_RGB15, PIXEL_FORMAT_ARGB15, PIXEL_FORMAT_RGB16, PIXEL_FORMAT_RGB24, PIXEL_FORMAT_ARGB32, PIXEL_FORMAT_XRGB32, PIXEL_FORMAT_RGBA32, PIXEL_FORMAT_RGBX32, PIXEL_FORMAT_BGR15, PIXEL_FORMAT_ABGR15, PIXEL_FORMAT_BGR16, PIXEL_FORMAT_BGR24, PIXEL_FORMAT_ABGR32, PIXEL_FORMAT_XBGR32, PIXEL_FORMAT_BGRA32, PIXEL_FORMAT_BGRX32 }; const UINT32 number_formats = sizeof(colorFormats) / sizeof(colorFormats[0]); for (i = 0; i < number_formats; i++) { HGDI_DC hdc = NULL; HGDI_PEN pen = NULL; HGDI_BITMAP hBmp = NULL; struct ropMap rop_map[] = { {GDI_R2_BLACK, NULL, line_to_R2_BLACK}, {GDI_R2_NOTMERGEPEN, NULL, line_to_R2_NOTMERGEPEN}, {GDI_R2_MASKNOTPEN, NULL, line_to_R2_MASKNOTPEN}, {GDI_R2_NOTCOPYPEN, NULL, line_to_R2_NOTCOPYPEN}, {GDI_R2_MASKPENNOT, NULL, line_to_R2_MASKPENNOT}, {GDI_R2_NOT, NULL, line_to_R2_NOT}, {GDI_R2_XORPEN, NULL, line_to_R2_XORPEN}, {GDI_R2_NOTMASKPEN, NULL, line_to_R2_NOTMASKPEN}, {GDI_R2_MASKPEN, NULL, line_to_R2_MASKPEN}, {GDI_R2_NOTXORPEN, NULL, line_to_R2_NOTXORPEN}, {GDI_R2_NOP, NULL, line_to_R2_NOP}, {GDI_R2_MERGENOTPEN, NULL, line_to_R2_MERGENOTPEN}, {GDI_R2_COPYPEN, NULL, line_to_R2_COPYPEN}, {GDI_R2_MERGEPENNOT, NULL, line_to_R2_MERGEPENNOT}, {GDI_R2_MERGEPEN, NULL, line_to_R2_MERGEPEN}, {GDI_R2_WHITE, NULL, line_to_R2_WHITE} }; const UINT32 map_size = sizeof(rop_map) / sizeof(rop_map[0]); HGDI_BITMAP hBmp_LineTo[LINTETO_NUMBER] = {NULL}; gdiPalette* hPalette = &g; UINT32 penColor; const UINT32 format = colorFormats[i]; g.format = format; for (i = 0; i < 256; i++) g.palette[i] = GetColor(format, i, i, i, 0xFF); rc = -1; if (!(hdc = gdi_GetDC())) { printf("failed to get gdi device context\n"); goto fail; } hdc->format = format; gdi_SetNullClipRgn(hdc); penColor = GetColor(format, 0xFF, 0xFF, 0xFF, 0xFF); if (!(pen = gdi_CreatePen(1, 1, penColor, format, hPalette))) { printf("gdi_CreatePen failed\n"); goto fail; } gdi_SelectObject(hdc, (HGDIOBJECT) pen); hBmp = gdi_CreateCompatibleBitmap(hdc, 16, 16); gdi_SelectObject(hdc, (HGDIOBJECT) hBmp); for (x = 0; x < LINTETO_NUMBER; x++) { hBmp_LineTo[x] = test_convert_to_bitmap(line_to_case[x], RawFormat, 0, 0, 0, format, 0, 0, 0, 16, 16, hPalette); if (!hBmp_LineTo[x]) goto fail; } for (x = 0; x < map_size; x++) { rop_map[x].bmp = test_convert_to_bitmap(rop_map[x].src, RawFormat, 0, 0, 0, format, 0, 0, 0, 16, 16, hPalette); if (!rop_map[x].bmp) goto fail; } if (!test_line(hdc, hPalette, 0, 0, 15, 15, hBmp, hBmp_LineTo[0], 0, 0, 16, 16)) goto fail; if (!test_line(hdc, hPalette, 15, 15, 0, 0, hBmp, hBmp_LineTo[1], 0, 0, 16, 16)) goto fail; if (!test_line(hdc, hPalette, 15, 0, 0, 15, hBmp, hBmp_LineTo[2], 0, 0, 16, 16)) goto fail; if (!test_line(hdc, hPalette, 0, 15, 15, 0, hBmp, hBmp_LineTo[3], 0, 0, 16, 16)) goto fail; if (!test_line(hdc, hPalette, 0, 8, 15, 8, hBmp, hBmp_LineTo[4], 0, 0, 16, 16)) goto fail; if (!test_line(hdc, hPalette, 15, 8, 0, 8, hBmp, hBmp_LineTo[5], 0, 0, 16, 16)) goto fail; if (!test_line(hdc, hPalette, 8, 0, 8, 15, hBmp, hBmp_LineTo[6], 0, 0, 16, 16)) goto fail; if (!test_line(hdc, hPalette, 8, 15, 8, 0, hBmp, hBmp_LineTo[7], 0, 0, 16, 16)) goto fail; if (!test_line(hdc, hPalette, 4, 4, 12, 12, hBmp, hBmp_LineTo[8], 0, 0, 16, 16)) goto fail; if (!test_line(hdc, hPalette, 0, 0, 16, 16, hBmp, hBmp_LineTo[9], 5, 5, 8, 8)) goto fail; if (!test_line(hdc, hPalette, 0, 0, 26, 26, hBmp, hBmp_LineTo[10], 0, 0, 16, 16)) goto fail; for (x = 0; x < map_size; x++) { char name[1024]; _snprintf(name, sizeof(name), "%s [%s]", gdi_rop_to_string(rop_map[x].rop), GetColorFormatName(hdc->format)); /* Test Case 13: (0,0) -> (16,16), R2_NOTMERGEPEN */ if (!gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS, hPalette)) { printf("gdi_BitBlt failed (line #%u)\n", __LINE__); goto fail; } gdi_SetClipRgn(hdc, 0, 0, 16, 16); gdi_MoveToEx(hdc, 0, 0, NULL); gdi_SetROP2(hdc, rop_map[x].rop); gdi_LineTo(hdc, 16, 16); if (!test_assert_bitmaps_equal(hBmp, rop_map[x].bmp, name, hPalette)) goto fail; } rc = 0; fail: for (x = 0; x < LINTETO_NUMBER; x++) gdi_DeleteObject((HGDIOBJECT) hBmp_LineTo[x]); for (x = 0; x < map_size; x++) gdi_DeleteObject((HGDIOBJECT) rop_map[x].bmp); gdi_DeleteObject((HGDIOBJECT) pen); gdi_DeleteDC(hdc); if (rc != 0) break; } return rc; }
/** * Perform a bit blit operation on the given pixel buffers.\n * @msdn{dd183370} * @param hdcDest destination device context * @param nXDest destination x1 * @param nYDest destination y1 * @param nWidth width * @param nHeight height * @param hdcSrc source device context * @param nXSrc source x1 * @param nYSrc source y1 * @param rop raster operation code * @return 0 on failure, non-zero otherwise */ BOOL gdi_BitBlt(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest, UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc, UINT32 nXSrc, UINT32 nYSrc, DWORD rop, const gdiPalette* palette) { HGDI_BITMAP hSrcBmp, hDstBmp; if (!hdcDest) return FALSE; if (!gdi_ClipCoords(hdcDest, &nXDest, &nYDest, &nWidth, &nHeight, &nXSrc, &nYSrc)) return TRUE; /* Check which ROP should be performed. * Some specific ROP are used heavily and are resource intensive, * add optimized versions for these here. * * For all others fall back to the generic implementation. */ switch (rop) { case GDI_SRCCOPY: if (!hdcSrc) return FALSE; hSrcBmp = (HGDI_BITMAP) hdcSrc->selectedObject; hDstBmp = (HGDI_BITMAP) hdcDest->selectedObject; if (!hSrcBmp || !hDstBmp) return FALSE; if (!freerdp_image_copy(hDstBmp->data, hDstBmp->format, hDstBmp->scanline, nXDest, nYDest, nWidth, nHeight, hSrcBmp->data, hSrcBmp->format, hSrcBmp->scanline, nXSrc, nYSrc, palette, FREERDP_FLIP_NONE)) return FALSE; break; case GDI_DSTCOPY: hSrcBmp = (HGDI_BITMAP) hdcDest->selectedObject; hDstBmp = (HGDI_BITMAP) hdcDest->selectedObject; if (!hSrcBmp || !hDstBmp) return FALSE; if (!freerdp_image_copy(hDstBmp->data, hDstBmp->format, hDstBmp->scanline, nXDest, nYDest, nWidth, nHeight, hSrcBmp->data, hSrcBmp->format, hSrcBmp->scanline, nXSrc, nYSrc, palette, FREERDP_FLIP_NONE)) return FALSE; break; default: if (!BitBlt_process(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc, gdi_rop_to_string(rop), palette)) return FALSE; break; } if (!gdi_InvalidateRegion(hdcDest, nXDest, nYDest, nWidth, nHeight)) return FALSE; return TRUE; }