[comp.sys.mac.programmer] Correct way to set pixels?

wolf@piquet.cipl.uiowa.edu (Michael J. Wolf) (05/03/91)

What is the proper and endorsed manner to set and clear pixels in a window?

I would like to be able to do somethig like a fatbits editor.

Thanks.

Michael

stevec@Apple.COM (Steve Christensen) (05/04/91)

wolf@piquet.cipl.uiowa.edu (Michael J. Wolf) writes:
>What is the proper and endorsed manner to set and clear pixels in a window?
>
>I would like to be able to do somethig like a fatbits editor.

Well, certainly one way of doing it is something like this:

	ForeColor(pixelOn ? BlackColor : WhiteColor);
	MoveTo(h,v);
	Line(1,0);

This will draw a 1-pixel-long line.  There's no QuickDraw routine to touch a
single pixel...

steve

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Steve Christensen			Never hit a man with glasses.
  stevec@apple.com			Hit him with a baseball bat.

nerm@Apple.COM (Dean Yu) (05/04/91)

In article <52427@apple.Apple.COM> stevec@Apple.COM (Steve Christensen) writes:
>wolf@piquet.cipl.uiowa.edu (Michael J. Wolf) writes:
>>What is the proper and endorsed manner to set and clear pixels in a window?
>>
>>I would like to be able to do somethig like a fatbits editor.
>
>Well, certainly one way of doing it is something like this:
>
>	ForeColor(pixelOn ? BlackColor : WhiteColor);
>	MoveTo(h,v);
>	Line(1,0);
>
>This will draw a 1-pixel-long line.  There's no QuickDraw routine to touch a
>single pixel...
>

  Actually, Line(0,0) will draw a single pixel...

  -- Dean Yu
     Blue Meanie, Negative Ethnic Role Model, etc.
     Apple Computer, Inc.
     My opinion and so on and so forth...

keith@Apple.COM (Keith Rollin) (05/04/91)

In article <52431@apple.Apple.COM> nerm@Apple.COM (Dean Yu) writes:
>In article <52427@apple.Apple.COM> stevec@Apple.COM (Steve Christensen) writes:
>>wolf@piquet.cipl.uiowa.edu (Michael J. Wolf) writes:
>>>What is the proper and endorsed manner to set and clear pixels in a window?
>>>
>>>I would like to be able to do somethig like a fatbits editor.
>>
>>Well, certainly one way of doing it is something like this:
>>
>>	ForeColor(pixelOn ? BlackColor : WhiteColor);
>>	MoveTo(h,v);
>>	Line(1,0);
>>
>>This will draw a 1-pixel-long line.  There's no QuickDraw routine to touch a
>>single pixel...
>>
>
>  Actually, Line(0,0) will draw a single pixel...
>

SetCPixel() will touch a single pixel if you are running under Color
QuickDraw and dealing with a color port. If that's not the case, then
you can fill in a pixel with a single QuickDraw call:

	r.top = v; r.left = h; r.bottom = v+1; r.right = h+1;
	PaintRect(&r);

-- 
------------------------------------------------------------------------------
Keith Rollin  ---  Apple Computer, Inc. 
INTERNET: keith@apple.com
    UUCP: {decwrl, hoptoad, nsc, sun, amdahl}!apple!keith
"But where the senses fail us, reason must step in."  - Galileo

rasnow@bek-mc.caltech.edu (Brian Rasnow) (05/07/91)

The Think C profiler tells me Line(1,0) and Line(0,1) are nearly twice as slow
as Line(1,1).  Anyone know why?  It seems there should be a faster (legal) way
to set a pixel.

		Brian

Brian Rasnow, Caltech, 216-76, Pasadena, CA 91125
rasnow@bek-mc.cns.caltech.edu
rasnow@caltech.bitnet

rotberg@dms.UUCP (Ed Rotberg) (05/07/91)

From article <1991May7.041053.28488@nntp-server.caltech.edu>, by rasnow@bek-mc.caltech.edu (Brian Rasnow):
> The Think C profiler tells me Line(1,0) and Line(0,1) are nearly twice as slow
> as Line(1,1).  Anyone know why?  It seems there should be a faster (legal) way
> to set a pixel.


How about PutPixel() (or is it PutRGBPixel()?).  This is defined in IM V.
I'm not sure just how fast it is, but it probably deon't need to go through
any algorithmic loops at all.

Hope this helps.

	- Ed Rotberg -

stevec@Apple.COM (Steve Christensen) (05/08/91)

In article <1243@dms.UUCP> rotberg@dms.UUCP (Ed Rotberg) writes:
>that rasnow@bek-mc.caltech.edu (Brian Rasnow) wrote:
>> The Think C profiler tells me Line(1,0) and Line(0,1) are nearly twice as
>> slow as Line(1,1).  Anyone know why?  It seems there should be a faster
>> (legal) way to set a pixel.
>
>
>How about PutPixel() (or is it PutRGBPixel()?).  This is defined in IM V.
>I'm not sure just how fast it is, but it probably deon't need to go through
>any algorithmic loops at all.

Well, as was pointed out to me, you could call SetCPixel() if your code will
only run on a color Mac.  Since this call doesn't exist on the older black
and white Macs, I suggested doing a MoveTo/LineTo to draw the pixel, since
that will work on all Macs.  There's no single QuickDraw call on both b&w
and color Macs that does the job.

If the bits you want to blast to the screen are in the right order, you could
just use CopyBits to blit it onto the screen...

steve

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Steve Christensen			Never hit a man with glasses.
  stevec@apple.com			Hit him with a baseball bat.