From: dmwick@napier.uwaterloo.ca (Dale Wick)
Subject: Use of ReadPixelArray8/ReadPixelLine8
Summary: I need an example that works, or to find why mine doesn't
Originator: dmwick@napier.waterloo.edu
Keywords: graphics.library v36 SuperKickStart v37.175
Organization: University of Waterloo
Date: Thu, 16 Apr 1992 20:11:27 GMT

	I'm puzzeled about the use of the new functions in graphics.library
(v36) called ReadPixelLine8, ReadPixelArray8, WritePixelArray8, and
WritePixelLine8.
	Can you either solve my problem, or at least direct to a place
where these functions are used successfully?

	Here is the best that I can come up with.  There are notes at the
end of this code about external variables.  Note also that this compiles
without warning under SAS/C 5.10b, with the 2.04 includes.  I got the
examples of how to set up my rastport from 1.3 RKM:Libs&Devs, and my
Release 2 RKM: Inc&autodocs for calling parameters.  The includes came from
the 2.04 Native Developer's Update.

---------------------- Start of code fragment --------------------
/* Mask.c -- graphic designer.  Allows the user to draw a mask for top/side
 * By Dale Wick  92 04 16.  This code is fully public domain.
 */

/* Includes */
#include<stdio.h>
#include<intuition/intuition.h>
#include<graphics/gfxmacros.h>
#include<proto/intuition.h>
#include<proto/graphics.h>

#include"structs.h"

/* The Defines -- for lazy programmers */
#define rp     FirstWindow->RPort

/* The Code -- but is it a secret code? */
void LoadMask(fname)
char * fname;
{
    UWORD i,d,h,w,c;
    struct BitMap bitMap;
    struct RastPort rastPort;
    UBYTE *mask;
    int err=FALSE;          /* TRUE means that there were memory problems, probably */

    h=1; w=rp->BitMap->BytesPerRow<<3; d=rp->BitMap->Depth;

    InitBitMap(&bitMap,d,w,h);
    /* now allocate the memory for the bit planes.  (first clear the pointers) */
    for(i=0;i<d;i++) bitMap.Planes[i]=NULL;
    for(i=0;i<d;i++) 
    {
        if(!(bitMap.Planes[i]=AllocRaster(w,h))) 
	{
            DoAutoRequest("Not enough free memory to create mask",NULL,"Understood");
            err=TRUE;
            break;
        }
    }
    InitRastPort(&rastPort);
    rastPort.BitMap=&bitMap;

    if(!err) 
    {
        /* Loads a mask -- which is simple a picture */
        ShowIFF(FirstScreen,FirstWindow->RPort->BitMap,fname);
        /* Now locate the mask, and scan away -- uses new 2.0 features
         * of graphics.library */
        if(mask=palloc((((w+15)>>4)<<4)*(MaxY-MinY+1))) 
	{
            c=ReadPixelArray8(rp,MinX,MinY,MaxX,MaxY,mask,&rastPort);
            printf("Converted %d pixels.  You'd expect %d or %d though.\n",
                    c,Width*Height,(MaxX-MinX+1)*(MaxY-MinY+1));
            General->xmask=mask;
        } 
	else 
	{
            DoAutoRequest("There isn't enough memory to create mask.  Please try again",NULL,"Understood");
        }
    }

    for(i=0;i<d;i++) 
    {
        if(bitMap.Planes[i])
            FreeRaster(bitMap.Planes[i],w,h);
    }

}
------ End of code fragment -------
	Obviously FirstWindow and FirstScreen are struct Window and struct
	Screen pointers.

	ShowIFF is a routine that I've been using reliably for a while, and
	creates no enforcer hits, so I'm assuming it is clean (it comes from
	iff.library v18.5.

	DoAutoRequest is a function which displays a message and returns
	true or false.

	Width and Height correspond to MaxX-MinX, and MaxY-MinY.

	structs.h is a list of #defines and structs and prototypes.

	The program gives no enforcer hits, but the system locks up soon
	after running this section of code.  I can only assume that I'm
	trashing things that I shouldn't.


		Feel free to send tips/flames/patient explainations,
					Dale
--
dmwick@descartes.uwaterloo.ca		C.S. Major U of Waterloo
u190@cs910.cciw.ca			Coop for Environment Canada's
Compuserve: 76545,2566			National Water Research Institute
BIX, BIX, BIX that's all I ever hear.	Lake's Research Branch.
"You can interpret it much better if I just animate it." - concerning my Amiga