Solved

need a faster way to draw image

Posted on 1999-01-25
4
171 Views
Last Modified: 2013-12-26
i'm opening a gif and drawing it to the screen one pixel at a time.
even drawing in an offscreen pixmap is painfully slow.
is there a way to poke values directly to a pixmap ?
perhaps load an array of values and use blockMove or something ?
i'm using think c 5.0.4
( yes i know it's time to switch to code warrior )
thanks
0
Comment
Question by:jabes012399
  • 2
4 Comments
 
LVL 2

Expert Comment

by:roov
ID: 1291762
As I recall (and forgive me if I'm wrong) GIFs are run-length-encoded. In such a case, I've seen drastic improvments when in stead setting one pixel at a time you use MoveTo() and LineTo(). In my case, it was a 600% improvement.
0
 

Author Comment

by:jabes012399
ID: 1291763
This actually slows it down more
for me.  Perhaps this question needs to be restated:

Does anyone know how programs like "JPEGView" are able to decode and draw
gif files so quickly ?  I have QuickTime disabled and the offscreen bitmap
option is set to "Never created".  So that leads me to believe that it's
not using QuickTime or offscreen bitmaps.  Yet it amazes me how fast it's
able to draw.  I'm able to decode a gif file rather quickly but still am at
a loss on how to draw it as fast as JPEGView.
0
 
LVL 3

Accepted Solution

by:
boonstra earned 100 total points
ID: 1291764
You haven't shown us your GIF decoding code, so it is possible that part of the problem lies there.  However, you certainly want to access the PixMap memory directly after you have decoded the GIF.  Directly setting the pixels in a tight loop will certainly be faster than using a trap like SetCPixel, or even a QuickDraw routine like LineTo.

JPEGView and other GIF decoders take advantage of the fact that a GIF can by design contain only 256 colors, meaning that the PixMap pixelSize can be set to one byte per pixel.  This allows the byte associated with the pixel at (row,col) to be accessed as:
  *(pm->baseAddr + row*pm->rowBytes + col),
where pm is a PixMapPtr.  For the last ounce of speed, you might also consider coding your innermost loops in assembly language.

Stored at this address is the index of the color in pm->colorTable.

There is much sample code associated with blasting (or "blitting") values to a PixMap.  Among the ones you might want to look at are:

<ftp://dev.apple.com/developer/Sample_Code/Snippets/QuickDraw/Out_of_This_GWorld.sit.hqx>
<ftp://dev.apple.com/developer/Sample_Code/Snippets/QuickDraw/Direct_Pixel_Access.sit.hqx>
<ftp://dev.apple.com/developer/Sample_Code/Snippets/QuickDraw/CopyBits_vs._CopyMask.sit.hqx>
<ftp://dev.apple.com/developer/Sample_Code/QuickDraw/OffSample.sit.hqx>

You can certainly also use BlockMove (or BlockMoveData) to blast data to your PixMap.  But you still would need to move it to an Offscreen PixMap first, which uses the same techniques described above.  For CopyBits insights, you could look (among other places) in the back issues of (shameless plug) MacTech, like:
<http://www.mactech.com/articles/develop/issue_18/043-054_Othmer_REV.html>

Hope this helps.
0
 

Author Comment

by:jabes012399
ID: 1291765
Although I was not able to solve
my problem via the information
submitted by boonstra,  I'm sure the answer does lie there somewhere.  Plus there are some good code examples.  After days of struggling to get it to work,  I went back to a snippet of code that was sent to me from comp.sys.mac.programmer.help and after some reworking of the code, i finally got it to go.

Results are impressive.

I'll post the code if anyone is interested.

-jabes
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now