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; }
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); }