Path: utzoo!utgpu!attcan!uunet!yale!husc6!huma1!fry From: fry@huma1.HARVARD.EDU (David Fry) Newsgroups: comp.sys.mac.programmer Subject: Re: Help with setting pixel color Message-ID: <5057@husc6.harvard.edu> Date: 2 Aug 88 12:46:41 GMT References: <77900003@peterson> <1668@microsoft.UUCP> Sender: news@husc6.harvard.edu Reply-To: fry@huma1.UUCP (David Fry) Organization: Harvard Math Department Lines: 44 In article <1668@microsoft.UUCP> t-benw@microsoft.UUCP (Benjamin Waldman) writes: >In article <77900003@peterson> peterson@peterson.applicon.UUCP writes: >> >>I would like to be able to set a pixel to a color using the color index >>number rather than RGB (as in SetPixel(RGB Color)). >> >>I can use SetPixel, but it is much too slow for filling a window with >>pixels (as in a grey scale picture). Maybe I am missing "the" way to >>draw an image into a window. Can anyone help? I am new to color quickdraw! > >Have you read the Palette Manager manual? >If you want to draw an image with certain colors, create a palette with >those colors, and them use PmForeColor to set the color (you'll be setting >a number corresponding to the palette position of your RGB color), and then >use LineTo or something (this is also neat if you have run length encoded >image data - if you have 10 pixels with the same value, do 1 PmForeColor, >and then a Line to 10 pixels down the line). > >Unfortunately, I have no sample code, but good luck anyway. This is certainly the "standard" way of drawing pixel data, but it is mind-numbingly slow. Much faster, and quite adequate, is to create an offscreen PixMap, stuff the pixel values into data structure, and then CopyBits that onto the screen. It's about 2000% faster, if not more. First determine the color you want the pixel to be, say MyColor, and then do a Color2Index() call to the index of that color (or the closest) on the current color table. Put that value in the PixMap structure. If you have an 8-bit image, say, with only 256 colors, you can call the 256 Color2Index()'s at the beginning of the loop and you need only move memory, which is very fast, with no toolbox calls, which is relatively slow. If you're squeamish about offscreen PixMaps, and most people seem to be, I recommend Knaster's "Macintosh Programming Secrets," which has an extremely lucid account, with sample code. David Fry fry@huma1.harvard.EDU Department of Mathematics fry@huma1.bitnet Harvard University ...!harvard!huma1!fry Cambridge, MA 02138