[comp.sys.mac.programmer] Quick drawing

aberno@questor.wimsey.bc.ca (Anthony Berno) (12/16/90)

Hello, I'm a part-time Mac "programmer" (I don't know if I can elevate
myself to that status yet) that is working on real-time data acquisition
and analysis applications for the Mac II. I have a couple of things that
I would like some advice on.

First, I am trying to get a really fast way of doing 2-d color histograms.
This, of course, involves drawing LOTS of little color rectangles on the
screen. When drawing a little 2x2 rectangle, there are many ways of
doing it. You can use FrameRect, PaintRect, use a pen, etc. But what is
the fastest? I would rather avoid assembly language. Also, there are
a lot of colors that I have to use, usually about 10-20 absolute colors.
Would I get faster results if I were to bypass the Palette Manager and 
use lower-level tricks to get the right colors in the right rectangles?
And what about larger rectangles, up to 8x8 pixels?

Also, although this may sound kind of silly, I CANNOT figure out from
Inside Macintosh how to do something very simple - take a portion of
the image in a color window and save it to disk as a color PICT file.
A general pointer on how to do this (no pun intended) would be very
highly appreciated.

Thanks a 1,048,576.
-Anthony.

russotto@eng.umd.edu (Matthew T. Russotto) (12/17/90)

In article <PcZ9T3w163w@questor.wimsey.bc.ca> aberno@questor.wimsey.bc.ca (Anthony Berno) writes:
>
>First, I am trying to get a really fast way of doing 2-d color histograms.
>This, of course, involves drawing LOTS of little color rectangles on the
>screen. When drawing a little 2x2 rectangle, there are many ways of
>doing it. You can use FrameRect, PaintRect, use a pen, etc. But what is
>the fastest?
Try it a few different ways and see-- I tend to suspect the differences won't
be noticeable.

>I would rather avoid assembly language. Also, there are
>a lot of colors that I have to use, usually about 10-20 absolute colors.
>Would I get faster results if I were to bypass the Palette Manager and 
>use lower-level tricks to get the right colors in the right rectangles?
>And what about larger rectangles, up to 8x8 pixels?
Use the Palette Manager-- it simplifies your programming quite a bit, and if
you use PMForeColor, it is faster than SetRGBColor, because it doesn't have
to do a Color2Index.  Writing directly to the screen is a real pain-- you have
to contend with the different bitmap formats, it isn't worth it.

>Also, although this may sound kind of silly, I CANNOT figure out from
>Inside Macintosh how to do something very simple - take a portion of
>the image in a color window and save it to disk as a color PICT file.
>A general pointer on how to do this (no pun intended) would be very
>highly appreciated.
OpenPicture()
CopyBits(&WinPixMap,&WinPixMap, &srcrect, &srcrect, srcCopy, NULL);
ClosePicture().

That's the picture-- you now merely write it out to disk according to the PICT
format (in IM V and the tech notes)
--
Matthew T. Russotto	russotto@eng.umd.edu	russotto@wam.umd.edu
     .sig under construction, like the rest of this campus.

oster@well.sf.ca.us (David Phillip Oster) (12/17/90)

In article <PcZ9T3w163w@questor.wimsey.bc.ca> aberno@questor.wimsey.bc.ca (Anthony Berno) writes:
>This, of course, involves drawing LOTS of little color rectangles on the
>screen. When drawing a little 2x2 rectangle, there are many ways of
>doing it. You can use FrameRect, PaintRect, use a pen, etc. But what is
>the fastest?
The fastest way is to 
1.) Use an offscreen pixmap with the same longword alignment as the 
destination window. The new offscreen support from Apple may help here.
2.) make sure the offscreen pixmap has the same color table as the destination
window.
3.) Draw all your 2x2 rectangles with 4 assignment statements.
(if you align things right, you can draw a 2x2 rectangle in 2 16-bit
assignment statements. Can't get much faster than that.)
4.) when they arer all drawn, CopyBits the entire offscreen pixmap to
the destination window. This gives you the benefits of QuickDraw to
handle video in other address spaces, and clipping against partially obscrured
windows, but you pay for the overhead only once.

>Also, although this may sound kind of silly, I CANNOT figure out from
>Inside Macintosh how to do something very simple - take a portion of
>the image in a color window and save it to disk as a color PICT file.

There was a tecch note about this. First, get a PicHandle.
	OpenPicture();
	CopyBits()
	ClosePicture()
is the basic idea here. Then you can either do a PutScrap() to put
the picHandle on the clipboard, or you can write it to a file of type
PICT after a header of 512? bytes of zero.
-- 
-- David Phillip Oster - At least the government doesn't make death worse.
-- oster@well.sf.ca.us = {backbone}!well!oster

daven@svc.portal.com (12/26/90)

In article <PcZ9T3w163w@questor.wimsey.bc.ca> aberno@questor.wimsey.bc.ca (Anthony Berno) writes:
> 
> First, I am trying to get a really fast way of doing 2-d color histograms.
> This, of course, involves drawing LOTS of little color rectangles on the
> screen. When drawing a little 2x2 rectangle, there are many ways of
> doing it. You can use FrameRect, PaintRect, use a pen, etc. But what is
> the fastest? I would rather avoid assembly language.

My hunch is that setting the pen to the width of the rect, and drawing
the rect as a line would produce the fastest results.

> And what about larger rectangles, up to 8x8 pixels?

The above idea ought to work fine, even for a line 8 pixels wide.


-- 
-------------------------------------------------------------------------------
   Dave Newman              |  daven@svc.portal.com        |  AppleLink: D0025
   Sofware Ventures Corp.   |  AOL: MicroPhone             |  CIS: 76004,2161
   Berkeley, CA  94705      |  WELL: tinman@well.sf.ca.us  |  (415) 644-3232