Solved

need a faster way to draw image

Posted on 1999-01-25
4
176 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
tripleUp challenge 7 86
changeXy challenge 13 89
Is there a simple front-end menu system. 9 104
Increment column based of a FK 8 31
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

831 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