Direct Blitting (Image Processing) and Saving Bitmaps

General help with the Ecere Cross Platform GUI toolkit: Window, common controls, events, etc.
Help with the 2D Graphics library: Surface, Display, Bitmap, Font and others.
Post Reply
sacrebleu
Posts: 27
Joined: Sun Jan 17, 2010 12:37 pm

Direct Blitting (Image Processing) and Saving Bitmaps

Post by sacrebleu »

Please show examples of how to blit directly to a surface such as in this code sample

Code: Select all

     case _Overlay:     // B<128 ? (2*A*B/255) : 255-2*(255-A)*(255-B)/255
         for ( x=0; x< merged.height; x++ ) {
          for ( y=0; y< merged.width; y++ ) {
            ColorRGBA A = *(pixels1);
            ColorRGBA B = *(pixels2);
            *pixels2 = ColorRGBA {
                           (byte) URANGE(0, OVERLAY(A.r,B.r), 255),
                           (byte) URANGE(0, OVERLAY(A.g,B.g), 255),
                           (byte) URANGE(0, OVERLAY(A.b,B.b), 255),
                           (byte) URANGE(0, OVERLAY(A.a,B.a), 255)
                       };
            pixels1++; pixels2++;
          }
          pixels1 += L.source.stride - L.source.width; 
          pixels2 += merged.stride - merged.width; 
         }
Sometimes the math doesn't seem to work out, but this above code may actually work.

Here's another sample:

Code: Select all

Bitmap genStatic( int w, int h, float n ) {
 Bitmap out {};
 int x,y;
 out.Allocate(null,w,h,0,pixelFormatRGBA,false);
 for( x=0; x<w; x++ )
  for ( y=0; y<h; y++ ) { 
   byte c;
   float f= (float) uniform();
   if ( f>0.5 ) c=0;
   else c=255;
   G_Pixel(out,x,y, ColorRGBA { c, c, c, c });
 }
 return out;
}

inline void G_Pixel( Bitmap s, int x, int y, ColorRGBA c ) {
 ((ColorRGBA *)s.picture)[s.stride * y + x] = c;
}

inline void G_PixelRGBA( Bitmap s, int x, int y, int r, int g, int b, int a ) {
 ColorRGBA c { (byte) r, (byte) b, (byte) g, (byte) a };
 ((ColorRGBA *)s.picture)[s.stride * y + x] = c;
}

inline void G_PixelRGB( Bitmap s, int x, int y, int r, int g, int b ) {
 ColorRGBA c { (byte) r, (byte) g, (byte) b, 255 };
 ((ColorRGBA *)s.picture)[s.stride * y + x] = c;
}
jerome
Site Admin
Posts: 608
Joined: Sat Jan 16, 2010 11:16 pm

Re: Direct Blitting (Image Processing) and Saving Bitmaps

Post by jerome »

We don't see the declarations of pixels1 and pixels2 in the first code sample?
And neither do I have any indication of what format the actual Bitmaps are in.

Also note you can do

Code: Select all

 to get syntax highlighting
(Maybe I should make the Code button do that by default!)

[quote="sacrebleu"]Please show examples of how to blit directly to a surface such as in this code sample[/quote]
What kind of surface are we talking about here? A surface from a Window's OnRedraw, or obtained from a Bitmap?

Another interesting note, the JPEG writer will only process bitmaps which are in pixelFormat888, not pixelFormatRGBA. The PNG writer however should handle at least both pixelFormat888 and pixelFormatRGBA. You should be able to call Bitmap::Convert to convert one format into the other.
Post Reply