Gray Scale raw image into PICT ?

Gray Scale raw image into PICT ?

Post by Pierre Caro » Fri, 31 Jan 1997 04:00:00


I have to load files where an image is stored as a list of
pixels (Gray Scale) represented in bytes (8 bits/pixel), and
I want to transfer this data in a PICT format to display in
a window.  I know how many bytes per row and how many rows
of data I have in the file, but I have no idea of how, once
I have read the data in a buffer, I can transfer this
sequence of pixels (bytes) into a PICT structure that I will
'SetWindowPic' afterward.

I'd appreciate some hint on the matter please !

Thanks

Pierre Caron
Laboratoire LEINA
Departement de psychologie
Universite du Quebec a Montreal

 
 
 

Gray Scale raw image into PICT ?

Post by Eric Shapi » Wed, 05 Feb 1997 04:00:00




> I have to load files where an image is stored as a list of
> pixels (Gray Scale) represented in bytes (8 bits/pixel), and
> I want to transfer this data in a PICT format to display in
> a window.  I know how many bytes per row and how many rows
> of data I have in the file, but I have no idea of how, once
> I have read the data in a buffer, I can transfer this
> sequence of pixels (bytes) into a PICT structure that I will
> 'SetWindowPic' afterward.

There's no need to transfer the image into a PICT. In fact,
this will only slow your code down.

You should probably just create a GWorld with NewGWorld() and
then read the file directly into the area allocated by NewGWorld.
You can then use CopyBits() to draw into your window whenever
you get an update event.

Something like:

err = NewGWorld( &myGWorld, 8, width, height, myColorTable, ...);
PixMapHandle h = GetGWorldPixMap( myGWorld );
LockPixels( h );
 Ptr rowPtr = GetPixBaseAddr( h );
 long rowBytes = (**h).rowBytes &= 0x3FFF; // clear flag bits
 for ( long rowCount = 0; rowCount < height; rowCount++ )
 {
   err = FSRead( myFileID, &width, rowPtr );
   rowPtr += rowBytes;
 }
UnlockPixels( h );

And then:
HLock( (Handle) h );
LockPixels( h );
SetRect( &r, 0, 0, width, height );
CopyBits( (BitMap*)*h, &myWindow->portBits,&r,&r,srcCopy,nil );
UnlockPixles( h );
HUnlock( (Handle) h );  // or better yet, use HGetState/HSetState

The tricky things are:
 (1) The GWorld structure and sub-structures are a little weird
 (2) The rowBytes in the GWorld will *not* match the rowBytes in
     your file. Thus you have to read the file one line at a time.
     -- There are workarounds to this if speed becomes an issue --
 (3) Make sure you lock the pixels in the GWorld before doing
     anything with them.

 -Eric

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

 Relium Corp.                          www.relium.com

 "Things are only impossible until they are not."            
------------------------------------------------------

 
 
 

1. How to display gray scale images???

You may want to translate the row-data-image to noncompressed-TIFF format.
It's easy, I've done it for satellite-images (header with tags + data).

For information about the TIFF-format you may refer to the group
comp.graphics (read the FAQ-file point 8) or get information via
anonymous ftp from zamenhof.cs.rice.edu in directory pub/graphics.formats

Hope, this may help!

Ciao
    Markus

--
____________________________________________________________
Senoner Markus                          _/      _/    _/_/_/
Computer Science Dept.- Univ. of Milan _/_/  _/_/     _/

2. IBM Ethernet and Lan Manager?

3. Saving gray scale images in .BMP format

4. Remote dump and restore from sgi to sun

5. BC45 View Grey Scale Image?

6. Wanted: A1000 HD SCSI Controller

7. How to scale lots of PICT resources automatically?

8. User Rights on Library-Level

9. Gray Scale Bitmaps, Help needed

10. How to convert true color DIB to gray scale bitmap.

11. Gray Scale Palette Problem

12. Grey scale bitmaps

13. Rollover PICT changes to another alternate image