Solved

need a faster way to draw image

Posted on 1999-01-25
4
162 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

728 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

9 Experts available now in Live!

Get 1:1 Help Now