From: Vijay Kiran Kamuju infyquest@gmail.com
--- dlls/gdiplus/gdiplus_private.h | 13 ++++ dlls/gdiplus/image.c | 109 +++++++++++++++++++++++++++++++-- dlls/gdiplus/tests/image.c | 95 +++++++++++++++++++++++++++- include/gdipluseffects.h | 1 + 4 files changed, 212 insertions(+), 6 deletions(-)
diff --git a/dlls/gdiplus/gdiplus_private.h b/dlls/gdiplus/gdiplus_private.h index 44d3e6d1000..6325ab40aa0 100644 --- a/dlls/gdiplus/gdiplus_private.h +++ b/dlls/gdiplus/gdiplus_private.h @@ -386,6 +386,19 @@ typedef enum EffectType { typedef struct CGpEffect{ INT datasize; void *data; + union params { + struct BlurParams *blurparams; + struct SharpenParams *sharpenparams; + struct TintParams *tintparams; + struct RedEyeCorrectionParams *redeyeparams; + ColorMatrix *clrmatrixparams; + struct ColorLUTParams *clrlutparams; + struct BrightnessContrastParams *brtcntrstparams; + struct HueSaturationLightnessParams *huesatliteparams; + struct ColorBalanceParams *clrbalanceparams; + struct LevelsParams *levelsparams; + struct ColorCurveParams *clrcurveparams; + } p; EffectType type; } CGpEffect;
diff --git a/dlls/gdiplus/image.c b/dlls/gdiplus/image.c index f8b98de460d..47485f4505c 100644 --- a/dlls/gdiplus/image.c +++ b/dlls/gdiplus/image.c @@ -5591,46 +5591,57 @@ GpStatus WINGDIPAPI GdipCreateEffect(const GUID guid, CGpEffect **effect) if (IsEqualGUID(&guid, &BlurEffectGuid)) { ef->type = BlurEffect; + ef->p.blurparams = NULL; } else if (IsEqualGUID(&guid, &SharpenEffectGuid)) { ef->type = SharpenEffect; + ef->p.sharpenparams = NULL; } else if (IsEqualGUID(&guid, &TintEffectGuid)) { ef->type = TintEffect; + ef->p.tintparams = NULL; } else if (IsEqualGUID(&guid, &RedEyeCorrectionEffectGuid)) { ef->type = RedEyeCorrectionEffect; + ef->p.redeyeparams = NULL; } else if (IsEqualGUID(&guid, &ColorMatrixEffectGuid)) { ef->type = ColorMatrixEffect; + ef->p.clrmatrixparams = NULL; } else if (IsEqualGUID(&guid, &ColorLUTEffectGuid)) { ef->type = ColorLUTEffect; + ef->p.clrlutparams = NULL; } else if (IsEqualGUID(&guid, &BrightnessContrastEffectGuid)) { ef->type = BrightnessContrastEffect; + ef->p.brtcntrstparams = NULL; } else if (IsEqualGUID(&guid, &HueSaturationLightnessEffectGuid)) { ef->type = HueSaturationLightnessEffect; + ef->p.huesatliteparams = NULL; } else if (IsEqualGUID(&guid, &ColorBalanceEffectGuid)) { ef->type = ColorBalanceEffect; + ef->p.clrbalanceparams = NULL; } else if (IsEqualGUID(&guid, &LevelsEffectGuid)) { ef->type = LevelsEffect; + ef->p.levelsparams = NULL; } else if (IsEqualGUID(&guid, &ColorCurveEffectGuid)) { ef->type = ColorCurveEffect; + ef->p.clrcurveparams = NULL; } else { @@ -5679,6 +5690,8 @@ GpStatus WINGDIPAPI GdipGetEffectParameterSize(CGpEffect *effect, UINT *size) break; case RedEyeCorrectionEffect: sz = sizeof(struct RedEyeCorrectionParams); + if (effect->p.redeyeparams) + sz += effect->p.redeyeparams->numberOfAreas*sizeof(RECT); break; case ColorMatrixEffect: sz = sizeof(ColorMatrix); @@ -5705,8 +5718,8 @@ GpStatus WINGDIPAPI GdipGetEffectParameterSize(CGpEffect *effect, UINT *size) status = InvalidParameter; break; } - *size = sz; + return status; }
@@ -5716,14 +5729,100 @@ GpStatus WINGDIPAPI GdipGetEffectParameterSize(CGpEffect *effect, UINT *size) GpStatus WINGDIPAPI GdipSetEffectParameters(CGpEffect *effect, const VOID *params, const UINT size) { - static int calls; + UINT paramsize = 0, num = 0;
TRACE("(%p,%p,%u)\n", effect, params, size);
- if(!(calls++)) - FIXME("not implemented\n"); + if (!effect || !params || !size) + return InvalidParameter;
- return NotImplemented; + switch (effect->type) + { + case BlurEffect: + paramsize = sizeof(struct BlurParams); + if (paramsize != size) + return InvalidParameter; + effect->p.blurparams = malloc(size); + memcpy(effect->p.blurparams, params, size); + break; + case SharpenEffect: + paramsize = sizeof(struct SharpenParams); + if (paramsize != size) + return InvalidParameter; + effect->p.sharpenparams = malloc(size); + memcpy(effect->p.sharpenparams, params, size); + break; + case TintEffect: + paramsize = sizeof(struct TintParams); + if (paramsize != size) + return InvalidParameter; + effect->p.tintparams = malloc(size); + memcpy(effect->p.tintparams, params, size); + break; + case RedEyeCorrectionEffect: + paramsize = sizeof(struct RedEyeCorrectionParams); + if ((size-paramsize <= 0) || (((size-paramsize)%sizeof(RECT)) != 0)) + return InvalidParameter; + effect->p.redeyeparams = malloc(paramsize); + num = (size-paramsize)/sizeof(RECT); + effect->p.redeyeparams->numberOfAreas = num; + effect->p.redeyeparams->areas = malloc(num*sizeof(RECT)); + memcpy(effect->p.redeyeparams->areas, ((struct RedEyeCorrectionParams *)params)->areas, num*sizeof(RECT)); + break; + case ColorMatrixEffect: + paramsize = sizeof(ColorMatrix); + if (paramsize != size) + return InvalidParameter; + effect->p.clrmatrixparams = malloc(size); + memcpy(effect->p.clrmatrixparams, params, size); + break; + case ColorLUTEffect: + paramsize = sizeof(struct ColorLUTParams); + if (paramsize != size) + return InvalidParameter; + effect->p.clrlutparams = malloc(size); + memcpy(effect->p.clrlutparams, params, size); + break; + case BrightnessContrastEffect: + paramsize = sizeof(struct BrightnessContrastParams); + if (paramsize != size) + return InvalidParameter; + effect->p.brtcntrstparams = malloc(size); + memcpy(effect->p.brtcntrstparams, params, size); + break; + case HueSaturationLightnessEffect: + paramsize = sizeof(struct HueSaturationLightnessParams); + if (paramsize != size) + return InvalidParameter; + effect->p.huesatliteparams = malloc(size); + memcpy(effect->p.huesatliteparams, params, size); + break; + case ColorBalanceEffect: + paramsize = sizeof(struct ColorBalanceParams); + if (paramsize != size) + return InvalidParameter; + effect->p.clrbalanceparams = malloc(size); + memcpy(effect->p.clrbalanceparams, params, size); + break; + case LevelsEffect: + paramsize = sizeof(struct LevelsParams); + if (paramsize != size) + return InvalidParameter; + effect->p.levelsparams = malloc(size); + memcpy(effect->p.levelsparams, params, size); + break; + case ColorCurveEffect: + paramsize = sizeof(struct ColorCurveParams); + if (paramsize != size) + return InvalidParameter; + effect->p.clrcurveparams = malloc(size); + memcpy(effect->p.clrcurveparams, params, size); + break; + default: + return InvalidParameter; + } + + return Ok; }
/***************************************************************************** diff --git a/dlls/gdiplus/tests/image.c b/dlls/gdiplus/tests/image.c index abf8fd98625..5690f6bb27e 100644 --- a/dlls/gdiplus/tests/image.c +++ b/dlls/gdiplus/tests/image.c @@ -5408,19 +5408,34 @@ static void test_createeffect(void) GpStatus (WINAPI *pGdipCreateEffect)( const GUID guid, CGpEffect **effect); GpStatus (WINAPI *pGdipDeleteEffect)( CGpEffect *effect); GpStatus (WINAPI *pGdipGetEffectParameterSize)( CGpEffect *effect, UINT *size); + GpStatus (WINAPI *pGdipSetEffectParameters)( CGpEffect *effect, const VOID *params, const UINT size); GpStatus stat; CGpEffect *effect; UINT size, paramsize = 0; + void *params = NULL; HMODULE mod = GetModuleHandleA("gdiplus.dll"); - int i; + int i, j, k; const GUID * const effectlist[] = {&BlurEffectGuid, &SharpenEffectGuid, &ColorMatrixEffectGuid, &ColorLUTEffectGuid, &BrightnessContrastEffectGuid, &HueSaturationLightnessEffectGuid, &LevelsEffectGuid, &TintEffectGuid, &ColorBalanceEffectGuid, &RedEyeCorrectionEffectGuid, &ColorCurveEffectGuid}; + struct BlurParams blur; + struct SharpenParams sharpen; + ColorMatrix matrix; + struct ColorLUTParams clut; + struct BrightnessContrastParams bc; + struct HueSaturationLightnessParams hsl; + struct LevelsParams lvl; + struct TintParams tint; + struct ColorBalanceParams cbal; + struct RedEyeCorrectionParams redi; + struct ColorCurveParams ccurve; + RECT rects[2];
pGdipCreateEffect = (void*)GetProcAddress( mod, "GdipCreateEffect"); pGdipDeleteEffect = (void*)GetProcAddress( mod, "GdipDeleteEffect"); pGdipGetEffectParameterSize = (void*)GetProcAddress( mod, "GdipGetEffectParameterSize"); + pGdipSetEffectParameters = (void*)GetProcAddress( mod, "GdipSetEffectParameters"); if(!pGdipCreateEffect || !pGdipDeleteEffect) { /* GdipCreateEffect/GdipDeleteEffect was introduced in Windows Vista. */ @@ -5434,15 +5449,27 @@ static void test_createeffect(void) stat = pGdipGetEffectParameterSize(NULL, NULL); expect(InvalidParameter, stat);
+ stat = pGdipSetEffectParameters(NULL, NULL, 0); + expect(InvalidParameter, stat); + stat = pGdipGetEffectParameterSize(effect, NULL); expect(InvalidParameter, stat);
+ stat = pGdipSetEffectParameters(effect, params, 0); + expect(InvalidParameter, stat); + stat = pGdipCreateEffect(noneffect, &effect); expect(Win32Error, stat);
stat = pGdipGetEffectParameterSize(effect, &size); expect(InvalidParameter, stat); expect(0, size); + stat = pGdipSetEffectParameters(effect, (void *)0xdeadbeef, 0); + expect(InvalidParameter, stat); + stat = pGdipSetEffectParameters(effect, (void *)0xdeadbeef, 8); + expect(InvalidParameter, stat); + stat = pGdipSetEffectParameters(effect, (void *)0xdeadbeef, 5); + expect(InvalidParameter, stat);
for(i=0; i < ARRAY_SIZE(effectlist); i++) { @@ -5458,38 +5485,104 @@ static void test_createeffect(void) { case 0: paramsize = sizeof(struct BlurParams); + expect(paramsize, size); + blur.radius = 2.0; + blur.expandEdge = TRUE; + stat = pGdipSetEffectParameters(effect, (void *)&blur, 5); + expect(InvalidParameter, stat); + stat = pGdipSetEffectParameters(effect, (void *)&blur, paramsize); break; case 1: paramsize = sizeof(struct SharpenParams); + expect(paramsize, size); + sharpen.radius = 5.0; + sharpen.amount = 2; + stat = pGdipSetEffectParameters(effect, (void *)&sharpen, paramsize); break; case 2: paramsize = sizeof(ColorMatrix); + expect(paramsize, size); + for (j = 0; j < 5; j++) { + for (k = 0; k < 5; k++) { + matrix.m[j][k] = (float) j+1; + } + } + stat = pGdipSetEffectParameters(effect, (void *)&matrix, paramsize); break; case 3: paramsize = sizeof(struct ColorLUTParams); + expect(paramsize, size); + for (j = 0; j < sizeof(ColorChannelLUT); j++) + { + clut.lutB[j] = j%8; + clut.lutG[j] = j%16; + clut.lutR[j] = j%4; + clut.lutA[j] = 0; + } + stat = pGdipSetEffectParameters(effect, (void *)&clut, paramsize); break; case 4: paramsize = sizeof(struct BrightnessContrastParams); + expect(paramsize, size); + bc.brightnessLevel = 75; + bc.contrastLevel = 50; + stat = pGdipSetEffectParameters(effect, (void *)&bc, paramsize); break; case 5: paramsize = sizeof(struct HueSaturationLightnessParams); + expect(paramsize, size); + hsl.hueLevel = 50; + hsl.saturationLevel = 50; + hsl.lightnessLevel = 50; + stat = pGdipSetEffectParameters(effect, (void *)&hsl, paramsize); break; case 6: paramsize = sizeof(struct LevelsParams); + expect(paramsize, size); + lvl.highlight = 50; + lvl.midtone = 50; + lvl.shadow = 5; + stat = pGdipSetEffectParameters(effect, (void *)&lvl, paramsize); break; case 7: paramsize = sizeof(struct TintParams); + expect(paramsize, size); + tint.hue = 20; + tint.amount = 5; + stat = pGdipSetEffectParameters(effect, (void *)&tint, paramsize); break; case 8: paramsize = sizeof(struct ColorBalanceParams); + expect(paramsize, size); + cbal.cyanRed = 50; + cbal.magentaGreen = 50; + cbal.yellowBlue = 50; + stat = pGdipSetEffectParameters(effect, (void *)&cbal, paramsize); break; case 9: paramsize = sizeof(struct RedEyeCorrectionParams); + expect(paramsize, size); + SetRect(&rects[0], 0, 0, 75, 75); + SetRect(&rects[1], -32, -32, 32, 32); + redi.numberOfAreas = 2; + redi.areas = rects; + stat = pGdipSetEffectParameters(effect, (void *)&redi, paramsize); + expect(InvalidParameter, stat); + paramsize = paramsize + (2*sizeof(RECT)); + stat = pGdipSetEffectParameters(effect, (void *)&redi, paramsize); break; case 10: paramsize = sizeof(struct ColorCurveParams); + expect(paramsize, size); + ccurve.adjustment = AdjustExposure; + ccurve.channel = CurveChannelAll; + ccurve.adjustValue = 5; + stat = pGdipSetEffectParameters(effect, (void *)&ccurve, paramsize); break; } + expect(Ok, stat); + size = 0; + stat = pGdipGetEffectParameterSize(effect, &size); expect(paramsize, size);
stat = pGdipDeleteEffect(effect); diff --git a/include/gdipluseffects.h b/include/gdipluseffects.h index a58d25cb0e3..2b94479f7f5 100644 --- a/include/gdipluseffects.h +++ b/include/gdipluseffects.h @@ -112,6 +112,7 @@ extern "C" { GpStatus WINGDIPAPI GdipCreateEffect(const GUID guid, CGpEffect **effect); GpStatus WINGDIPAPI GdipDeleteEffect(CGpEffect *effect); GpStatus WINGDIPAPI GdipGetEffectParameterSize(CGpEffect *effect, UINT *size); +GpStatus WINGDIPAPI GdipSetEffectParameters(CGpEffect *effect, const VOID *params, const UINT size);
#ifdef __cplusplus }