[comp.sys.mac.programmer] Help, greyvalue images on the Macintosh

bartels@haydn.kulesat.uucp (04/03/89)

Dear Macintosh Users,



		I have some problems with writing a program in MPW-C to put 
a grey-value image on the screen. See here mine program: 

#include <Types.h>
#include <Memory.h>
#include <Quickdraw.h>
#include <Palette.h>
#include <Fonts.h>
#include <Events.h>
#include <Menus.h>
#include <Windows.h>
#include <TextEdit.h>
#include <Dialogs.h>
#include <Desk.h>
#include <OSUtils.h>
#include <ToolUtils.h>
#include <SegLoad.h>
#include <stdio.h>

typedef BitMap *BitMapPtr;

main()
{
CWindowPtr ImagePort;
CTabHandle CThan;
Handle Image;
Rect Imagerect;
PixMapHandle ImageMap;
int i;
CWindowRecord wRecord;
long int refCon;

InitGraf(&qd.thePort);
InitFonts();
InitWindows();
InitMenus();
TEInit();
InitDialogs(nil);
InitCursor();

/*opening a window for putting the image in*/
SetRect(&Imagerect,20,20,400,400);
ImagePort = (CWindowPtr) NewCWindow((Ptr) &wRecord,&Imagerect,
             "Mijn eerste beeld",1,documentProc, (WindowPtr) -1 ,0,refCon = 4);
/*intializing of color look up table*/
CThan = (CTabHandle) (NewHandle(255 * 4 + 10));
(*CThan)->ctSeed = GetCTSeed();
(*CThan)->ctFlags = 0;
(*CThan)->ctSize = 256;
for (i=1; i<=255; i++)
  {(*CThan)->ctTable[i].value = i;
   (*CThan)->ctTable[i].rgb.red = (short) (255 * i);
   (*CThan)->ctTable[i].rgb.green = (short) (255 * i);
   (*CThan)->ctTable[i].rgb.blue = (short) (255 * i);};
/* initializing of grey value image */
Image = NewHandle(128*128);
for (i=0; i<=128*128-1; i++)
{*(*Image + i) = (short)(i/255);}
SetRect(&Imagerect,0,0,128,128);
ImageMap = NewPixMap();
(*ImageMap)->baseAddr = *Image;
(*ImageMap)->rowBytes = (0x8000|128);
(*ImageMap)->bounds = Imagerect;
(*ImageMap)->pmTable = CThan;
CopyBits(((BitMapPtr)*ImageMap),((BitMapPtr)*(ImagePort->portPixMap)),
         &Imagerect,&Imagerect,0,0);
}

The program doesn't pass the line 
Image = NewHandle(128*128);
except when I decrease the dimensions of the image to 28 * 28. With the little
image there apears something on the screen but after running the program I had
to restart the computer.

		Now I am searching for some example programs (I prefer C 
programs) to put greyvalue images on the Macintosh screen. Hoping someone 
can help me, I thank you to study mine  problem

					Yours sincerly,
								
									
					Rudi Bartels
					KU Leuven 
					Faculteit der Toegepaste Wetenschappen
					ESAT-MI2
					Kard. Mercierlaan 94
					3030 Heverlee
					Belgium
					email: bartels@kulesat.uucp
					Fax: 32-16-221855

oster@dewey.soe.berkeley.edu (David Phillip Oster) (04/05/89)

In article <991@haydn.kulesat.uucp> bartels@kulesat.uucp writes:
>Image = NewHandle(128*128);

should be Image = NewHandle(128L*128);
If you include a prototype for NewHandle at the beginning of the file:

Handle NewHandle(long);

Think C will handle the number coercion directly.  I have a short C
program that takes as input a text file of postscript, posted in
comp.lang.postscript before the election, and shows Bush in a window.
You also get Bush on your clipboard. I'd be happy to post it, but I've
never been able to reach comp.sys.mac.sources. If some one could help me
find a path, I'll post the program (a K or two) and the data file (40k).

--- David Phillip Oster            --"When we replace the mouse with a pen,
Arpa: oster@dewey.soe.berkeley.edu --3 button mouse fans will need saxophone
Uucp: {uwvax,decvax}!ucbvax!oster%dewey.soe.berkeley.edu --lessons." - Gasee