static void test_pathgradientcenterpoint(void) { static const GpPointF path_points[] = {{0,0}, {3,0}, {0,4}}; GpStatus status; GpPathGradient *grad; GpPointF point; status = GdipCreatePathGradient(path_points+1, 2, WrapModeClamp, &grad); expect(Ok, status); status = GdipGetPathGradientCenterPoint(NULL, &point); expect(InvalidParameter, status); status = GdipGetPathGradientCenterPoint(grad, NULL); expect(InvalidParameter, status); status = GdipGetPathGradientCenterPoint(grad, &point); expect(Ok, status); expectf(1.5, point.X); expectf(2.0, point.Y); status = GdipSetPathGradientCenterPoint(NULL, &point); expect(InvalidParameter, status); status = GdipSetPathGradientCenterPoint(grad, NULL); expect(InvalidParameter, status); point.X = 10.0; point.Y = 15.0; status = GdipSetPathGradientCenterPoint(grad, &point); expect(Ok, status); point.X = point.Y = -1; status = GdipGetPathGradientCenterPoint(grad, &point); expect(Ok, status); expectf(10.0, point.X); expectf(15.0, point.Y); status = GdipDeleteBrush((GpBrush*)grad); expect(Ok, status); status = GdipCreatePathGradient(path_points, 3, WrapModeClamp, &grad); expect(Ok, status); status = GdipGetPathGradientCenterPoint(grad, &point); expect(Ok, status); todo_wine expectf(1.0, point.X); todo_wine expectf(4.0/3.0, point.Y); status = GdipDeleteBrush((GpBrush*)grad); expect(Ok, status); }
static void test_penfilltype(void) { GpPen *pen; GpSolidFill *solid; GpLineGradient *line; GpPointF a, b; GpStatus status; GpPenType type; /* NULL */ status = GdipGetPenFillType(NULL, NULL); expect(InvalidParameter, status); status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen); expect(Ok, status); status = GdipGetPenFillType(pen, NULL); expect(InvalidParameter, status); /* created with GdipCreatePen1() */ status = GdipGetPenFillType(pen, &type); expect(Ok, status); expect(PenTypeSolidColor, type); GdipDeletePen(pen); /* based on SolidBrush */ status = GdipCreateSolidFill((ARGB)0xffff00ff, &solid); expect(Ok, status); status = GdipCreatePen2((GpBrush*)solid, 10.0f, UnitPixel, &pen); expect(Ok, status); status = GdipGetPenFillType(pen, &type); expect(Ok, status); expect(PenTypeSolidColor, type); GdipDeletePen(pen); GdipDeleteBrush((GpBrush*)solid); /* based on LinearGradientBrush */ a.X = a.Y = 0.0; b.X = b.Y = 10.0; status = GdipCreateLineBrush(&a, &b, (ARGB)0xffff00ff, (ARGB)0xffff0000, WrapModeTile, &line); expect(Ok, status); status = GdipCreatePen2((GpBrush*)line, 10.0f, UnitPixel, &pen); expect(Ok, status); status = GdipGetPenFillType(pen, &type); expect(Ok, status); expect(PenTypeLinearGradient, type); GdipDeletePen(pen); GdipDeleteBrush((GpBrush*)line); }
static void test_constructor_destructor(void) { GpStatus status; GpSolidFill *brush = NULL; status = GdipCreateSolidFill((ARGB)0xdeadbeef, &brush); expect(Ok, status); ok(brush != NULL, "Expected brush to be initialized\n"); status = GdipDeleteBrush(NULL); expect(InvalidParameter, status); status = GdipDeleteBrush((GpBrush*) brush); expect(Ok, status); }
static void test_pathgradientpath(void) { GpStatus status; GpPath *path=NULL; GpPathGradient *grad=NULL; status = GdipCreatePathGradient(blendcount_ptf, 2, WrapModeClamp, &grad); expect(Ok, status); status = GdipGetPathGradientPath(grad, NULL); expect(NotImplemented, status); status = GdipCreatePath(FillModeWinding, &path); expect(Ok, status); status = GdipGetPathGradientPath(NULL, path); expect(NotImplemented, status); status = GdipGetPathGradientPath(grad, path); expect(NotImplemented, status); status = GdipDeletePath(path); expect(Ok, status); status = GdipDeleteBrush((GpBrush*)grad); expect(Ok, status); }
static void test_getbounds(void) { GpStatus status; GpPathGradient *brush; GpRectF bounds; status = GdipCreatePathGradient(getbounds_ptf, 4, WrapModeClamp, &brush); expect(Ok, status); status = GdipGetPathGradientRect(NULL, NULL); expect(InvalidParameter, status); status = GdipGetPathGradientRect(brush, NULL); expect(InvalidParameter, status); status = GdipGetPathGradientRect(NULL, &bounds); expect(InvalidParameter, status); status = GdipGetPathGradientRect(brush, &bounds); expect(Ok, status); expectf(0.0, bounds.X); expectf(20.0, bounds.Y); expectf(50.0, bounds.Width); expectf(30.0, bounds.Height); GdipDeleteBrush((GpBrush*) brush); }
static void test_constructor_destructor2(void) { GpStatus status; GpPen *pen = NULL; GpBrush *brush = NULL; GpPointF points[2]; status = GdipCreatePen2(NULL, 10.0f, UnitPixel, &pen); expect(InvalidParameter, status); ok(pen == NULL, "Expected pen to be NULL\n"); points[0].X = 7.0; points[0].Y = 11.0; points[1].X = 13.0; points[1].Y = 17.0; status = GdipCreateLineBrush(&points[0], &points[1], (ARGB)0xffff00ff, (ARGB)0xff0000ff, WrapModeTile, (GpLineGradient **)&brush); expect(Ok, status); ok(brush != NULL, "Expected brush to be initialized\n"); status = GdipCreatePen2(brush, 10.0f, UnitPixel, &pen); expect(Ok, status); ok(pen != NULL, "Expected pen to be initialized\n"); status = GdipDeletePen(pen); expect(Ok, status); status = GdipDeleteBrush(brush); expect(Ok, status); }
static void test_getblend(void) { GpStatus status; GpPathGradient *brush; REAL blends[4]; REAL pos[4]; status = GdipCreatePathGradient(getblend_ptf, 2, WrapModeClamp, &brush); expect(Ok, status); /* check some invalid parameters combinations */ status = GdipGetPathGradientBlend(NULL, NULL, NULL, -1); expect(InvalidParameter, status); status = GdipGetPathGradientBlend(brush,NULL, NULL, -1); expect(InvalidParameter, status); status = GdipGetPathGradientBlend(NULL, blends,NULL, -1); expect(InvalidParameter, status); status = GdipGetPathGradientBlend(NULL, NULL, pos, -1); expect(InvalidParameter, status); status = GdipGetPathGradientBlend(NULL, NULL, NULL, 1); expect(InvalidParameter, status); blends[0] = (REAL)0xdeadbeef; pos[0] = (REAL)0xdeadbeef; status = GdipGetPathGradientBlend(brush, blends, pos, 1); expect(Ok, status); expectf(1.0, blends[0]); expectf((REAL)0xdeadbeef, pos[0]); GdipDeleteBrush((GpBrush*) brush); }
static GpStatus gdip_texture_create_from_cloned_image (GpImage *image, GpWrapMode wrapMode, GpTexture **texture) { GpTexture *result; cairo_surface_t *imageSurface = NULL; result = gdip_texture_new (); if (!result) return OutOfMemory; result->image = image; /* note: we must keep the scan0 alive, so we must use the cloned image (and not the original) see bug #80971 */ imageSurface = cairo_image_surface_create_for_data ((BYTE*)result->image->active_bitmap->scan0, result->image->cairo_format, result->image->active_bitmap->width, result->image->active_bitmap->height, result->image->active_bitmap->stride); if (!imageSurface) { GdipDeleteBrush ((GpBrush *) result); return OutOfMemory; } result->wrapMode = wrapMode; if (result->image->surface) cairo_surface_destroy (result->image->surface); result->image->surface = imageSurface; result->rectangle.X = 0; result->rectangle.Y = 0; result->rectangle.Width = result->image->active_bitmap->width; result->rectangle.Height = result->image->active_bitmap->height; *texture = result; return Ok; }
void gdip_recompute_line_gradient(GF_STENCIL _this) { GpPointF start, end; u32 i, k; REAL w, h; GPSTEN(); if (!_sten->needs_rebuild) return; _sten->needs_rebuild = GF_FALSE; if (_sten->pLinear) GdipDeleteBrush(_sten->pLinear); GdipCreateLineBrush(&_sten->start, &_sten->end, 0xFFFF0000, 0xFFFF00FF, WrapModeTile, &_sten->pLinear); switch (_sten->spread) { case GF_GRADIENT_MODE_PAD: break; case GF_GRADIENT_MODE_SPREAD: GdipSetLineWrapMode(_sten->pLinear, WrapModeTileFlipXY); GdipSetLinePresetBlend(_sten->pLinear, (ARGB *) _sten->cols, _sten->pos, _sten->num_pos); return; case GF_GRADIENT_MODE_REPEAT: GdipSetLineWrapMode(_sten->pLinear, WrapModeTile); GdipSetLinePresetBlend(_sten->pLinear, (ARGB *) _sten->cols, _sten->pos, _sten->num_pos); return; } /*currently gdiplus doesn't support padded mode on gradients, so update the line gradient by using a line 3 times longer*/ w = _sten->end.X - _sten->start.X; h = _sten->end.Y - _sten->start.Y; start.X = _sten->start.X - w; start.Y = _sten->start.Y - h; end.X = _sten->end.X + w; end.Y = _sten->end.Y + h; GdipCreateLineBrush(&start, &end, 0xFFFF0000, 0xFFFF00FF, WrapModeTile, &_sten->pLinear); ARGB *cols = new ARGB[_sten->num_pos+2]; REAL *pos = new REAL[_sten->num_pos+2]; k=0; for (i=0; i<_sten->num_pos; i++) { cols[i+k] = _sten->cols[i]; pos[i+k] = (1 + _sten->pos[i])/3; if (!i) { pos[1] = pos[0]; cols[1] = cols[0]; k=1; pos[0] = 0; } } pos[_sten->num_pos+1] = 1.0; cols[_sten->num_pos+1] = cols[_sten->num_pos]; /*since depending on gradient transform the padding is likely to be not big enough, use flipXY to assure that in most cases the x3 dilatation is enough*/ GdipSetLineWrapMode(_sten->pLinear, WrapModeTileFlipXY); GdipSetLinePresetBlend(_sten->pLinear, cols, pos, 2+_sten->num_pos); delete [] cols; delete [] pos; }
GpStatus WINGDIPAPI GdipSetPenBrushFill(GpPen *pen, GpBrush *brush) { TRACE("(%p, %p)\n", pen, brush); if(!pen || !brush) return InvalidParameter; GdipDeleteBrush(pen->brush); return GdipCloneBrush(brush, &pen->brush); }
static void gdip_delete_stencil(GF_STENCIL _this) { GPSTEN(); if (_sten->pSolid) GdipDeleteBrush(_sten->pSolid); if (_sten->pTexture) GdipDeleteBrush(_sten->pTexture); if (_sten->pLinear) GdipDeleteBrush(_sten->pLinear); if (_sten->pRadial) GdipDeleteBrush(_sten->pRadial); if (_sten->circle) GdipDeletePath(_sten->circle); if (_sten->pMat) GdipDeleteMatrix(_sten->pMat); if (_sten->pLinearMat) GdipDeleteMatrix(_sten->pLinearMat); if (_sten->pBitmap) GdipDisposeImage(_sten->pBitmap); if (_sten->conv_buf) gf_free(_sten->conv_buf); if (_sten->cols) delete [] _sten->cols; if (_sten->pos) delete [] _sten->pos; gf_free(_sten); }
static void test_brushfill(void) { GpStatus status; GpPen *pen; GpBrush *brush, *brush2; GpBrushType type; ARGB color = 0; /* default solid */ GdipCreatePen1(0xdeadbeef, 4.5, UnitWorld, &pen); status = GdipGetPenBrushFill(pen, &brush); expect(Ok, status); GdipGetBrushType(brush, &type); expect(BrushTypeSolidColor, type); GdipGetPenColor(pen, &color); expect(0xdeadbeef, color); GdipDeleteBrush(brush); /* color controlled by brush */ GdipCreateSolidFill(0xabaddeed, (GpSolidFill**)&brush); status = GdipSetPenBrushFill(pen, brush); expect(Ok, status); GdipGetPenColor(pen, &color); expect(0xabaddeed, color); GdipDeleteBrush(brush); color = 0; /* get returns a clone, not a reference */ GdipGetPenBrushFill(pen, &brush); GdipSetSolidFillColor((GpSolidFill*)brush, 0xbeadfeed); GdipGetPenBrushFill(pen, &brush2); ok(brush != brush2, "Expected to get a clone, not a copy of the reference\n"); GdipGetSolidFillColor((GpSolidFill*)brush2, &color); expect(0xabaddeed, color); GdipDeleteBrush(brush); GdipDeleteBrush(brush2); /* brush cannot be NULL */ status = GdipSetPenBrushFill(pen, NULL); expect(InvalidParameter, status); GdipDeletePen(pen); }
static void test_gradientsurroundcolorcount(void) { GpStatus status; GpPathGradient *grad; ARGB *color; INT count = 3; status = GdipCreatePathGradient(blendcount_ptf, 2, WrapModeClamp, &grad); expect(Ok, status); color = GdipAlloc(sizeof(ARGB[3])); status = GdipSetPathGradientSurroundColorsWithCount(grad, color, &count); expect(InvalidParameter, status); GdipFree(color); count = 2; color = GdipAlloc(sizeof(ARGB[2])); color[0] = 0x00ff0000; color[1] = 0x0000ff00; status = GdipSetPathGradientSurroundColorsWithCount(NULL, color, &count); expect(InvalidParameter, status); status = GdipSetPathGradientSurroundColorsWithCount(grad, NULL, &count); expect(InvalidParameter, status); /* WinXP crashes on this test */ if(0) { status = GdipSetPathGradientSurroundColorsWithCount(grad, color, NULL); expect(InvalidParameter, status); } status = GdipSetPathGradientSurroundColorsWithCount(grad, color, &count); todo_wine expect(Ok, status); expect(2, count); status = GdipGetPathGradientSurroundColorCount(NULL, &count); expect(InvalidParameter, status); status = GdipGetPathGradientSurroundColorCount(grad, NULL); expect(InvalidParameter, status); count = 0; status = GdipGetPathGradientSurroundColorCount(grad, &count); todo_wine expect(Ok, status); todo_wine expect(2, count); GdipFree(color); GdipDeleteBrush((GpBrush*)grad); }
static GF_Err gdip_set_vertex_path(GF_STENCIL _this, GF_Path *path) { GPSTEN(); GpPath *p; CHECK_RET(GF_STENCIL_VERTEX_GRADIENT); p = gdip_create_path(path); if (_sten->pRadial) GdipDeleteBrush(_sten->pRadial); GdipCreatePathGradientFromPath(p, &_sten->pRadial); GdipDeletePath(p); return GF_OK; }
GpStatus WINGDIPAPI GdipCreatePen1(ARGB color, REAL width, GpUnit unit, GpPen **pen) { GpBrush *brush; GpStatus status; TRACE("(%x, %.2f, %d, %p)\n", color, width, unit, pen); GdipCreateSolidFill(color, (GpSolidFill **)(&brush)); status = GdipCreatePen2(brush, width, unit, pen); GdipDeleteBrush(brush); return status; }
static void test_type(void) { GpStatus status; GpBrushType bt; GpSolidFill *brush = NULL; GdipCreateSolidFill((ARGB)0xdeadbeef, &brush); status = GdipGetBrushType((GpBrush*)brush, &bt); expect(Ok, status); expect(BrushTypeSolidColor, bt); GdipDeleteBrush((GpBrush*) brush); }
GpStatus WINGDIPAPI GdipDeletePen(GpPen *pen) { TRACE("(%p)\n", pen); if(!pen) return InvalidParameter; GdipDeleteBrush(pen->brush); GdipDeleteCustomLineCap(pen->customstart); GdipDeleteCustomLineCap(pen->customend); heap_free(pen->dashes); heap_free(pen); return Ok; }
static void test_texturewrap(void) { GpStatus status; GpTexture *texture; GpGraphics *graphics = NULL; GpBitmap *bitmap; HDC hdc = GetDC(0); GpWrapMode wrap; status = GdipCreateFromHDC(hdc, &graphics); expect(Ok, status); status = GdipCreateBitmapFromGraphics(1, 1, graphics, &bitmap); expect(Ok, status); status = GdipCreateTexture((GpImage*)bitmap, WrapModeTile, &texture); expect(Ok, status); /* NULL */ status = GdipGetTextureWrapMode(NULL, NULL); expect(InvalidParameter, status); status = GdipGetTextureWrapMode(texture, NULL); expect(InvalidParameter, status); status = GdipGetTextureWrapMode(NULL, &wrap); expect(InvalidParameter, status); /* get */ wrap = WrapModeClamp; status = GdipGetTextureWrapMode(texture, &wrap); expect(Ok, status); expect(WrapModeTile, wrap); /* set, then get */ wrap = WrapModeClamp; status = GdipSetTextureWrapMode(texture, wrap); expect(Ok, status); wrap = WrapModeTile; status = GdipGetTextureWrapMode(texture, &wrap); expect(Ok, status); expect(WrapModeClamp, wrap); status = GdipDeleteBrush((GpBrush*)texture); expect(Ok, status); status = GdipDisposeImage((GpImage*)bitmap); expect(Ok, status); status = GdipDeleteGraphics(graphics); expect(Ok, status); ReleaseDC(0, hdc); }
static GF_Err gdip_set_linear_gradient (GF_STENCIL _this, Fixed start_x, Fixed start_y, Fixed end_x, Fixed end_y) { GPSTEN(); CHECK_RET(GF_STENCIL_LINEAR_GRADIENT); if (_sten->pLinear) GdipDeleteBrush(_sten->pLinear); _sten->start.X = FIX2FLT(start_x); _sten->start.Y = FIX2FLT(start_y); _sten->end.X = FIX2FLT(end_x); _sten->end.Y = FIX2FLT(end_y); GdipCreateLineBrush(&_sten->start, &_sten->end, 0xFF000000, 0xFFFFFFFF, WrapModeTile, &_sten->pLinear); if (!_sten->pLinearMat) GdipCreateMatrix(&_sten->pLinearMat); GdipGetLineTransform(_sten->pLinear, _sten->pLinearMat); _sten->needs_rebuild = GF_TRUE; return GF_OK; }
GpStatus gdip_texture_clone (GpBrush *brush, GpBrush **clonedBrush) { GpTexture *result; GpTexture *texture; GpStatus status; if (!brush || !clonedBrush) return InvalidParameter; result = gdip_texture_new (); if (!result) return OutOfMemory; texture = (GpTexture *) brush; result->base = texture->base; result->wrapMode = texture->wrapMode; /* Let the clone create its own pattern. */ result->pattern = NULL; result->base.changed = TRUE; gdip_cairo_matrix_copy (&result->matrix, &texture->matrix); result->rectangle.X = texture->rectangle.X; result->rectangle.Y = texture->rectangle.Y; result->rectangle.Width = texture->rectangle.Width; result->rectangle.Height = texture->rectangle.Height; result->image = NULL; status = GdipCloneImage (texture->image, &result->image); if (status != Ok) { GdipDeleteBrush ((GpBrush *) result); *clonedBrush = NULL; return status; } else { cairo_surface_reference (result->image->surface); } *clonedBrush = (GpBrush *) result; return status; }
static void test_gradientblendcount(void) { GpStatus status; GpPathGradient *brush; INT count; status = GdipCreatePathGradient(blendcount_ptf, 2, WrapModeClamp, &brush); expect(Ok, status); status = GdipGetPathGradientBlendCount(NULL, NULL); expect(InvalidParameter, status); status = GdipGetPathGradientBlendCount(NULL, &count); expect(InvalidParameter, status); status = GdipGetPathGradientBlendCount(brush, NULL); expect(InvalidParameter, status); status = GdipGetPathGradientBlendCount(brush, &count); expect(Ok, status); expect(1, count); GdipDeleteBrush((GpBrush*) brush); }
static void test_getgamma(void) { GpStatus status; GpLineGradient *line; GpPointF start, end; BOOL gamma; start.X = start.Y = 0.0; end.X = end.Y = 100.0; status = GdipCreateLineBrush(&start, &end, (ARGB)0xdeadbeef, 0xdeadbeef, WrapModeTile, &line); expect(Ok, status); /* NULL arguments */ status = GdipGetLineGammaCorrection(NULL, NULL); expect(InvalidParameter, status); status = GdipGetLineGammaCorrection(line, NULL); expect(InvalidParameter, status); status = GdipGetLineGammaCorrection(NULL, &gamma); expect(InvalidParameter, status); GdipDeleteBrush((GpBrush*)line); }
GpStatus WINGDIPAPI GdipSetPenBrushFill (GpPen *pen, GpBrush *brush) { GpBrushType type; if (!pen || !brush) return InvalidParameter; GdipGetBrushType (brush, &type); if (type == BrushTypeSolidColor) GdipGetSolidFillColor ((GpSolidFill *) brush, &pen->color); else pen->color = 0; if (pen->own_brush && pen->brush) GdipDeleteBrush (pen->brush); pen->brush = brush; pen->changed = TRUE; pen->own_brush = FALSE; return Ok; }
GpStatus WINGDIPAPI GdipDeletePen (GpPen *pen) { if (!pen) return InvalidParameter; if (pen->dash_count != 0 && pen->own_dash_array) { GdipFree (pen->dash_array); pen->dash_count = 0; pen->dash_array = NULL; } if (pen->own_brush && pen->brush) { GdipDeleteBrush (pen->brush); pen->brush = NULL; } if (pen->compound_count != 0) { GdipFree (pen->compound_array); pen->compound_array = NULL; pen->compound_count = 0; } if (pen->custom_start_cap != NULL) { GdipDeleteCustomLineCap (pen->custom_start_cap); pen->custom_start_cap = NULL; } if (pen->custom_end_cap != NULL) { GdipDeleteCustomLineCap (pen->custom_end_cap); pen->custom_end_cap = NULL; } GdipFree (pen); return Ok; }
static void test_gradientsurroundcolorcount(void) { GpStatus status; GpPathGradient *grad; ARGB color[3]; INT count; status = GdipCreatePathGradient(blendcount_ptf, 2, WrapModeClamp, &grad); expect(Ok, status); count = 0; status = GdipGetPathGradientSurroundColorCount(grad, &count); expect(Ok, status); expect(2, count); color[0] = color[1] = color[2] = 0xdeadbeef; count = 3; status = GdipGetPathGradientSurroundColorsWithCount(grad, color, &count); expect(Ok, status); expect(1, count); expect(0xffffffff, color[0]); expect(0xffffffff, color[1]); expect(0xdeadbeef, color[2]); color[0] = color[1] = color[2] = 0xdeadbeef; count = 2; status = GdipGetPathGradientSurroundColorsWithCount(grad, color, &count); expect(Ok, status); expect(1, count); expect(0xffffffff, color[0]); expect(0xffffffff, color[1]); expect(0xdeadbeef, color[2]); color[0] = color[1] = color[2] = 0xdeadbeef; count = 1; status = GdipGetPathGradientSurroundColorsWithCount(grad, color, &count); expect(InvalidParameter, status); expect(1, count); expect(0xdeadbeef, color[0]); expect(0xdeadbeef, color[1]); expect(0xdeadbeef, color[2]); color[0] = color[1] = color[2] = 0xdeadbeef; count = 0; status = GdipGetPathGradientSurroundColorsWithCount(grad, color, &count); expect(InvalidParameter, status); expect(0, count); expect(0xdeadbeef, color[0]); expect(0xdeadbeef, color[1]); expect(0xdeadbeef, color[2]); count = 3; status = GdipSetPathGradientSurroundColorsWithCount(grad, color, &count); expect(InvalidParameter, status); count = 2; color[0] = 0x00ff0000; color[1] = 0x0000ff00; status = GdipSetPathGradientSurroundColorsWithCount(NULL, color, &count); expect(InvalidParameter, status); status = GdipSetPathGradientSurroundColorsWithCount(grad, NULL, &count); expect(InvalidParameter, status); /* WinXP crashes on this test */ if(0) { status = GdipSetPathGradientSurroundColorsWithCount(grad, color, NULL); expect(InvalidParameter, status); } status = GdipSetPathGradientSurroundColorsWithCount(grad, color, &count); expect(Ok, status); expect(2, count); status = GdipGetPathGradientSurroundColorCount(NULL, &count); expect(InvalidParameter, status); status = GdipGetPathGradientSurroundColorCount(grad, NULL); expect(InvalidParameter, status); count = 0; status = GdipGetPathGradientSurroundColorCount(grad, &count); expect(Ok, status); expect(2, count); color[0] = color[1] = color[2] = 0xdeadbeef; count = 2; status = GdipGetPathGradientSurroundColorsWithCount(grad, color, &count); expect(Ok, status); expect(2, count); expect(0x00ff0000, color[0]); expect(0x0000ff00, color[1]); expect(0xdeadbeef, color[2]); count = 1; status = GdipSetPathGradientSurroundColorsWithCount(grad, color, &count); expect(Ok, status); expect(1, count); count = 0; status = GdipGetPathGradientSurroundColorCount(grad, &count); expect(Ok, status); expect(2, count); /* If all colors are the same, count is set to 1. */ color[0] = color[1] = 0; count = 2; status = GdipSetPathGradientSurroundColorsWithCount(grad, color, &count); expect(Ok, status); expect(2, count); color[0] = color[1] = color[2] = 0xdeadbeef; count = 2; status = GdipGetPathGradientSurroundColorsWithCount(grad, color, &count); expect(Ok, status); expect(1, count); expect(0x00000000, color[0]); expect(0x00000000, color[1]); expect(0xdeadbeef, color[2]); color[0] = color[1] = 0xff00ff00; count = 2; status = GdipSetPathGradientSurroundColorsWithCount(grad, color, &count); expect(Ok, status); expect(2, count); color[0] = color[1] = color[2] = 0xdeadbeef; count = 2; status = GdipGetPathGradientSurroundColorsWithCount(grad, color, &count); expect(Ok, status); expect(1, count); expect(0xff00ff00, color[0]); expect(0xff00ff00, color[1]); expect(0xdeadbeef, color[2]); count = 0; status = GdipSetPathGradientSurroundColorsWithCount(grad, color, &count); expect(InvalidParameter, status); expect(0, count); GdipDeleteBrush((GpBrush*)grad); status = GdipCreatePathGradient(getbounds_ptf, 3, WrapModeClamp, &grad); expect(Ok, status); color[0] = color[1] = color[2] = 0xdeadbeef; count = 3; status = GdipGetPathGradientSurroundColorsWithCount(grad, color, &count); expect(Ok, status); expect(1, count); expect(0xffffffff, color[0]); expect(0xffffffff, color[1]); expect(0xffffffff, color[2]); color[0] = color[1] = color[2] = 0xdeadbeef; count = 2; status = GdipGetPathGradientSurroundColorsWithCount(grad, color, &count); expect(InvalidParameter, status); expect(2, count); expect(0xdeadbeef, color[0]); expect(0xdeadbeef, color[1]); expect(0xdeadbeef, color[2]); count = 0; status = GdipGetPathGradientSurroundColorCount(grad, &count); expect(Ok, status); expect(3, count); GdipDeleteBrush((GpBrush*)grad); }
GpStatus WINGDIPAPI GdipPlayMetafileRecord(GDIPCONST GpMetafile *metafile, EmfPlusRecordType recordType, UINT flags, UINT dataSize, GDIPCONST BYTE *data) { GpStatus stat; GpMetafile *real_metafile = (GpMetafile*)metafile; TRACE("(%p,%x,%x,%d,%p)\n", metafile, recordType, flags, dataSize, data); if (!metafile || (dataSize && !data) || !metafile->playback_graphics) return InvalidParameter; if (recordType >= 1 && recordType <= 0x7a) { /* regular EMF record */ if (metafile->playback_dc) { ENHMETARECORD *record; record = heap_alloc_zero(dataSize + 8); if (record) { record->iType = recordType; record->nSize = dataSize + 8; memcpy(record->dParm, data, dataSize); PlayEnhMetaFileRecord(metafile->playback_dc, metafile->handle_table, record, metafile->handle_count); heap_free(record); } else return OutOfMemory; } } else { EmfPlusRecordHeader *header = (EmfPlusRecordHeader*)(data)-1; METAFILE_PlaybackReleaseDC((GpMetafile*)metafile); switch(recordType) { case EmfPlusRecordTypeHeader: case EmfPlusRecordTypeEndOfFile: break; case EmfPlusRecordTypeGetDC: METAFILE_PlaybackGetDC((GpMetafile*)metafile); break; case EmfPlusRecordTypeClear: { EmfPlusClear *record = (EmfPlusClear*)header; return GdipGraphicsClear(metafile->playback_graphics, record->Color); } case EmfPlusRecordTypeFillRects: { EmfPlusFillRects *record = (EmfPlusFillRects*)header; GpBrush *brush, *temp_brush=NULL; GpRectF *rects, *temp_rects=NULL; if (dataSize + sizeof(EmfPlusRecordHeader) < sizeof(EmfPlusFillRects)) return InvalidParameter; if (flags & 0x4000) { if (dataSize + sizeof(EmfPlusRecordHeader) < sizeof(EmfPlusFillRects) + sizeof(EmfPlusRect) * record->Count) return InvalidParameter; } else { if (dataSize + sizeof(EmfPlusRecordHeader) < sizeof(EmfPlusFillRects) + sizeof(GpRectF) * record->Count) return InvalidParameter; } if (flags & 0x8000) { stat = GdipCreateSolidFill((ARGB)record->BrushID, (GpSolidFill**)&temp_brush); brush = temp_brush; } else { FIXME("brush deserialization not implemented\n"); return NotImplemented; } if (stat == Ok) { if (flags & 0x4000) { EmfPlusRect *int_rects = (EmfPlusRect*)(record+1); int i; rects = temp_rects = heap_alloc_zero(sizeof(GpRectF) * record->Count); if (rects) { for (i=0; i<record->Count; i++) { rects[i].X = int_rects[i].X; rects[i].Y = int_rects[i].Y; rects[i].Width = int_rects[i].Width; rects[i].Height = int_rects[i].Height; } } else stat = OutOfMemory; } else rects = (GpRectF*)(record+1); } if (stat == Ok) { stat = GdipFillRectangles(metafile->playback_graphics, brush, rects, record->Count); } GdipDeleteBrush(temp_brush); heap_free(temp_rects); return stat; } case EmfPlusRecordTypeSetPageTransform: { EmfPlusSetPageTransform *record = (EmfPlusSetPageTransform*)header; GpUnit unit = (GpUnit)flags; if (dataSize + sizeof(EmfPlusRecordHeader) < sizeof(EmfPlusSetPageTransform)) return InvalidParameter; real_metafile->page_unit = unit; real_metafile->page_scale = record->PageScale; return METAFILE_PlaybackUpdateWorldTransform(real_metafile); } default: FIXME("Not implemented for record type %x\n", recordType); return NotImplemented; } } return Ok; }
/*GDIplus is completely bugged here, we MUST build the gradient in local coord system and apply translation after, otherwise performances are just horrible*/ void gdip_recompute_radial_gradient(GF_STENCIL _this) { s32 repeat, k; u32 i; GpPointF pt; GpMatrix *mat; GPSTEN(); if (!_sten->needs_rebuild) return; _sten->needs_rebuild = GF_FALSE; if (_sten->pRadial) { GdipDeleteBrush(_sten->pRadial); _sten->pRadial = NULL; } if (_sten->pSolid) { GdipDeleteBrush(_sten->pSolid); _sten->pSolid = NULL; } if (_sten->circle) { GdipDeletePath(_sten->circle); _sten->circle = NULL; } GdipCreatePath(FillModeAlternate, &_sten->circle); /*get number of repeats*/ if (_sten->spread == GF_GRADIENT_MODE_PAD) { GdipAddPathEllipse(_sten->circle, - _sten->radius.X, -_sten->radius.Y, 2*_sten->radius.X, 2*_sten->radius.Y); GdipCreatePathGradientFromPath(_sten->circle, &_sten->pRadial); ARGB *blends = new ARGB[_sten->num_pos + 1]; /*radial blend pos are from bounds to center in gdiplus*/ blends[0] = _sten->cols[_sten->num_pos - 1]; for (i=0; i<_sten->num_pos;i++) { blends[i+1] = _sten->cols[_sten->num_pos - i - 1]; } REAL *pos = new REAL[_sten->num_pos + 1]; pos[0] = 0; for (i=0; i<_sten->num_pos;i++) { pos[i+1] = _sten->pos[i]; } GdipSetPathGradientPresetBlend(_sten->pRadial, blends, pos, _sten->num_pos + 1); delete [] blends; delete [] pos; /*set focal*/ pt = _sten->focal; pt.X -= _sten->center.X; pt.Y -= _sten->center.Y; GdipSetPathGradientCenterPoint(_sten->pRadial, &pt); /*set transform*/ GdipCreateMatrix(&mat); GdipTranslateMatrix(mat, _sten->center.X, _sten->center.Y, MatrixOrderAppend); if (_sten->pMat) GdipMultiplyMatrix(mat, _sten->pMat, MatrixOrderAppend); GdipSetTextureTransform((GpTexture*)_sten->pRadial, mat); GdipDeleteMatrix(mat); /*create back brush*/ GdipCreateSolidFill(_sten->cols[_sten->num_pos - 1], &_sten->pSolid); GdipResetPath(_sten->circle); GdipAddPathEllipse(_sten->circle, - _sten->radius.X + _sten->center.X, -_sten->radius.Y + _sten->center.Y, 2*_sten->radius.X, 2*_sten->radius.Y); } else { repeat = 10; GdipAddPathEllipse(_sten->circle, - repeat * _sten->radius.X, - repeat*_sten->radius.Y, 2*repeat*_sten->radius.X, 2*repeat*_sten->radius.Y); GdipCreatePathGradientFromPath(_sten->circle, &_sten->pRadial); GdipDeletePath(_sten->circle); _sten->circle = NULL; ARGB *blends = new ARGB[_sten->num_pos*repeat]; REAL *pos = new REAL[_sten->num_pos*repeat]; if (_sten->spread == GF_GRADIENT_MODE_REPEAT) { for (k=0; k<repeat; k++) { for (i=0; i<_sten->num_pos; i++) { blends[k*_sten->num_pos + i] = _sten->cols[_sten->num_pos - i - 1]; pos[k*_sten->num_pos + i] = (k + _sten->pos[i]) / repeat; } } } else { for (k=0; k<repeat; k++) { for (i=0; i<_sten->num_pos; i++) { u32 index = (k%2) ? (_sten->num_pos-i-1) : i; blends[k*_sten->num_pos + i] = _sten->cols[index]; if (k%2) { pos[k*_sten->num_pos + i] = (k + (1 - _sten->pos[index]) ) / repeat; } else { pos[k*_sten->num_pos + i] = ( k + _sten->pos[i] ) / repeat; } } } } GdipSetPathGradientPresetBlend(_sten->pRadial, blends, pos, _sten->num_pos*repeat); delete [] pos; delete [] blends; /*set focal*/ pt = _sten->focal; pt.X -= (1 - repeat) * (_sten->focal.X - _sten->center.X) + _sten->center.X; pt.Y -= (1 - repeat) * (_sten->focal.Y - _sten->center.Y) + _sten->center.Y; GdipSetPathGradientCenterPoint(_sten->pRadial, &pt); /*set transform*/ GdipCreateMatrix(&mat); GdipTranslateMatrix(mat, (1 - repeat) * (_sten->focal.X - _sten->center.X) + _sten->center.X, (1 - repeat) * (_sten->focal.Y - _sten->center.Y) + _sten->center.Y, MatrixOrderAppend); if (_sten->pMat) GdipMultiplyMatrix(mat, _sten->pMat, MatrixOrderAppend); GdipSetTextureTransform((GpTexture*)_sten->pRadial, mat); GdipDeleteMatrix(mat); GdipSetPathGradientWrapMode(_sten->pRadial, WrapModeTileFlipXY); } }
static void test_linelinearblend(void) { GpLineGradient *brush; GpStatus status; GpPointF pt1, pt2; INT count=10; REAL res_factors[3] = {0.3f}; REAL res_positions[3] = {0.3f}; status = GdipSetLineLinearBlend(NULL, 0.6, 0.8); expect(InvalidParameter, status); pt1.X = pt1.Y = 1.0; pt2.X = pt2.Y = 100.0; status = GdipCreateLineBrush(&pt1, &pt2, 0, 0, WrapModeTile, &brush); expect(Ok, status); status = GdipSetLineLinearBlend(brush, 0.6, 0.8); expect(Ok, status); status = GdipGetLineBlendCount(brush, &count); expect(Ok, status); expect(3, count); status = GdipGetLineBlend(brush, res_factors, res_positions, 3); expect(Ok, status); expectf(0.0, res_factors[0]); expectf(0.0, res_positions[0]); expectf(0.8, res_factors[1]); expectf(0.6, res_positions[1]); expectf(0.0, res_factors[2]); expectf(1.0, res_positions[2]); status = GdipSetLineLinearBlend(brush, 0.0, 0.8); expect(Ok, status); status = GdipGetLineBlendCount(brush, &count); expect(Ok, status); expect(2, count); status = GdipGetLineBlend(brush, res_factors, res_positions, 3); expect(Ok, status); expectf(0.8, res_factors[0]); expectf(0.0, res_positions[0]); expectf(0.0, res_factors[1]); expectf(1.0, res_positions[1]); status = GdipSetLineLinearBlend(brush, 1.0, 0.8); expect(Ok, status); status = GdipGetLineBlendCount(brush, &count); expect(Ok, status); expect(2, count); status = GdipGetLineBlend(brush, res_factors, res_positions, 3); expect(Ok, status); expectf(0.0, res_factors[0]); expectf(0.0, res_positions[0]); expectf(0.8, res_factors[1]); expectf(1.0, res_positions[1]); status = GdipDeleteBrush((GpBrush*)brush); expect(Ok, status); }
static void test_lineblend(void) { GpLineGradient *brush; GpStatus status; GpPointF pt1, pt2; INT count=10; int i; const REAL factors[5] = {0.0f, 0.1f, 0.5f, 0.9f, 1.0f}; const REAL positions[5] = {0.0f, 0.2f, 0.5f, 0.8f, 1.0f}; const REAL two_positions[2] = {0.0f, 1.0f}; const ARGB colors[5] = {0xff0000ff, 0xff00ff00, 0xff00ffff, 0xffff0000, 0xffffffff}; REAL res_factors[6] = {0.3f, 0.0f, 0.0f, 0.0f, 0.0f}; REAL res_positions[6] = {0.3f, 0.0f, 0.0f, 0.0f, 0.0f}; ARGB res_colors[6] = {0xdeadbeef, 0, 0, 0, 0}; pt1.X = pt1.Y = pt2.Y = pt2.X = 1.0; status = GdipCreateLineBrush(&pt1, &pt2, 0, 0, WrapModeTile, &brush); expect(OutOfMemory, status); pt1.X = pt1.Y = 1.0; pt2.X = pt2.Y = 100.0; status = GdipCreateLineBrush(&pt1, &pt2, 0, 0, WrapModeTile, &brush); expect(Ok, status); status = GdipGetLineBlendCount(NULL, &count); expect(InvalidParameter, status); status = GdipGetLineBlendCount(brush, NULL); expect(InvalidParameter, status); status = GdipGetLineBlendCount(brush, &count); expect(Ok, status); expect(1, count); status = GdipGetLineBlend(NULL, res_factors, res_positions, 1); expect(InvalidParameter, status); status = GdipGetLineBlend(brush, NULL, res_positions, 1); expect(InvalidParameter, status); status = GdipGetLineBlend(brush, res_factors, NULL, 1); expect(InvalidParameter, status); status = GdipGetLineBlend(brush, res_factors, res_positions, 0); expect(InvalidParameter, status); status = GdipGetLineBlend(brush, res_factors, res_positions, -1); expect(InvalidParameter, status); status = GdipGetLineBlend(brush, res_factors, res_positions, 1); expect(Ok, status); status = GdipGetLineBlend(brush, res_factors, res_positions, 2); expect(Ok, status); status = GdipSetLineBlend(NULL, factors, positions, 5); expect(InvalidParameter, status); status = GdipSetLineBlend(brush, NULL, positions, 5); expect(InvalidParameter, status); status = GdipSetLineBlend(brush, factors, NULL, 5); expect(InvalidParameter, status); status = GdipSetLineBlend(brush, factors, positions, 0); expect(InvalidParameter, status); status = GdipSetLineBlend(brush, factors, positions, -1); expect(InvalidParameter, status); /* leave off the 0.0 position */ status = GdipSetLineBlend(brush, &factors[1], &positions[1], 4); expect(InvalidParameter, status); /* leave off the 1.0 position */ status = GdipSetLineBlend(brush, factors, positions, 4); expect(InvalidParameter, status); status = GdipSetLineBlend(brush, factors, positions, 5); expect(Ok, status); status = GdipGetLineBlendCount(brush, &count); expect(Ok, status); expect(5, count); status = GdipGetLineBlend(brush, res_factors, res_positions, 4); expect(InsufficientBuffer, status); status = GdipGetLineBlend(brush, res_factors, res_positions, 5); expect(Ok, status); for (i=0; i<5; i++) { expectf(factors[i], res_factors[i]); expectf(positions[i], res_positions[i]); } status = GdipGetLineBlend(brush, res_factors, res_positions, 6); expect(Ok, status); status = GdipSetLineBlend(brush, factors, positions, 1); expect(Ok, status); status = GdipGetLineBlendCount(brush, &count); expect(Ok, status); expect(1, count); status = GdipGetLineBlend(brush, res_factors, res_positions, 1); expect(Ok, status); status = GdipGetLinePresetBlendCount(NULL, &count); expect(InvalidParameter, status); status = GdipGetLinePresetBlendCount(brush, NULL); expect(InvalidParameter, status); status = GdipGetLinePresetBlendCount(brush, &count); expect(Ok, status); expect(0, count); status = GdipGetLinePresetBlend(NULL, res_colors, res_positions, 1); expect(InvalidParameter, status); status = GdipGetLinePresetBlend(brush, NULL, res_positions, 1); expect(InvalidParameter, status); status = GdipGetLinePresetBlend(brush, res_colors, NULL, 1); expect(InvalidParameter, status); status = GdipGetLinePresetBlend(brush, res_colors, res_positions, 0); expect(InvalidParameter, status); status = GdipGetLinePresetBlend(brush, res_colors, res_positions, -1); expect(InvalidParameter, status); status = GdipGetLinePresetBlend(brush, res_colors, res_positions, 1); expect(InvalidParameter, status); status = GdipGetLinePresetBlend(brush, res_colors, res_positions, 2); expect(GenericError, status); status = GdipSetLinePresetBlend(NULL, colors, positions, 5); expect(InvalidParameter, status); status = GdipSetLinePresetBlend(brush, NULL, positions, 5); expect(InvalidParameter, status); status = GdipSetLinePresetBlend(brush, colors, NULL, 5); expect(InvalidParameter, status); status = GdipSetLinePresetBlend(brush, colors, positions, 0); expect(InvalidParameter, status); status = GdipSetLinePresetBlend(brush, colors, positions, -1); expect(InvalidParameter, status); status = GdipSetLinePresetBlend(brush, colors, positions, 1); expect(InvalidParameter, status); /* leave off the 0.0 position */ status = GdipSetLinePresetBlend(brush, &colors[1], &positions[1], 4); expect(InvalidParameter, status); /* leave off the 1.0 position */ status = GdipSetLinePresetBlend(brush, colors, positions, 4); expect(InvalidParameter, status); status = GdipSetLinePresetBlend(brush, colors, positions, 5); expect(Ok, status); status = GdipGetLinePresetBlendCount(brush, &count); expect(Ok, status); expect(5, count); status = GdipGetLinePresetBlend(brush, res_colors, res_positions, 4); expect(InsufficientBuffer, status); status = GdipGetLinePresetBlend(brush, res_colors, res_positions, 5); expect(Ok, status); for (i=0; i<5; i++) { expect(colors[i], res_colors[i]); expectf(positions[i], res_positions[i]); } status = GdipGetLinePresetBlend(brush, res_colors, res_positions, 6); expect(Ok, status); status = GdipSetLinePresetBlend(brush, colors, two_positions, 2); expect(Ok, status); status = GdipDeleteBrush((GpBrush*)brush); expect(Ok, status); }
RT_B RT_API RtGdipStretchBitmap(RT_H hBitmap, RT_H hDc, RT_N nWidth, RT_N nHeight, RT_GDIP_INTERPOLATION_MODE nInterpolationMode) { GpGraphics* lpGraphics; GpBitmap* lpBitmap; GpBrush* lpBrush; GpStatus nStatus; RT_B bResult; lpGraphics = RT_NULL; lpBitmap = RT_NULL; lpBrush = RT_NULL; /* Create destination graphics hDc. */ nStatus = GdipCreateFromHDC(hDc, &lpGraphics); if (nStatus) { RtGdipSetLastErrorFromGpStatus(nStatus); goto handle_error; } /* Adjust quality. */ nStatus = GdipSetInterpolationMode(lpGraphics, (InterpolationMode)nInterpolationMode); if (nStatus) { RtGdipSetLastErrorFromGpStatus(nStatus); goto handle_error; } /* Create a brush to fill the background. */ nStatus = GdipCreateSolidFill(0xFFFFFFFF, &lpBrush); if (nStatus) { RtGdipSetLastErrorFromGpStatus(nStatus); goto handle_error; } /* Fill the destination DC with a background. Necessary to avoid edges artifacts. */ nStatus = GdipFillRectangleI(lpGraphics, lpBrush, 0, 0, nWidth, nHeight); if (nStatus) { RtGdipSetLastErrorFromGpStatus(nStatus); goto handle_error; } /* Create source image/bitmap from hBitmap. */ nStatus = GdipCreateBitmapFromHBITMAP(hBitmap, RT_NULL, &lpBitmap); if (nStatus) { RtGdipSetLastErrorFromGpStatus(nStatus); goto handle_error; } /* Stretch. */ nStatus = GdipDrawImageRectI(lpGraphics, lpBitmap, 0, 0, nWidth, nHeight); if (nStatus) { RtGdipSetLastErrorFromGpStatus(nStatus); goto handle_error; } bResult = RT_TRUE; goto free_resources; handle_error: bResult = RT_FALSE; free_resources: if (lpGraphics) { nStatus = GdipDeleteGraphics(lpGraphics); lpGraphics = RT_NULL; if (nStatus && bResult) { RtGdipSetLastErrorFromGpStatus(nStatus); goto handle_error; } } if (lpBitmap) { nStatus = GdipDisposeImage(lpBitmap); lpBitmap = RT_NULL; if (nStatus && bResult) { RtGdipSetLastErrorFromGpStatus(nStatus); goto handle_error; } } if (lpBrush) { nStatus = GdipDeleteBrush(lpBrush); lpBrush = RT_NULL; if (nStatus && bResult) { RtGdipSetLastErrorFromGpStatus(nStatus); goto handle_error; } } return bResult; }