Announcement

Collapse
No announcement yet.

GDI Plus Wrapper Classes

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • GDI Plus Wrapper Classes

    I've started creating some GDI+ wrapper classes. The nice thing about them is they track the resources and dispose of them when no longer needed. You can download them here along with a small demo program that exercises some of them.

    LarryC
    Website
    Sometimes life's a dream, sometimes it's a scream

  • #2
    • Added loading icons, drawing, and drawing sub-images along with the position of the drawing to Bitmaps
    • Added clarity setting to graphics
    • Added HSL class
    • Added DrawOutline to path
    • Added end caps, line joins, pen alignment, and dashes to Pen
    • Added RGB class
    • Added simple color from a, h, s, l values function
    • Added Count, Remove, Transform type, x, y, Add transform to transform
    • Created big SLL, single sll. Getting linker errors with individual files.
    • Created DLL
    • Added test versions for SLL and DLL.
    • Added outline and rotation tests
    LarryC
    Website
    Sometimes life's a dream, sometimes it's a scream

    Comment


    • #3
      Fixed a bug with bitmap rendering.
      Added Grayscale, Sepia, Contrast, Saturation, Negative, Brightness, Gama, Color scale, Color Tranform, Color Rotate, Color Shear, and HSV transforms to ColorAttribute. Updated demo with example calls.
      LarryC
      Website
      Sometimes life's a dream, sometimes it's a scream

      Comment


      • #4
        Added a convolution matrix to bitmap with Sharpen, MeanRemoval, EdgeEnhance, Emboss, and FindEdges, Blur, and Smooth.

        Edit: Forgot to mention that the color matrices have been made cumulative. i.e. you can apply a series of them and the cumulative effect is what the resulting matrix will produce.
        Last edited by Larry Charlton; 28 Oct 2011, 04:27 AM.
        LarryC
        Website
        Sometimes life's a dream, sometimes it's a scream

        Comment


        • #5
          Fixed an bug with convolution matrixes.
          Add more in-place bitmap effects:

          EmbossLaplacian
          FindEdgesQuick
          FindEdgesSobel
          FindEdgesPrewitt
          FindEdgesKirsh
          Invert
          Mask
          FlipHorizontal
          FlipVertical
          RotateLeft
          RotateRight
          RotateHalf
          Jitter
          Swirl
          Sphere
          Wave
          Pixelate
          Maze

          Edit: Updated the Wave function to remove some artifacts, Added a bitmap Fade. Updated demo to Animate Swirl/Sphere/Pixelate over a reflected moving wave.
          Edit: Added ShearFromBitmap
          Last edited by Larry Charlton; 30 Oct 2011, 10:33 PM.
          LarryC
          Website
          Sometimes life's a dream, sometimes it's a scream

          Comment


          • #6
            Added a puzzle piece path generator and an nxn random piece puzzle path generator.
            LarryC
            Website
            Sometimes life's a dream, sometimes it's a scream

            Comment


            • #7
              Hi Larry,
              I'm very interested in your work with GDI+. But I've had way too many distractions (I am easily distracted) that have kept me from doing anything with your code.

              It is comforting to know, however, that there are toys laying in wait when time becomes available. Is it inappropriate to say thanks for your work, when I haven't tested it out just yet? At the rate you're making improvements, by the time I do get to test it out, you'll have polished it to perfection, yes?

              Comment


              • #8
                Thanks, just having fun and trying to learn stuff. A great deal of credit belongs to many people accross the web that ideas and code were ported from.
                LarryC
                Website
                Sometimes life's a dream, sometimes it's a scream

                Comment


                • #9
                  Thanks Larry.
                  As we spoke on Jose's board i'll certainly take some stuff out of your code.
                  Unf. i can not use PB10 for this at this time so i'll have to rewrite a few things

                  (Also not Jose's incudes and also not declares to gdiplus)
                  hellobasic

                  Comment


                  • #10
                    Originally posted by Edwin Knoppert View Post
                    Thanks Larry.
                    As we spoke on Jose's board i'll certainly take some stuff out of your code.
                    Unf. i can not use PB10 for this at this time so i'll have to rewrite a few things

                    (Also not Jose's incudes and also not declares to gdiplus)
                    Great, hope it speeds things along. That's the main reason I post it instead of just learning on my computer
                    LarryC
                    Website
                    Sometimes life's a dream, sometimes it's a scream

                    Comment


                    • #11
                      I downloaded your last package but could not compile it.
                      Even an 0:000 error in PB

                      Anyway, it seems the brightness as contrast in your code share the same b() c() arrays.
                      Is this ok?
                      I rewrote these parts into a single function with separate arrays and seems ok.

                      Note that the newer gdiplus v1.1. draweffects/contrast feature has more depth on the highest setting.
                      I assume they use the matrixc somewhat different.
                      hellobasic

                      Comment


                      • #12
                        I've updated the ColorAttribute class to use the full matrix notation. Makes it a bit easier to follow. Contrast and Brightness should be different matrices (they do different things).
                        LarryC
                        Website
                        Sometimes life's a dream, sometimes it's a scream

                        Comment


                        • #13
                          I worked on this matter a few hours today and i had assistance from a colleague.
                          We both determined that it's unlikely Method Brightness( v As Single ) as Method Contrast( v As Single ) use c() for the matrix.
                          We could be wrong but in our opinion brightness and contrast need to be set in different arrays and then multilplied.

                          Are we wrong?

                          Also.., the new contrast code seems to lack the 3 float settings as shown in Patrice's c code, see: Reply #7 and Reply #16 on
                          http://www.jose.it-berater.org/smffo...p?topic=4415.0

                          Today we used mat() similar like what you did, i can't understand the move to your new code.
                          Stability for our software is important, in this case i mean that the enduser will do some settings, it should not perform differently in a next release using these same settings.
                          For example a shift in contrast is a no-no for us.
                          Can you explain this move, can't detect a difference between mat() and plain code.
                          hellobasic

                          Comment


                          • #14
                            I can only repeat that the brightness and contrast matrixes are different. If you have a version of the code where they were the same, it was in error. The effect is remarkably different. The one Patrice showed is another variation. I didn't care for the way it scaled which is why I changed my brightness matrix.

                            At the end of the day, particularly if you're writing your own code, any change I make won't affect your code. The change I made today should have been simply to make it easier to visualize the entire matrix.
                            LarryC
                            Website
                            Sometimes life's a dream, sometimes it's a scream

                            Comment


                            • #15
                              I just looked at Patrices, here's some variations of brightness:

                              Patrice
                              Brightness
                              Code:
                              1 0 0 0 0
                              0 1 0 0 0
                              0 0 1 0 0
                              0 0 0 1 0
                              V V V 0 1
                              Larry
                              Brightness
                              Code:
                              1 0 0 0 v
                              0 1 0 0 v
                              0 0 1 0 v
                              0 0 0 1 1
                              0 0 0 0 1
                              You'll notice that the difference between Patrices and mine is we reverse axis and I have a 1 by the alpha value in the 4th column where he has a 0. I believe my matrix is in error and should have a 0, can't think of a good reason to increase alpha by one I'm not completely sure why our axises are backwards, but I will say this: If you put the values in the 4th axis on the wrong dimension, there will be no effect (because w is not part of the color or alpha, i.e. changing w has no effect on the color).

                              If you had to choose between my knowlege of color theory and Patrices, I'd recommend you go with Patrices, have you seen his apps?
                              LarryC
                              Website
                              Sometimes life's a dream, sometimes it's a scream

                              Comment


                              • #16
                                Added a lightning strike generator and forked lightning generator. Strength, forks, variance, start, and end are parameters.
                                LarryC
                                Website
                                Sometimes life's a dream, sometimes it's a scream

                                Comment


                                • #17
                                  We looked at both your code but at the end the multiply made us use yours.
                                  Does this look wrong?
                                  Code:
                                  'nBrightness: -255 <> + 255
                                  'nContrast: -100 <> +100
                                  Function GDIPlus_CreateBrightnessContrastMatrix( ByVal nBrightness As Long, ByVal nContrast As Long ) As Long
                                  
                                      Local imgAttr           As Long
                                      Local CDW               As Dword
                                      Local hLIB              As Long
                                      Local m                 As Watermark_ColorMatrix
                                      Local b                 As Single   ' brightness
                                      Local c                 As Single   ' contrast
                                      Local t                 As Single
                                      Dim aa(0 To 4, 0 To 4)  As Single At VarPtr( m.m(0,0) )
                                      Dim bb(0 To 4, 0 To 4)  As Single
                                      Dim cc(0 To 4, 0 To 4)  As Single    
                                  
                                      If VD_GDIPlus_IsLoaded() = 0 Then Exit Function
                                  
                                      b = CSng( nBrightness ) / 255!
                                      c = CSng( nContrast + 100 ) / 100!
                                      t = (1! - c) / 2!
                                  
                                      hLib = VD_GDIPlus_Props.hLib
                                      CDW = GetProcAddress( hLib, "GdipCreateImageAttributes" )
                                      Call Dword CDW Using Watermark_GdipCreateImageAttributes( imgAttr ) 
                                  
                                      Mat aa() = Idn
                                      Mat bb() = Idn
                                      Mat cc() = Idn
                                      
                                      bb(0,4) = b
                                      bb(1,4) = b
                                      bb(2,4) = b
                                  
                                      cc(0,0) = c
                                      cc(1,1) = c
                                      cc(2,2) = c
                                      cc(0,4) = t
                                      cc(1,4) = t
                                      cc(2,4) = t    
                                  
                                      Mat aa() = cc() * bb()
                                  
                                      CDW = GetProcAddress( hLib, "GdipSetImageAttributesColorMatrix" )
                                      Call Dword CDW Using Watermark_GdipSetImageAttributesColorMatrix( imgAttr, 0, %true, m, ByVal 0&, 0) 
                                  
                                      Function = imgAttr
                                  
                                  End Function
                                  Last edited by Edwin Knoppert; 2 Nov 2011, 05:45 AM.
                                  hellobasic

                                  Comment


                                  • #18
                                    Contrast seems odd
                                    Normally
                                    1 -> 0 = Decrease contrast
                                    1 -> n = Increase contrast (n can be large like 500)

                                    Yours
                                    1 -> 0 = Decrease contrast
                                    1 -> n/100 = Increase contrast (n can be large like 50,000)

                                    Brightness seems to be scaled -255 to 255.

                                    At least that's what it looks like without testing.

                                    The last note is that as written I don't think you can ever add additional operations such as rotating hue, shearing, scaling, grayscale, etc. But if that works for you you should be set.

                                    I also assume you're dynamically loading GDI+, but if so is there a fall back for these operations when there's no GDI+?
                                    LarryC
                                    Website
                                    Sometimes life's a dream, sometimes it's a scream

                                    Comment


                                    • #19
                                      I sent a slightly older code, i have renewed it with what we actually use.
                                      Also the input is made clear in the remark.

                                      In fact this the same as the drawimageFX stuff does in v1.1 of gdiplus.
                                      Though it lacks the color depth a little when contrast is set to 100
                                      I don't mind much, it seems ok.

                                      I just would like to have input on the mat stuff i did.

                                      PS,
                                      The input levels are controlled via trackbars, you can't get over 255 for brightness and so on.
                                      hellobasic

                                      Comment


                                      • #20
                                        Awesome, sounds like you're on the right track. In my book the most important thing is does it behave the way you would like it to. The MAT stuff looks fine.
                                        LarryC
                                        Website
                                        Sometimes life's a dream, sometimes it's a scream

                                        Comment

                                        Working...
                                        X