Confused about NewPicture, RGBsurfaces, etc. 
Author Message
 Confused about NewPicture, RGBsurfaces, etc.

I want to open a jpeg, display it, and analyze it on a pixel-by-pixel
basis. (Sort of like generating a histogram, but more complicated.) I'm
not sure how many "pictures" I need to do this.

I understand (or I THINK I understand) the following:

1) If I want to count all the individual pixels of my JPEG, it will much
faster to use an RGBSurface than the graphics.pixel property.
2) In order to have an RGBsurface, I need to call NewPicture(x,y,32).

I've written a {*filter*} test program (using GetOpenFolderItem and
OpenAsPicture) that lets the user choose the JPEG file and then displays
the image in a window. All of that is working fine. So far, I'm using
the window's backdrop property to display the picture - but in doing
this, I don't get access to the RGBSurface, do I?

It seems like I need to have several pictures in memory to make this
work, and I'm worried about speed and memory issues. (I would eventually
like to be able to drag a batch of jpegs over and drop them all onto the
app at once!) Is the following correct:

1) Pic1 will receive the OpenAsPicture call
2) Now that I've got Pic1 (so that I can determine the x and y of the
JPEG) I need to create Pic2 with the NewPicture(x,y,32) call. (This
gives me a picture with an RGBSurface of the correct size.)
3) Then I use DrawPicture to copy Pic1 into Pic2. Now Pic2's RGBSurface
contains the JPEG so I can do my statistical analysis of each pixel.*
4) I still need to display the JPEG. Since a hi-res JPEG often contains
more pixels than most monitors, I'll need to scale the picture into the
window's backdrop property. (Or into a canvas or imagewell - but I don't
see why they would be preferable to the window's backdrop in this case.)
So I'll need to use DrawPicture again, to copy Pic2 into the window's
backdrop property, with dest and source parameters as needed to scale
it. **

So I'm ending up with _three_ pictures - Pic1, that receives the image
from the OpenAsPicture call, Pic2, that contains an RGBsurface, and the
picture that's displayed in the window's backdrop. I'm also concerned
about two calls to DrawPicture. How fast is it? Is there a quicker way
to copy the pictures back and forth?

This all seems terribly wasteful to me, especially in this day of 5+
megapixel cameras. (20 jpegs * 5 megapixels * 3 pictures for each jpeg!)
Is there some way I can streamline this?

If I'm careful how I let Pic1 and Pic2 go out of scope, do I avoid
memory problems? For example, does Pic1 get disposed of here (*)(after
Step 3) if I don't refer to it again? Does Pic2 get disposed of here
(**)? Is their memory freed up or does it just become fragmented?

Thanks for your help,

Chip
(who started programming when 64K ("K" as in Kaypro) was considered a
lot of memory, and always liked the "under the hood" feeling one gets
from working in C or assembly.)



Mon, 03 May 2004 02:50:02 GMT  
 Confused about NewPicture, RGBsurfaces, etc.

Quote:

> So I'm ending up with _three_ pictures - Pic1, that receives the image
> from the OpenAsPicture call, Pic2, that contains an RGBsurface, and the
> picture that's displayed in the window's backdrop.

Nope, only two.  Whatever's displayed on the screen does not take up
your application's RAM.  And two is only temporary, you can dump Pic1
after you're done copying to Pic2.  (Though, as I understand it, this
would not be desirable for vector images -- in such a case, Pic2 would
contain a pixmap of the vector image at a certain size, while Pic1
would scale much better.  But JPEG images don't fit that category.)

--
Thomas Reed



Mon, 03 May 2004 02:58:39 GMT  
 Confused about NewPicture, RGBsurfaces, etc.


[snipped]

Thanks once again, Joe - I really appreciate your help!

Chip



Mon, 03 May 2004 09:43:06 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Confused about versions: FreeRIDE,Fox,FXRuby, etc.

2. confused if i should be doing type checking in the code ( a confused java programmer)

3. confused if i should be doing type checking in the co de ( a confused java programmer)

4. newpicture-failure ?

5. newPicture is there a delete?

6. Trouble with Newpicture and windows

7. RGBSurface

8. RGBsurface and external LUTs

9. RGBSurface, important note!

10. RGBSurface

11. RGBSurface samples

12. Algorithm etc etc

 

 
Powered by phpBB® Forum Software