Beispiel #1
0
/* New pointer to raster returned in pimage */
static int display_size(void *handle, void *device, int width, int height,
    int raster, unsigned int format, unsigned char *pimage)
{
    PixMapPtr pixmap;
    IMAGE *img = image_find(handle, device);
    if (img == NULL)
       return -1;

    /* Check that image is within allowable bounds */
    if (raster > 0x3fff)
    {
       printf("QuickDraw can't cope with an image this big.\n");
       fflush(stdout);
       if (img->pixmapHdl)
       {
           DisposePixMap(img->pixmapHdl);
           img->pixmapHdl = NULL;
       }
       return e_rangecheck;
    }

    /* Create the PixMap */
    if (!img->pixmapHdl)
        img->pixmapHdl = NewPixMap();

    pixmap = *(img->pixmapHdl);
    pixmap->baseAddr = (char*)pimage;
    pixmap->rowBytes = (((SInt16)raster) & 0x3fff) | 0x8000;
    pixmap->bounds.right = width;
    pixmap->bounds.bottom = height;
    pixmap->packType = 0;
    pixmap->packSize = 0;
    pixmap->pixelType = RGBDirect;
    pixmap->pixelSize = 32;
    pixmap->cmpCount = 3;
    pixmap->cmpSize = 8;

    /* Update the display window */
    window_adjust_scrollbars(img->windowRef);
    window_invalidate(img->windowRef);
    return gsdll_poll(handle);
}
Beispiel #2
0
void initialize_shape_handler(
	void)
{
	FSSpec shapes_file;
	OSErr error;

	/* open the resource fork of our shape file for reading */
	error= get_file_spec(&shapes_file, strFILENAMES, filenameSHAPES8, strPATHS);
	if (error==noErr)
	{
		open_shapes_file(&shapes_file);
	}
	
	if (error!=noErr || shapes_file_refnum==-1)
	{
		alert_user(fatalError, strERRORS, badExtraFileLocations, error);
	}
	else
	{
		atexit(shutdown_shape_handler);
	}

	hollow_pixmap= NewPixMap();
	assert(hollow_pixmap);
	if (HOLLOW_PIXMAP_BUFFER_SIZE)
	{
		hollow_data= (pixel8 *)NewPtr(HOLLOW_PIXMAP_BUFFER_SIZE);
		assert(hollow_data);
	}

	/* bounds and rowBytes are deliberately unset! */
	(*hollow_pixmap)->pixelType= 0;
	(*hollow_pixmap)->pixelSize= 8;
	(*hollow_pixmap)->cmpCount= 1;
	(*hollow_pixmap)->cmpSize= (*hollow_pixmap)->pixelSize;
	(*hollow_pixmap)->pmReserved= 0;

	return;
}
Beispiel #3
0
static void SetUpPixmap(void) {
	int i, r, g, b;

	stColorTable = (CTabHandle) NewHandle(sizeof(ColorTable) + (256 * sizeof(ColorSpec)));
	(*stColorTable)->ctSeed = GetCTSeed();
	(*stColorTable)->ctFlags = 0;
	(*stColorTable)->ctSize = 255;

	/* 1-bit colors (monochrome) */
	SetColorEntry(0, 65535, 65535, 65535);	/* white or transparent */
	SetColorEntry(1,     0,     0,     0);	/* black */

	/* additional colors for 2-bit color */
	SetColorEntry(2, 65535, 65535, 65535);	/* opaque white */
	SetColorEntry(3, 32768, 32768, 32768);	/* 1/2 gray */

	/* additional colors for 4-bit color */
	SetColorEntry( 4, 65535,     0,     0);	/* red */
	SetColorEntry( 5,     0, 65535,     0);	/* green */
	SetColorEntry( 6,     0,     0, 65535);	/* blue */
	SetColorEntry( 7,     0, 65535, 65535);	/* cyan */
	SetColorEntry( 8, 65535, 65535,     0);	/* yellow */
	SetColorEntry( 9, 65535,     0, 65535);	/* magenta */
	SetColorEntry(10,  8192,  8192,  8192);	/* 1/8 gray */
	SetColorEntry(11, 16384, 16384, 16384);	/* 2/8 gray */
	SetColorEntry(12, 24576, 24576, 24576);	/* 3/8 gray */
	SetColorEntry(13, 40959, 40959, 40959);	/* 5/8 gray */
	SetColorEntry(14, 49151, 49151, 49151);	/* 6/8 gray */
	SetColorEntry(15, 57343, 57343, 57343);	/* 7/8 gray */

	/* additional colors for 8-bit color */
	/* 24 more shades of gray (does not repeat 1/8th increments) */
	SetColorEntry(16,  2048,  2048,  2048);	/*  1/32 gray */
	SetColorEntry(17,  4096,  4096,  4096);	/*  2/32 gray */
	SetColorEntry(18,  6144,  6144,  6144);	/*  3/32 gray */
	SetColorEntry(19, 10240, 10240, 10240);	/*  5/32 gray */
	SetColorEntry(20, 12288, 12288, 12288);	/*  6/32 gray */
	SetColorEntry(21, 14336, 14336, 14336);	/*  7/32 gray */
	SetColorEntry(22, 18432, 18432, 18432);	/*  9/32 gray */
	SetColorEntry(23, 20480, 20480, 20480);	/* 10/32 gray */
	SetColorEntry(24, 22528, 22528, 22528);	/* 11/32 gray */
	SetColorEntry(25, 26624, 26624, 26624);	/* 13/32 gray */
	SetColorEntry(26, 28672, 28672, 28672);	/* 14/32 gray */
	SetColorEntry(27, 30720, 30720, 30720);	/* 15/32 gray */
	SetColorEntry(28, 34815, 34815, 34815);	/* 17/32 gray */
	SetColorEntry(29, 36863, 36863, 36863);	/* 18/32 gray */
	SetColorEntry(30, 38911, 38911, 38911);	/* 19/32 gray */
	SetColorEntry(31, 43007, 43007, 43007);	/* 21/32 gray */
	SetColorEntry(32, 45055, 45055, 45055);	/* 22/32 gray */
	SetColorEntry(33, 47103, 47103, 47103);	/* 23/32 gray */
	SetColorEntry(34, 51199, 51199, 51199);	/* 25/32 gray */
	SetColorEntry(35, 53247, 53247, 53247);	/* 26/32 gray */
	SetColorEntry(36, 55295, 55295, 55295);	/* 27/32 gray */
	SetColorEntry(37, 59391, 59391, 59391);	/* 29/32 gray */
	SetColorEntry(38, 61439, 61439, 61439);	/* 30/32 gray */
	SetColorEntry(39, 63487, 63487, 63487);	/* 31/32 gray */

	/* The remainder of color table defines a color cube with six steps
	   for each primary color. Note that the corners of this cube repeat
	   previous colors, but simplifies the mapping between RGB colors and
	   color map indices. This color cube spans indices 40 through 255.
	*/
	for (r = 0; r < 6; r++) {
		for (g = 0; g < 6; g++) {
			for (b = 0; b < 6; b++) {
				i = 40 + ((36 * r) + (6 * b) + g);
				SetColorEntry(i, (r * 65535) / 5, (g * 65535) / 5, (b * 65535) / 5);
			}
		}
	}

	stPixMap = NewPixMap();
	(*stPixMap)->pixelType = 0; /* chunky */
	(*stPixMap)->cmpCount = 1;
	(*stPixMap)->pmTable = stColorTable;
}
void createOffscreen()
{
	Rect		rect;
	Handle		iclHandle;
	char		*image;
	int			row, col, index, value;
	
	
	SetRect( &rect, 0, 0, 32, 32 );
	
	/* Create offscreen pixmap image using an 'icl8' icon resource. */

	iclHandle = GetResource( 'icl8', 129 );
    HandToHand( &iclHandle );
    HLock( iclHandle );
	HNoPurge( iclHandle );
	
	//gPixmap = (PixMapHandle)NewHandle( sizeof( PixMap ) );
	gPixmap = NewPixMap();
	
	(**gPixmap).baseAddr = *iclHandle;
	(**gPixmap).rowBytes = ((32 * 8) / 8) | 0x8000;
	(**gPixmap).bounds = rect;
	(**gPixmap).pmVersion = 0;
	(**gPixmap).packType = 0;
	(**gPixmap).packSize = 0;
	(**gPixmap).hRes = 72;
	(**gPixmap).vRes = 72;
	(**gPixmap).pixelSize = 8;
	//(**gPixmap).planeBytes = 0;
	//(**gPixmap).pmReserved = 0;
	(**gPixmap).pixelType = 0;
	(**gPixmap).cmpCount = 1;
	(**gPixmap).cmpSize = 8;
	(**gPixmap).pmTable = GetCTable( 8 );
	(**gPixmap).pixelFormat = 0;
	
	/* Give a unique seed for the pixmap's colortable. */
	(**(**gPixmap).pmTable).ctSeed = GetCTSeed();
	
	SetRect( &rect, 0, 0, 20, 20 );
	
	/* Set the pointer to the beginning of the pixel image. */
	image = GetPixBaseAddr( gPixmap );
	
	/*****************************************************************/
	/* For this example, let's set the pixel values of the left half */
	/*   of the image to half their original values.				 */
	/*****************************************************************/
	
	for (row = 0; row < rect.bottom; row++)
	{
		// Loop through the first 10 columns of the pixel image. 
		for (index = 0, col = 0; col < rect.right / 2; col++)
		{
			// Set the value at this index to half its value. 
			value = (unsigned char)*(image + index);
			*(image + index) = value / 2;
			
			index++;
		}
		
		// Increment the pointer to the next row of the pixel image. 
		image += ((**gPixmap).rowBytes & 0x7fff);
	}

}