Powerbasic Museum 2020-B

General Category => General Discussion => Topic started by: Edwin Knoppert on October 17, 2011, 12:19:27 PM

Title: GDIplus - brightness
Post by: Edwin Knoppert on October 17, 2011, 12:19:27 PM
Can't find the way to do this with PB:

http://msdn.microsoft.com/en-us/library/ms536278(v=vs.85).aspx

Just need to brighten an image via a slider.
Got so far  ;D

Type BrightnessContrastParams
  brightnessLevel As Long
  contrastLevel As Long
End Type
Title: Re: GDIplus - brightness
Post by: José Roca on October 17, 2011, 04:02:22 PM
Looks like a good start...

Now create an Effects object with GdipCreateEffect, fill the brightnessLevel member of the structure with the wanted value, set the parameters with GdipSetEffectParameters, draw the image using GdipDrawImageFX and delete the effects object with GdipDeleteEffect.
Title: Re: GDIplus - brightness
Post by: Edwin Knoppert on October 18, 2011, 10:10:03 AM
Thanks!

First issue i found:
Byref Guid doesn't do it:

Declare Function GdipCreateEffect Lib "GDIPLUS.DLL" Alias "GdipCreateEffect" ( _
   ByRef Guid As Guid _                                 ' __in  const GUID guid
, ByRef effect As Dword _                              ' __out CGpEffect **effect
) As Long                                              ' GpStatus

I changed it to ByVal and i get 0 for result and pointer to effects.

Note: did not use your declare but a call dword as:

    g = Guid$("{D3A1DBE1-8EC4-4C17-9F4C-EA97AD1C343D}")
    Call Dword CDW Using VD_GdipCreateEffect( g, effect ) To hr

Declare Function VD_GdipCreateEffect( _
   ByVal Guid As Guid _                                 ' __in  const GUID guid
, ByRef effect As Dword _                              ' __out CGpEffect **effect
) As Long                                              ' GpStatus
)

Later..
Title: Re: GDIplus - brightness
Post by: Edwin Knoppert on October 18, 2011, 10:41:35 AM
It works :)
Title: Re: GDIplus - brightness
Post by: Edwin Knoppert on October 18, 2011, 11:32:33 AM
Any idea how to strecth during draw?
The matrix param seems to be the part i need(?)
Don't know how that works.
Title: Re: GDIplus - brightness
Post by: José Roca on October 18, 2011, 01:27:37 PM
Create a Matrix object with GdipCreateMatrix, call one of  the GdipCreateMatrixXXX, e.g. GdipCreateMatrix2 functions, and later delete it with GdipDeleteMatrix.
Title: Re: GDIplus - brightness
Post by: Edwin Knoppert on October 18, 2011, 01:56:19 PM
Thanks, works, FAI:

GdipCreateMatrix2(...)

xscale, 0, 0, yscale, offsetx, offsety like: 1, 0, 0, 1, 400, 40
Title: Re: GDIplus - brightness
Post by: Patrice Terrier on October 18, 2011, 03:49:33 PM
Quote
FUNCTION UseBrightnessMatrix(BYVAL imgAttr AS LONG, BYVAL Value AS LONG) AS LONG
  ' Range value 0 to 255 (-1 to 1, with 0 = neutral)
    LOCAL c AS ColorMatrix, V AS SINGLE
    Value = MAX&(MIN&(Value + 1, 256), 0)
    V = -1 + (Value / 128)
  ' Create the ImageAttributes object
    IF imgAttr = 0 THEN CALL GdipCreateImageAttributes(imgAttr)
  ' Fill the color matrix
  ' Red            Green          Blue           Alpha          W
    c.m(0, 0) = 1: c.m(1, 0) = 0: c.m(2, 0) = 0: c.m(3, 0) = 0: c.m(4, 0) = 0
    c.m(0, 1) = 0: c.m(1, 1) = 1: c.m(2, 1) = 0: c.m(3, 1) = 0: c.m(4, 1) = 0
    c.m(0, 2) = 0: c.m(1, 2) = 0: c.m(2, 2) = 1: c.m(3, 2) = 0: c.m(4, 2) = 0
    c.m(0, 3) = 0: c.m(1, 3) = 0: c.m(2, 3) = 0: c.m(3, 3) = 1: c.m(4, 3) = 0
    c.m(0, 4) = V: c.m(1, 4) = V: c.m(2, 4) = V: c.m(3, 4) = 0: c.m(4, 4) = 1
  ' And set its color matrix
    CALL GdipSetImageAttributesColorMatrix(imgAttr&, %ColorAdjustTypeDefault, %TRUE, c, BYVAL 0, %ColorMatrixFlagsDefault)
    FUNCTION = imgAttr
