DO NOT REPLY TO THIS MESSAGE.  INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.

[STR New]

Link: http://www.fltk.org/str.php?L2257
Version: 1.3-current


Alex Croy posted this to the fltk.dev list - I'm appending it here so we
don't lose it...

--------------

the problem is that the current implementation of fl_read_image seems to
make a screenshot of the current view (?) instead of accessing the
offscreen bitmap. I think I found a solution for this with the routine
below.

However, there is an additional problem: fl_begin_offscreen and
fl_end_offscreen currently do not reset (or clear) the clipping region,
which doesn't matter if your make a screenshot.
The respective code is actually commented out in Fl_Double_Window. IMHO
the calls to fl_push_no_clip and fl_pop_clip should be the last and first
calls in l_begin_offscreen and fl_end_offscreen, respectively.

Hope that helps somehow ...

- Alex

--------------------
Here comes the "new" fl_read_image routine:

uchar *                         // O - Pixel buffer or NULL if failed
fl_read_image_crutch( uchar *p, // I - Pixel buffer or NULL to allocate
              int   x,          // I - Left position
              int   y,          // I - Top position
              int   w,          // I - Width of area to read
              int   h,          // I - Height of area to read
              int   alpha) {    // I - Alpha value for image (0 for none)

  if(fl_window == (void *)0)   {  // sufficient condition for having an
                                  // active offscreen buffer??

    CGContextRef src = (CGContextRef)fl_gc;   // get bitmap context

    uchar *base = (uchar *)CGBitmapContextGetData(src);  // get data

    if(!base) return NULL;

    int sw = CGBitmapContextGetWidth(src);
    int sh = CGBitmapContextGetHeight(src);
    // CGImageAlphaInfo bmpalpha = CGBitmapContextGetAlphaInfo(src);
    int rowBytes = CGBitmapContextGetBytesPerRow(src);
    int delta = CGBitmapContextGetBitsPerPixel(src)/8;

    if( (sw - x > w) || (sh - y > h) )  return NULL;

    // Allocate the image data array as needed...
    int d = alpha ? 4 : 3;

    printf("%i %i %i %i %i\n", sw, sh, rowBytes, delta, d);   // DEBUG

    if (!p) p = new uchar[w * h * d];
    // Initialize the default colors/alpha in the whole image...
    memset(p, alpha, w * h * d);

    // Copy the image from the off-screen buffer to the memory buffer.
    int    idx, idy;    // Current X & Y in image
    uchar *pdst, *psrc;
    for (idy = 0, pdst = p; idy < h; idy ++) {
      for (idx = 0, psrc = base + (idy + y) * rowBytes + x; idx < w; idx
++, psrc += delta, pdst += d) {
        pdst[0] = psrc[0];  // R
        pdst[1] = psrc[1];  // G
        pdst[2] = psrc[2];  // B
      }
    }
    return p;
  }
  else  {   // no active offscreen, use "old code"
    return fl_read_image(p, x, y, w, h, alpha);
  }
}


Link: http://www.fltk.org/str.php?L2257
Version: 1.3-current

_______________________________________________
fltk-bugs mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-bugs

Reply via email to