FLTK logo

STR #161

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 Home  |  Articles & FAQs  |  Bugs & Features  |  Documentation  |  Download  |  Screenshots  ]
 

Return to Bugs & Features | Roadmap 1.1 | SVN ⇄ GIT ]

STR #161

Application:FLTK Library
Status:1 - Closed w/Resolution
Priority:2 - Low, e.g. a documentation error or undocumented side-effect
Scope:2 - Specific to an operating system
Subsystem:MacOS
Summary:OSX fl_read_image() doesn't do anything
Version:1.1.4rc2
Created By:yves.usson
Assigned To:mike
Fix Version:1.1.4
Update Notification:

Receive EMails Don't Receive EMails

Trouble Report Files:

No files


Trouble Report Comments:


Name/Time/Date Text  
 
#1 yves.usson
10:13 Sep 08, 2003
Hi

Here is the bit of code I wrote to have the fl_read_image_mac working.
I send you the code directly because I don't know how to use CVS and all this stuff.
I have tested it quickly and it does  what I expected...

There it is :

//
// 'fl_read_image()' - Read an image from the current window.
//

uchar *                // O - Pixel buffer or NULL if failed
fl_read_image(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)


  Rect src;
  GWorldPtr gWorld = fl_create_offscreen(w,h);
  if (! gWorld ) return 0;
  src.top = y; src.left = x; src.bottom = y+h; src.right = x+w;
  Rect dst;
  dst.top = 0; dst.left = 0; dst.bottom = h; dst.right = w;
  GrafPtr srcPort; GetPort(&srcPort);
  RGBColor rgb;
  rgb.red = 0xffff; rgb.green = 0xffff; rgb.blue = 0xffff;
  RGBBackColor( &rgb );
  rgb.red = 0x0000; rgb.green = 0x0000; rgb.blue = 0x0000;
  RGBForeColor( &rgb );
  CopyBits(GetPortBitMapForCopyBits(srcPort), GetPortBitMapForCopyBits(gWorld), &src, &dst, srcCopy, 0L);
  SetGWorld( gWorld, 0 ); // sets the correct port
  PixMapHandle pm = GetGWorldPixMap(gWorld);
  LockPixels( pm );
  uchar *base = (uchar*)GetPixBaseAddr( pm );
  int rowBytes = (*pm)->rowBytes & 0x3fff;
  uchar *pdest = p;
  for (int idy = 0; idy < h; idy ++)
  {
      uchar *psrce = base + idy * rowBytes;
      for (int idx = 0; idx < w; idx ++)
      {
        psrce++;  // may this should be taken into account if alpha != 0 !!!!!
        *pdest++ = *psrce++;
        *pdest++ = *psrce++;
        *pdest++ = *psrce++;
    }
  }
  UnlockPixels(pm);
  fl_delete_offscreen(gWorld);
  return p;
}

 
 
#2 mike
08:23 Sep 09, 2003
Thanks, I've revised your implementation to correctly support alpha and allocating the pixel buffer if NULL and commited to CVS for the 1.1.4 release.  
     

Return to Bugs & Features ]

 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.