Solved

need a faster way to draw image

Posted on 1999-01-25
4
181 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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
Get filename and folder into excel 7 84
wordcount challenge 11 145
Can not remove SSL certificate on iPhone 6 - iOS10.2 12 1,294
Capture logon name 13 104
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

756 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