static GF_Err gdip_attach_surface_to_buffer(GF_SURFACE _this, char *pixels, u32 width, u32 height, s32 pitch_x, s32 pitch_y, GF_PixelFormat pixelFormat) { GpMatrix *mat; u32 pFormat; GPGRAPH(); if (pitch_y%4) return GF_NOT_SUPPORTED; switch (pixelFormat) { case GF_PIXEL_ALPHAGREY: pFormat = PixelFormat16bppGrayScale; if (pitch_x != 2) return GF_NOT_SUPPORTED; break; case GF_PIXEL_RGB_555: pFormat = PixelFormat16bppRGB555; if (pitch_x != 2) return GF_NOT_SUPPORTED; break; case GF_PIXEL_RGB_565: pFormat = PixelFormat16bppRGB565; if (pitch_x != 2) return GF_NOT_SUPPORTED; break; case GF_PIXEL_RGB_24: pFormat = PixelFormat24bppRGB; if (pitch_x != 3) return GF_NOT_SUPPORTED; break; case GF_PIXEL_RGB_32: pFormat = PixelFormat32bppRGB; if (pitch_x != 4) return GF_NOT_SUPPORTED; break; case GF_PIXEL_ARGB: pFormat = PixelFormat32bppARGB; if (pitch_x != 4) return GF_NOT_SUPPORTED; break; default: return GF_NOT_SUPPORTED; } GdipCreateBitmapFromScan0(width, height, pitch_y, pFormat, (unsigned char*)pixels, &_graph->pBitmap); GdipGetImageGraphicsContext(_graph->pBitmap, &_graph->graph); _graph->w = width; _graph->h = height; if (_graph->center_coords) { GdipCreateMatrix(&mat); GdipScaleMatrix(mat, 1.0, -1.0, MatrixOrderAppend); GdipTranslateMatrix(mat, (Float) width/2, (Float) height/2, MatrixOrderAppend); GdipSetWorldTransform(_graph->graph, mat); GdipDeleteMatrix(mat); } GdipSetPixelOffsetMode(_graph->graph, GDIP_PIXEL_MODE); return GF_OK; }
static void test_empty(void) { GpStatus stat; GpMetafile *metafile; GpGraphics *graphics; HDC hdc; HENHMETAFILE hemf, dummy; BOOL ret; static const GpRectF frame = {0.0, 0.0, 100.0, 100.0}; static const WCHAR description[] = {'w','i','n','e','t','e','s','t',0}; hdc = CreateCompatibleDC(0); stat = GdipRecordMetafile(hdc, EmfTypeEmfPlusOnly, &frame, MetafileFrameUnitPixel, description, &metafile); todo_wine expect(Ok, stat); DeleteDC(hdc); if (stat != Ok) return; stat = GdipGetHemfFromMetafile(metafile, &hemf); expect(InvalidParameter, stat); stat = GdipGetImageGraphicsContext((GpImage*)metafile, &graphics); expect(Ok, stat); stat = GdipGetHemfFromMetafile(metafile, &hemf); expect(InvalidParameter, stat); stat = GdipDeleteGraphics(graphics); expect(Ok, stat); stat = GdipGetHemfFromMetafile(metafile, &hemf); expect(Ok, stat); stat = GdipGetHemfFromMetafile(metafile, &dummy); expect(InvalidParameter, stat); stat = GdipDisposeImage((GpImage*)metafile); expect(Ok, stat); check_emfplus(hemf, empty_records, "empty"); ret = DeleteEnhMetaFile(hemf); ok(ret != 0, "Failed to delete enhmetafile %p\n", hemf); }
static GF_Err gdip_attach_surface_to_texture(GF_SURFACE _this, GF_STENCIL sten) { GpMatrix *mat; struct _stencil *_sten = (struct _stencil *)sten; GPGRAPH(); if (!_graph || !_sten || !_sten->pBitmap) return GF_BAD_PARAM; GdipGetImageGraphicsContext(_sten->pBitmap, &_graph->graph); if (_graph->center_coords) { GdipCreateMatrix(&mat); GdipScaleMatrix(mat, 1.0, -1.0, MatrixOrderAppend); GdipTranslateMatrix(mat, (Float) _sten->width/2, (Float) _sten->height/2, MatrixOrderAppend); GdipSetWorldTransform(_graph->graph, mat); GdipDeleteMatrix(mat); } _graph->w = _sten->width; _graph->h = _sten->height; GdipSetPixelOffsetMode(_graph->graph, GDIP_PIXEL_MODE); return GF_OK; }
static void test_emfonly(void) { GpStatus stat; GpMetafile *metafile; GpGraphics *graphics; HDC hdc, metafile_dc; HENHMETAFILE hemf; BOOL ret; static const GpRectF frame = {0.0, 0.0, 100.0, 100.0}; static const GpPointF dst_points[3] = {{0.0,0.0},{100.0,0.0},{0.0,100.0}}; static const WCHAR description[] = {'w','i','n','e','t','e','s','t',0}; HBRUSH hbrush, holdbrush; GpBitmap *bitmap; ARGB color; hdc = CreateCompatibleDC(0); stat = GdipRecordMetafile(hdc, EmfTypeEmfOnly, &frame, MetafileFrameUnitPixel, description, &metafile); expect(Ok, stat); DeleteDC(hdc); if (stat != Ok) return; stat = GdipGetHemfFromMetafile(metafile, &hemf); expect(InvalidParameter, stat); stat = GdipGetImageGraphicsContext((GpImage*)metafile, &graphics); expect(Ok, stat); stat = GdipGetDC(graphics, &metafile_dc); expect(Ok, stat); if (stat != Ok) { GdipDeleteGraphics(graphics); GdipDisposeImage((GpImage*)metafile); return; } hbrush = CreateSolidBrush(0xff0000); holdbrush = SelectObject(metafile_dc, hbrush); Rectangle(metafile_dc, 25, 25, 75, 75); SelectObject(metafile_dc, holdbrush); DeleteObject(hbrush); stat = GdipReleaseDC(graphics, metafile_dc); expect(Ok, stat); stat = GdipDeleteGraphics(graphics); expect(Ok, stat); check_metafile(metafile, emfonly_records, "emfonly metafile", dst_points, &frame, UnitPixel); stat = GdipCreateBitmapFromScan0(100, 100, 0, PixelFormat32bppARGB, NULL, &bitmap); expect(Ok, stat); stat = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics); expect(Ok, stat); play_metafile(metafile, graphics, emfonly_records, "emfonly playback", dst_points, &frame, UnitPixel); stat = GdipBitmapGetPixel(bitmap, 15, 15, &color); expect(Ok, stat); expect(0, color); stat = GdipBitmapGetPixel(bitmap, 50, 50, &color); expect(Ok, stat); expect(0xff0000ff, color); stat = GdipDeleteGraphics(graphics); expect(Ok, stat); stat = GdipDisposeImage((GpImage*)bitmap); expect(Ok, stat); stat = GdipGetHemfFromMetafile(metafile, &hemf); expect(Ok, stat); stat = GdipDisposeImage((GpImage*)metafile); expect(Ok, stat); check_emfplus(hemf, emfonly_records, "emfonly emf"); ret = DeleteEnhMetaFile(hemf); ok(ret != 0, "Failed to delete enhmetafile %p\n", hemf); }
static void test_getdc(void) { GpStatus stat; GpMetafile *metafile; GpGraphics *graphics; HDC hdc, metafile_dc; HENHMETAFILE hemf; BOOL ret; static const GpRectF frame = {0.0, 0.0, 100.0, 100.0}; static const GpPointF dst_points[3] = {{0.0,0.0},{100.0,0.0},{0.0,100.0}}; static const WCHAR description[] = {'w','i','n','e','t','e','s','t',0}; HBRUSH hbrush, holdbrush; hdc = CreateCompatibleDC(0); stat = GdipRecordMetafile(hdc, EmfTypeEmfPlusOnly, &frame, MetafileFrameUnitPixel, description, &metafile); expect(Ok, stat); DeleteDC(hdc); if (stat != Ok) return; stat = GdipGetHemfFromMetafile(metafile, &hemf); expect(InvalidParameter, stat); stat = GdipGetImageGraphicsContext((GpImage*)metafile, &graphics); expect(Ok, stat); stat = GdipGetDC(graphics, &metafile_dc); expect(Ok, stat); if (stat != Ok) { GdipDeleteGraphics(graphics); GdipDisposeImage((GpImage*)metafile); return; } hbrush = CreateSolidBrush(0xff0000); holdbrush = SelectObject(metafile_dc, hbrush); Rectangle(metafile_dc, 25, 25, 75, 75); SelectObject(metafile_dc, holdbrush); DeleteObject(hbrush); stat = GdipReleaseDC(graphics, metafile_dc); expect(Ok, stat); stat = GdipDeleteGraphics(graphics); expect(Ok, stat); check_metafile(metafile, getdc_records, "getdc metafile", dst_points, &frame, UnitPixel); stat = GdipGetHemfFromMetafile(metafile, &hemf); expect(Ok, stat); stat = GdipDisposeImage((GpImage*)metafile); expect(Ok, stat); check_emfplus(hemf, getdc_records, "getdc emf"); ret = DeleteEnhMetaFile(hemf); ok(ret != 0, "Failed to delete enhmetafile %p\n", hemf); }