END FUNCTION
Title: Re: GDIplus - brightness
Post by: Edwin Knoppert on October 27, 2011, 04:45:45 AM
I have not investigated which call fails yet but on a different Windows 7 computer on of the calls does not seem to be supported.
If i read your declare it's embedded with a
#If (%GDIPVER >= &H0110)
#endif
If i read MSDN it says it's available from Windows XP and up
http://msdn.microsoft.com/en-us/library/ms536058(v=vs.85).aspx

Like i said i have to check the actual call but i asume the GdipDrawImageFX() is the critter here?
Title: Re: GDIplus - brightness
Post by: José Roca on October 27, 2011, 05:43:36 AM
It requires GDI+ 1.1.
Title: Re: GDIplus - brightness
Post by: Patrice Terrier on October 27, 2011, 09:27:09 AM
I avoid to use GDI+ 1.1, because there is no standard distribution for it.

So far i didn't found anything in version 1.1, that couldn't be done with the standard version, but of course that come at a price:
more personnal work, and a good understanding of the fundamentals of GDI+ matrix.

...

Title: Re: GDIplus - brightness
Post by: Edwin Knoppert on October 27, 2011, 05:49:30 PM
Terribly irritating, especially the number of issues i already had last week using gdiplus while i thought it would be a breeze to implement.
Does your code handle brightness + contrast?
Is that matrix working identical to my code (output)?

I thought this would help for v1.1 but i don't had the time yet, found out that it's about a Vista computer:
http://support.microsoft.com/KB/958911

Added:
Can't i use my original code and manipulate the image and draw it using an older call instead of drawing the image and effects with the new call directly?
I can hold a copy of the image before modifying it.
Title: Re: GDIplus - brightness
Post by: Patrice Terrier on October 27, 2011, 07:40:14 PM
QuoteDoes your code handle brightness + contrast?

Yes, see PhotoSetup (http://www.jose.it-berater.org/smfforum/index.php?topic=2341.msg7290#msg7290)

...
Title: Re: GDIplus - brightness
Post by: Edwin Knoppert on October 29, 2011, 03:06:36 PM
FYI:
Will try your code and the code being posted on the PB forum.
I need brightness + contrast though
(Complex matrix stuff :) )
Title: Re: GDIplus - brightness
Post by: Larry Charlton on October 30, 2011, 01:05:17 AM
If you grab the GDIPlus testing code I've been writing it has a contrast matrix.  Just multiply the two together to get both.
Title: Re: GDIplus - brightness
Post by: Edwin Knoppert on October 30, 2011, 06:52:10 AM
Yes i seen it, only thing is that the scale/scope differs from the gdiplus effects -1/1 vs -255/255
I have the feeling that a float can not reach the same potential this way (?)
Title: Re: GDIplus - brightness
Post by: Patrice Terrier on October 30, 2011, 09:00:47 AM
Contrast

   // factor > 1.0f increases the contrast
   // 0.0f < factor < 1,0f decreases the contrast
   REAL factorT = 0.5f * (1.0f - factor);
   
   ColorMatrix colorMatrix =
   {
      factor,  0.0f,    0.0f,    0.0f, 0.0f,
      0.0f,    factor,  0.0f,    0.0f, 0.0f,
      0.0f,    0.0f,    factor,  0.0f, 0.0f,
      0.0f,    0.0f,    0.0f,    1.0f, 0.0f,
      factorT, factorT, factorT, 0.0f, 1.0f
   };
Title: Re: GDIplus - brightness
Post by: Edwin Knoppert on October 30, 2011, 12:25:42 PM
Somewhere this week i'll continue on this.
I have some other projects interfering :)

Thanks,
Title: Re: GDIplus - brightness
Post by: Edwin Knoppert on October 30, 2011, 12:31:42 PM
Btw, i was using a trackbar but does not seem to accept negative ranges (-1 <> 1)
I shifted it to positive values but the tracking tooltip shows those values as well.
I wonder if i can use negative values or customly set the value in the tooltip.

Last resort would be to prepare a tracking tooltip from scratch.