Esempio n. 1
0
LPTR EXPORT grabber_frame_ptr( int Depth, int x, int y, BOOL bModify )
/************************************************************************/
{
	if (Depth == -1)
		return(FramePointerRaw(frame_set(NULL), x, y, bModify));
	else
		return(FramePointer(frame_set(NULL), x, y, bModify));
}
Esempio n. 2
0
void RemoveCodedBackground()
{
    LPFRAME lpFrame;
    int x, y;
    int Width;
    int Height;
    LPTR lpSrcLine;
    BYTE r, g, b;
    
    if (!lpImage) return;
    ImgCombineObjects(lpImage, TRUE, FALSE, TRUE);
    lpFrame = ImgGetBaseEditFrame(lpImage);
    if (!lpFrame) return;
    Width  = FrameXSize (lpFrame);
    Height = FrameYSize (lpFrame);

    for (y=0;y<Height;y++)
    {
	    AstralClockCursor( y, Height, NO );
        lpSrcLine = FramePointer (lpFrame,0,y,TRUE);

        for (x=0;x<Width;x++)
        {
            RGBS Pixel;
            FrameGetRGB (lpFrame,lpSrcLine,&Pixel,1);
            r = Pixel.red;
            g = Pixel.green;
            b = Pixel.blue;

            if (r >= 100 && !g && !b)
            { // a dot
                Pixel.red   = 255;
                Pixel.green = 255;
                Pixel.blue  = 255;
                FrameSetRGB (lpFrame,&Pixel,lpSrcLine,1);
            }
			else
            if ( (r != g) || (g != b) )
            { // not white or black
                Pixel.red   = 0;
                Pixel.green = 0;
                Pixel.blue  = 0;
                FrameSetRGB (lpFrame,&Pixel,lpSrcLine,1);
            }
            lpSrcLine += 3;
            
        } // Width
    }     // Height
}
Esempio n. 3
0
static BOOL NEAR PathIsClear (int x1,int y1,int x2,int y2)
{
    BOOL bClear = TRUE;
    int  i;
    LPFRAME lpFrame = ImgGetBaseEditFrame (lpImage);

    nNumLinePoints = 0;
    ddaline (x1,y1,x2,y2, (LPPOINTFUNC)MazeLineProc);
    for (i = 0; i < nNumLinePoints; i++)
    {
        RGBS Pixel;
        LPTR lpLine = FramePointer (lpFrame,
            MazeLinePoints[i].x,MazeLinePoints[i].y,FALSE);

        FrameGetRGB (lpFrame,lpLine,&Pixel,1);
        if (!Pixel.red && !Pixel.green && !Pixel.blue)
        {
            bClear = FALSE;
            break;
        }
    }
    return bClear;
}
Esempio n. 4
0
BOOL ObjGetLine(LPOBJECT lpObject, int x, int y, int dx, LPTR lpOut)
/************************************************************************/
{
	LPALPHA     lpAlpha;
	LPTR        lp;
	LPPROCESSPROC lpProcessProc;
	RECT        rLine, rSect;
	int         nPixels, ox, oy, depth;
	FRMTYPEINFO TypeInfo;
	FRMDATATYPE DataType;
	long        lOffset;
	LPFRAME		lpFrame;

	// fill buffer with base image object
	// use depth of base image object
	lpFrame = ObjGetEditFrame(lpObject);
	FrameGetTypeInfo(lpFrame, &TypeInfo);
	DataType = TypeInfo.DataType;
	depth = FrameDepth(lpFrame);
	if (TypeInfo.DataType == FDT_LINEART)
	{
    	depth = 1;
    	TypeInfo.DataType = FDT_GRAYSCALE;
	}

	if (!ObjGetLineAlloc(dx, depth))
   	{
    	//Message(IDS_EMEMALLOC);
    	return(FALSE);
   	}

	if (!FrameRead(lpFrame, x, y, dx, lpOut, dx))
    	return(FALSE);

	// setup rect for this line for intersect check
	rLine.left = x;
	rLine.right = x + dx - 1;
	rLine.top = rLine.bottom = y;
	// start with first object on top of base image

	while(lpObject = lpObject->lpNext)
   	{
    	// if object cannot be rendered through raster means
    	if (lpObject->fDeleted || 
        	!AstralIntersectRect(&rSect, &lpObject->rObject, &rLine))
        	continue;

        // get merge proc for this object
        lpProcessProc = GetProcessProc(lpObject->MergeMode, DataType);

        ox = rSect.left-lpObject->rObject.left;
        oy = y-lpObject->rObject.top;
        nPixels = (rSect.right - rSect.left + 1);
        lOffset = (long)(rSect.left - rLine.left) * depth;
        lp = FramePointer(ObjGetEditFrame(lpObject), ox, oy, NO, nPixels);
        if (lp)
        {
        	if (lpAlpha = ObjGetAlpha(lpObject))
            {
            	MaskLoad(lpAlpha, ox, oy, nPixels, lpGLMaskBuf);
            	if (lpObject->Opacity != 255)
                	ScaleData8(lpGLMaskBuf, nPixels, lpObject->Opacity);
            }
        	else
            	set(lpGLMaskBuf, nPixels, lpObject->Opacity);
        	(*lpProcessProc)(lpOut+lOffset, lp, lpGLMaskBuf, nPixels);
        }
    }
	return(TRUE);
}
Esempio n. 5
0
BOOL CWriteBitmap::GIFWrite()
{
	GIFHDR      hdr;
	GIFDESC     imDesc;
	GIFMAP      ColorMap;
	int         y, i, j, npix, nlin;
	LPTR        lp, lpBuffer, lpImgScanline;
	BYTE        cTerm;
	int         codeSize;
	RECT        rSave;
	BOOL        bEscapable;
	BOOL        compressInit;
	LPLZW_STUFF lpLZW;
	LPRGB lpRGBmap;
	LPFRAME lpFrame;
	LPOBJECT lpObject;
	FRMTYPEINFO inType, outType, inTypeLA, outTypeLA;
	CFrameTypeConvert TypeConvert, LineArtConvert;
	BOOL fRet = FALSE;
	CFile 	theFile;
	CFile*	pTheFile = NULL;

	if (m_lpObjList)
	{
		lpObject = m_lpObjList->lpHead;
		if (lpObject)
			lpFrame = ObjGetEditFrame(lpObject);
	}
	else
	{
		lpFrame = m_lpFrame;
		lpObject = NULL;
	}

	ASSERT(lpFrame);
	
	ProgressBegin(1);
	if ((pTheFile = OpenFile()) == NULL)
	{
		ProgressEnd();
		return(FALSE);
	}

	TRY
	{

		lpBuffer      = NULL;
		lpImgScanline = NULL;
		compressInit = NO;

		/* full color not supported, force mini color */
		if (m_DataType != FDT_GRAYSCALE && m_DataType != FDT_LINEART)
			m_DataType = FDT_PALETTECOLOR;

		if (m_fSrcArea)
			rSave = m_rSrcArea;
		else
		{
			rSave.top    = rSave.left = 0;
			rSave.bottom = FrameYSize(lpFrame)-1;
			rSave.right  = FrameXSize(lpFrame)-1;
		}

		inType = FrameTypeInfo(lpFrame);
		// cause FramePointer never returns line art
		if (inType.DataType == FDT_LINEART)
			inType.DataType = FDT_GRAYSCALE;
		// make sure colormap is inited for outType so we don't free bogus ptr
		FrameSetTypeInfo(&outType, FDT_NONE);

		npix = RectWidth(&rSave);
		nlin = RectHeight(&rSave);

		/* initialize file header */
		hdr.ScnWidth    = npix;
		hdr.ScnHeight   = nlin;
		hdr.Background  = 0;
		hdr.GlobalMap   = TRUE;
		hdr.ColorRes    = 8;

		/* initialize image descriptor */
		imDesc.ImLeft   = 0;
		imDesc.ImTop    = 0;
		imDesc.ImWidth  = npix;
		imDesc.ImHeight = nlin;
		imDesc.Zero     = 0;

		/* determine type of image to create */
		if ( m_DataType == FDT_GRAYSCALE )
		{
			/* gray */
			hdr.ColorRes = 8;
			hdr.bpp      = 8;
			codeSize     = 8;
			FrameSetTypeInfo(&outType, FDT_GRAYSCALE);
		}
		else
		if ( m_DataType == FDT_LINEART )
		{
			/* line art or scatter */
			hdr.ColorRes = 1;
			hdr.bpp      = 1;
			codeSize     = 2;
			FrameSetTypeInfo(&outType, FDT_LINEART);
		}
		else
		//if ( m_DataType == FDT_PALETTECOLOR )
 		{
			/* mini color */
			hdr.ColorRes = 8;
			hdr.bpp      = 8;
			codeSize     = 8;
			if (inType.DataType == FDT_PALETTECOLOR)
				outType = inType;
			else
				FrameSetTypeInfo(&outType, FDT_PALETTECOLOR);
		}

		AllocLines( &lpBuffer, 1, npix, 4 ); // max size is cool
		AllocLines( &lpImgScanline, 1, npix, 4 );

		if ( !lpBuffer || !lpImgScanline )
		{
			SetError(BEC_errMemory);
			goto Exit;
		}

		/* set raw info byte */
		hdr.RawImInfo = 0x80 | ((hdr.ColorRes-1) << 4) | (hdr.bpp-1);

		/* write file header */
		pTheFile->Write((LPTR)"GIF87a", 6);
		pTheFile->Write((LPTR)&hdr.ScnWidth, 2);
		pTheFile->Write((LPTR)&hdr.ScnHeight, 2);
		pTheFile->Write((LPTR)&hdr.RawImInfo, 1);
		pTheFile->Write((LPTR)&hdr.Background, 1);
		pTheFile->Write((LPTR)"", 1);

		switch (m_DataType)
		{
			case FDT_LINEART:
				/* initialize the color map */
				ColorMap.Length = 2;
				ColorMap.Map[0].red =
				ColorMap.Map[0].green =
				ColorMap.Map[0].blue = 0xFF;
				ColorMap.Map[1].red =
				ColorMap.Map[1].green =
				ColorMap.Map[1].blue = 0x00;
	
				/* write image descriptor, color map and code size */
				if (gifWriteImDesc (pTheFile, &imDesc, &ColorMap, codeSize))
					goto BadWrite;
			break;

			case FDT_GRAYSCALE:
				/* initialize the color map */
				ColorMap.Length = 256;
				for (i = 0; i < 256; i++)
				{
					ColorMap.Map[i].red   =
					ColorMap.Map[i].green =
					ColorMap.Map[i].blue  = i;
				}
	
				/* write image descriptor, color map and code size */
				if (gifWriteImDesc (pTheFile, &imDesc, &ColorMap, codeSize))
					goto BadWrite;
			break;

			case FDT_PALETTECOLOR:
				// see if we need to create a palette
				if (!outType.ColorMap)
					{
					outType.ColorMap = FrameCreateColorMap();
					if (!outType.ColorMap)
						{
						SetError(BEC_errMemory);
						goto Exit;
						}
					outType.ColorMap->NumEntries = 256;
					if (!CreateOptimizedPalette(lpObject, lpFrame,
										outType.ColorMap->RGBData,
										&outType.ColorMap->NumEntries,
										TRUE,
										NULL))
						{
						SetError(BEC_errMemory);
						goto Exit;
						}
					}
				lpRGBmap = outType.ColorMap->RGBData;

				/* initialize the color map */
				ColorMap.Length = 256;
				for (i = 0; i < 256; i++)
				{
					ColorMap.Map[i].red   = lpRGBmap[i].red;
					ColorMap.Map[i].green = lpRGBmap[i].green;
					ColorMap.Map[i].blue  = lpRGBmap[i].blue;
				}
	
				/* write image descriptor, color map and code size */
				if (gifWriteImDesc (pTheFile, &imDesc, &ColorMap, codeSize))
					goto BadWrite;

			break;
		}


		// initialize stuff to do the type conversion
		if (!TypeConvert.Init(inType, outType, npix, m_DitherType))
		{
			SetError(BEC_errMemory);
			goto Exit;
		}

		if (outType.DataType == FDT_LINEART)
		{
			FrameSetTypeInfo(&inTypeLA, FDT_LINEART);
			FrameSetTypeInfo(&outTypeLA, FDT_GRAYSCALE);
			if (!LineArtConvert.Init(inTypeLA, outTypeLA, npix))
			{
				SetError(BEC_errMemory);
				goto Exit;
			}
		}
	
		/* write the image */
		if ( !( lpLZW = CompressLZW_GIF (pTheFile, NULL, 0, codeSize, NULL ) ) )
			goto BadWrite;

		compressInit = YES;

		for (y = rSave.top; y <= rSave.bottom; y++)
		{
			if (Progress (y-rSave.top, nlin, bEscapable ))
				goto Exit;

			if (lpObject)
			{
				if (!ObjGetLine( lpObject, rSave.left, y,
								npix, lpImgScanline))
					goto BadRead;
				lp = lpImgScanline;
			}
			else
			{
				if ( !(lp = FramePointer(lpFrame, rSave.left, y, NO)) )
					goto BadRead;
			}

			// convert the data to the new type
			TypeConvert.ConvertData(lp, lpBuffer, y, npix);
	
			if (outType.DataType == FDT_LINEART)
			{
				/* convert back to depth one, but with pixel values of 0 and 1 */
				LineArtConvert.ConvertData(lpBuffer, lpImgScanline, y, npix);
				for (lp = lpImgScanline, j = 0; j < npix; j++, lp++)
					*lp = (*lp) ? 0 : 1;
				lp = lpImgScanline;
			}
			else
				lp = lpBuffer;

			/* compress the data */
			if (!(CompressLZW_GIF (pTheFile, lp, npix, codeSize, lpLZW)))
				goto BadWrite;
		}

	   if ( compressInit )
		   CompressLZW_GIF (pTheFile, NULL, 0, codeSize, lpLZW);
		cTerm = 0;
		pTheFile->Write((LPTR)&cTerm, 1);

		cTerm = GIFTerm;
		pTheFile->Write((LPTR)&cTerm, 1);

		fRet = TRUE;
		goto Exit;
	}
	CATCH_ALL(e)
	{
		goto BadWrite;
	}
	END_CATCH_ALL

BadWrite:
	SetError(BEC_errWriteFile);
	goto Exit;

BadRead:
	SetError(BEC_errFrameRead);

Exit:
	/* clean up */
	CloseFile(pTheFile, fRet);
	compressInit = NO;

	if (lpBuffer)
		FreeUp (lpBuffer);
	if (lpImgScanline)
		FreeUp ( lpImgScanline );
	if (outType.ColorMap && (outType.ColorMap != inType.ColorMap))
		FrameDestroyColorMap(outType.ColorMap);

	ProgressEnd();

	return (fRet);
}
Esempio n. 6
0
BOOL CombineObjObjects( LPIMAGE lpImage, LPCMD_PARMS lpCmdParms )
/************************************************************************/
{
RECT		rCombine,r;
LPOBJECT	lpBase, lpObj;
LPALPHA	lpAlpha, lpMask;
LPFRAME	lpDFrame, lpSFrame;
LPTR		lpDF, lpDM, *lpSM, *lpSF;
int		x, y, yy, depth;
int      N, H, W, i;
double  *lpAlphaTable, *AiXOi;
double   red,blue,green,k;
POINT    pt;
double   Oi, Ai, Mi, Mc;
LPOBJECT *lpObject;
FRMTYPEINFO TypeInfo;
BOOL	fCanDoOpacity;
FRMDATATYPE MaskType = FDT_GRAYSCALE;

if (!(lpImage))
	return( FALSE );

ImgGetTypeInfo(lpImage, &TypeInfo);
if (TypeInfo.DataType == FDT_LINEART && Mask.OneBitMask)
   MaskType = FDT_LINEART;
fCanDoOpacity = CANDOTRANSPARENCY(TypeInfo.DataType);

lpObj = lpBase = ImgGetBase(lpImage);
if (!(depth = FrameDepth(ObjGetEditFrame(lpBase))))
   depth = 1; // never worry about lineart
N = ImgCountSelObjects(lpImage, NULL);
ImgGetSelObjectRect(lpImage, &rCombine, YES);
H = RectHeight(&rCombine);
W = RectWidth (&rCombine);

lpObject = NULL;
AiXOi = lpAlphaTable = NULL;

lpAlphaTable = (double *)Alloc((N+1) * sizeof(double));
AiXOi        = (double *)Alloc(N * sizeof(double));
lpSM         = (LPTR *)Alloc(N * sizeof(LPTR));
lpSF         = (LPTR *)Alloc(N * sizeof(LPTR));
lpObject     = (LPOBJECT *)Alloc(N * sizeof(LPOBJECT));
lpAlpha = MaskCreate(NULL, W, H, YES, Control.NoUndo, MaskType);
lpDFrame = ImgGetBaseEditFrame(lpImage);
lpDFrame = FrameOpen(FrameType(lpDFrame), W, H, FrameResolution(lpDFrame));

if (!lpAlphaTable || !lpObject || !AiXOi || !lpAlpha || !lpDFrame || !lpSM || !lpSF)
    {
    if (lpAlphaTable)
      FreeUp(lpAlphaTable);
    if (lpObject)
      FreeUp(lpObject);
    if (AiXOi)
      FreeUp(AiXOi);
    if (lpDFrame)
      FreeUp(lpDFrame);
    if (lpSF)
      FreeUp(lpSF);
    if (lpSM)
      FreeUp(lpSM);
      
    Message(IDS_EMEMALLOC);
    return(FALSE);
    }

for (i=0; i < N; i++)
   lpObj = lpObject[i] = ImgGetSelObject(lpImage, lpObj);

ImgEditInit(lpImage, ET_OBJECT, UT_DELETEOBJECTS, lpBase);

ProgressBegin(1, PROGRESS_ID(IDS_UNDOOBJCOMBOBJS));
for (y = 0; y <= H; y++)
   {
 	AstralClockCursor(y, H, NO);

   lpDF = FramePointer(lpDFrame, 0, y, YES);
   lpDM = PixmapPtr(&lpAlpha->Pixmap, PMT_EDIT, 0, y, YES);
   pt.y = y + rCombine.top;

   for (i=0; i < N; i++)
      {
      yy = pt.y - lpObject[i]->rObject.top;
      lpSFrame = ObjGetEditFrame(lpObject[i]);
      lpSF[i] = FramePointer(lpSFrame, 0, yy, NO);
      lpMask   = ObjGetAlpha(lpObject[i]);
      lpSM[i] = PixmapPtr(&lpMask->Pixmap, PMT_EDIT, 0, yy, NO);
      }
   
	for (x = 0; x < W; x++)
      {
      lpAlphaTable[N] = 1.0;
      pt.x = x + rCombine.left;

      for (i=N-1; i >= 0; i--)
         {
         r = lpObject[i]->rObject;
         r.bottom++;
         r.right++;
         if (PtInRect(&r, pt))
            {
			   if (fCanDoOpacity)
	           	Oi = lpObject[i]->Opacity / 255.0;
            else
					Oi = 1;
			   if (fCanDoOpacity)
	            Ai = *lpSM[i]++ / 255.0;
			   else if (*lpSM[i] < 128)
               {
               Ai = 0;
				   lpSM[i]++;
               }
			   else
			      {
				   Ai = 1;
				   lpSM[i]++;
			      }
            AiXOi[i] = Oi * Ai;
            lpAlphaTable[i] = lpAlphaTable[i+1] * (1.0 - AiXOi[i]);
            }
         else
            {
            AiXOi[i] = 1.0;
            lpAlphaTable[i] = lpAlphaTable[i+1];
            }
         }
      Mc = 1.0 - lpAlphaTable[0];
      lpDM[x] = (BYTE)(Mc * 255);

      red = blue = green = k = 0;
      for (i=0; i < N; i++)
         {
         r = lpObject[i]->rObject;
         r.bottom++;
         r.right++;
         if (PtInRect(&r, pt))
            {
            Mi = AiXOi[i] * lpAlphaTable[i+1];
            switch(depth)
               {
               case 1:
                  red     += *lpSF[i]++ * Mi;
                  break;
               case 3:
                  red     += *lpSF[i]++ * Mi;
                  green   += *lpSF[i]++ * Mi;
                  blue    += *lpSF[i]++ * Mi;
                  break;
               case 4:
                  red     += *lpSF[i]++ * Mi;
                  green   += *lpSF[i]++ * Mi;
                  blue    += *lpSF[i]++ * Mi;
                  k       += *lpSF[i]++ * Mi;
                  break;
               }
            }
         }

      if (Mc == 0.0)
         Mc = 1.0;
      switch(depth)
         {
         case 1:
            *lpDF++ = (BYTE)(red / Mc);
            break;
         case 3:
            *lpDF++ = (BYTE)(red   / Mc);
            *lpDF++ = (BYTE)(green / Mc);
            *lpDF++ = (BYTE)(blue  / Mc);
            break;
         case 4:
            *lpDF++ = (BYTE)(red   / Mc);
            *lpDF++ = (BYTE)(green / Mc);
            *lpDF++ = (BYTE)(blue  / Mc);
            *lpDF++ = (BYTE)(k     / Mc); 
            break;
         }
      }
   }

lpObj = ObjCreateFromFrame(ST_PERMANENT, lpDFrame, lpAlpha, &rCombine,
	Control.NoUndo );
lpObj->fSelected = YES;
lpObj->fUndoDeleted = YES;
ImgAddNewObject(lpImage, lpObj);
for (i=0; i < N; i++)
   lpObject[i]->fDeleted = YES;
ImgEditedObject(lpImage, lpBase, IDS_UNDOOBJCOMBOBJS, NULL);
UpdateImage(lpImage, &rCombine, YES);

FreeUp(lpSM);
FreeUp(lpSF);
FreeUp(AiXOi);
FreeUp(lpAlphaTable);
FreeUp(lpObject);
ProgressEnd();
return( TRUE );
}
Esempio n. 7
0
void InitPoints()
{
	int 		i;
	LPFRAME 	lpFrame;
	int 		Width;
	int 		Height;
	int 		x,y;
	LPTR 		lpSrcLine;
	BYTE 		r, g, b;

	iActiveDot = 0;
	iNumDots = 0;

// Clear out the array	
	for (i=0; i<MAX_DOTS; i++)
	{
		DotPoints[i].x = 0;
		DotPoints[i].y = 0;
	}

    if (!lpImage) return;
    lpFrame = ImgGetBaseEditFrame(lpImage);
    if (!lpFrame) return;
    Width  = FrameXSize (lpFrame);
    Height = FrameYSize (lpFrame);

// Find all the points in the image.
// Search for coded dots that indicate a dot-to-dot point.
// These dot points will be drawn as circles for the user to click in.
// An array of points - DotPoints[] is maintained to remember these dots.
    for (y=0;y<Height;y++)
    {
	    AstralClockCursor( y, Height, NO );
        lpSrcLine = FramePointer (lpFrame,0,y,FALSE);

        for (x=0;x<Width;x++)
        {
            RGBS Pixel;
            FrameGetRGB (lpFrame,lpSrcLine,&Pixel,1);
            r = Pixel.red;
            g = Pixel.green;
            b = Pixel.blue;
            if (r >= 100 && g == 0 && b == 0)
            {
            	// This is a coded pixel that contains:
            	//  1) green - No coding.  MUST be 0.
            	//  2) red   - Sequence that the dot is found.
            	//  3) blue  - No coding.  MUST be 0.
				r -= 100;
				if (r >= 0 && r <= MAX_DOTS)
				{
					// Save the Dot position.
					// Do not allow the dot to go off the screen.
					DotPoints[r].x = min(x, Width  - ((DOT_DIAMETER / 2) + 2));
					DotPoints[r].y = min(y, Height - ((DOT_DIAMETER / 2) + 2));
					iNumDots = max(iNumDots, r);
				}
            }
            lpSrcLine += 3;
        } // Width
    }     // Height
}
Esempio n. 8
0
BOOL CWriteBitmap::TGAWrite()
{
	TGAHDR  PicHdr;
	int     i, bpl, npix, nlin;
	LPTR    lp, lpBuffer, lpImgScanline;
	RECT    rSave;
	BOOL    bEscapable;
	LPRGB lpRGBmap;
	RGBS rgb;
	BOOL fCompressed;
	LPFRAME lpFrame = NULL;
	LPOBJECT lpObject;
	FRMTYPEINFO inType, outType;
	CFrameTypeConvert TypeConvert;
	BOOL fRet = FALSE;
	CFile*	pTheFile = NULL;
	LPMASK lpMask = NULL;

	LPTGAOPTIONS lpOptions = (LPTGAOPTIONS)m_lpOptions;

	ASSERT(lpOptions);
	if (!lpOptions)
		return(FALSE);

	if (m_lpObjList)
	{
		lpObject = m_lpObjList->lpHead;
		if (lpObject)
		{
			lpFrame = ObjGetEditFrame(lpObject);
			if (lpObject->lpAlpha && lpOptions->bSaveMask)
				lpMask = lpObject->lpAlpha;
			// if only one object don't do combines
			if (!lpObject->lpNext)
				lpObject = NULL;
		}
	}
	else
	{
		lpFrame = m_lpFrame;
		lpObject = NULL;
	}

	ASSERT(lpFrame);
	
 	ProgressBegin(1);
 
	if ((pTheFile = OpenFile()) == NULL)
	{
		ProgressEnd();
		return(FALSE);
	}

	TRY
	{
		if (m_fSrcArea)
			rSave = m_rSrcArea;
		else
		{
			rSave.top    = rSave.left = 0;
			rSave.bottom = FrameYSize(lpFrame)-1;
			rSave.right  = FrameXSize(lpFrame)-1;
		}

		inType = FrameTypeInfo(lpFrame);
		// cause FramePointer never returns line art
		if (inType.DataType == FDT_LINEART)
			inType.DataType = FDT_GRAYSCALE;
		// make sure colormap is inited for outType so we don't free bogus ptr
		FrameSetTypeInfo(&outType, FDT_NONE);

		npix = RectWidth(&rSave);
		nlin = RectHeight(&rSave);

		/* image compression does not currently work */
		fCompressed = NO;
	
		/* initialize file header */
		PicHdr.textSize = 0;	/* no id field */
		PicHdr.XOffset  = 0;
		PicHdr.YOffset  = 0;
		PicHdr.x        = npix;
		PicHdr.y        = nlin;
		PicHdr.imType   = 0;

		/*************************************/
		/* determine type of image to create */
		/*************************************/

		/* save line art and scatter as gray */

		switch (m_DataType)
		{
			case FDT_LINEART:
			case FDT_GRAYSCALE:
				/* gray */
				PicHdr.mapType = 1;
				PicHdr.mapOrig = 0;
				PicHdr.mapLength = 256;
				PicHdr.CMapBits = 24;
				PicHdr.dataType = (fCompressed) ? 9 : 1;
				PicHdr.dataBits = 8;
				bpl = npix;
				FrameSetTypeInfo(&outType, FDT_GRAYSCALE);
				lpMask = NULL;
			break;

			case FDT_PALETTECOLOR:
				/* mini color */
				PicHdr.mapType = 1;
				PicHdr.mapOrig = 0;
				PicHdr.mapLength = 256;
				PicHdr.CMapBits = 24;
				PicHdr.dataType = (fCompressed) ? 9 : 1;
				PicHdr.dataBits = 8;
				bpl = npix;
				if (inType.DataType == FDT_PALETTECOLOR)
					outType = inType;
				else
					FrameSetTypeInfo(&outType, FDT_PALETTECOLOR);
				lpMask = NULL;
			break;

			case FDT_RGBCOLOR:
			case FDT_CMYKCOLOR:
				/* full color */
				PicHdr.mapType = 0;	/* no color map data */
				PicHdr.mapOrig = 0;
				PicHdr.mapLength = 0;
				PicHdr.CMapBits = 0;
				PicHdr.dataType = 2;
				PicHdr.dataType = (fCompressed) ? 10 : 2;
				if (m_DataType == FDT_CMYKCOLOR)
					lpMask = NULL;
				if (lpMask || (m_DataType == FDT_CMYKCOLOR))
				{
					PicHdr.dataBits = 32;
					bpl = npix * 4;
				}
				else
				{
					PicHdr.dataBits = 24;
					bpl = npix * 3;
				}
				FrameSetTypeInfo(&outType, m_DataType);
			break;

			default:
				//Print ("Unknown flag value");
				goto BadRead;
			break;
		}

		AllocLines (&lpBuffer, 1, npix, 4);
		AllocLines (&lpImgScanline, 1, npix, 4 );

		if ( !lpBuffer || !lpImgScanline )
		{
			SetError (BEC_errMemory);
			goto Exit;
		}

		/* write file header */
		pTheFile->Write(&PicHdr.textSize, 1);
		pTheFile->Write(&PicHdr.mapType,  1);
		pTheFile->Write(&PicHdr.dataType, 1);

		pTheFile->Write(&PicHdr.mapOrig,   2);
		pTheFile->Write(&PicHdr.mapLength, 2);
		pTheFile->Write(&PicHdr.CMapBits,  1);
		pTheFile->Write(&PicHdr.XOffset,   2);
		pTheFile->Write(&PicHdr.YOffset,   2);
		pTheFile->Write(&PicHdr.x,         2);
		pTheFile->Write(&PicHdr.y,         2);
		pTheFile->Write(&PicHdr.dataBits,  1);
		pTheFile->Write(&PicHdr.imType,    1);

		switch (outType.DataType)
		{
			case FDT_LINEART:
			case FDT_GRAYSCALE:
				/* gray */
				/* write the color map */
				for (i = 0; i < 256; i++) 
				{
					rgb.red =
					rgb.green =
					rgb.blue = i;
					pTheFile->Write((LPTR) &rgb, 3);
				}
			break;

			case FDT_PALETTECOLOR:
				/* mini color */
				// see if we need to create a palette
				if (!outType.ColorMap)
					{
					outType.ColorMap = FrameCreateColorMap();
					if (!outType.ColorMap)
						{
						SetError(BEC_errMemory);
						goto Exit;
						}
					outType.ColorMap->NumEntries = 256;
					if (!CreateOptimizedPalette(lpObject, lpFrame,
										outType.ColorMap->RGBData,
										&outType.ColorMap->NumEntries,
										TRUE,
										NULL))
						{
						SetError(BEC_errMemory);
						goto Exit;
						}
					}
				lpRGBmap = outType.ColorMap->RGBData;

				/* write the color map */
				for (i = 0; i < 256; i++)
				{
					pTheFile->Write((LPTR) &lpRGBmap[i].blue,  1);
					pTheFile->Write((LPTR) &lpRGBmap[i].green, 1);
					pTheFile->Write((LPTR) &lpRGBmap[i].red,   1);
				}
			break;

			case FDT_RGBCOLOR:
			case FDT_CMYKCOLOR:
				/* full color */
			break;
		}

		// initialize stuff to do the type conversion
		if (!TypeConvert.Init(inType, outType, npix, m_DitherType))
		{
			SetError(BEC_errMemory);
			goto Exit;
		}

		/* write the image */
		for (i = rSave.bottom; i >= rSave.top; i--) 
		{
			if (Progress(rSave.bottom-i, nlin, bEscapable))
				goto Exit;

			if (lpObject)
			{
				if (!ObjGetLine( lpObject, rSave.left, i,
					(rSave.right - rSave.left) + 1, lpImgScanline))
					goto BadRead;
				lp = lpImgScanline;
			}
			else
			{
				if ( !(lp = FramePointer(lpFrame, rSave.left, i, NO)) )
					goto BadRead;
			}

			// convert the data to the new type
			TypeConvert.ConvertData(lp, lpBuffer, i, npix);

			if (outType.DataType == FDT_RGBCOLOR)
			{
				swapBGR( lpBuffer, lpBuffer, npix );
				if (lpMask)
				{
					MergeMaskData(lpMask, rSave.left, i, npix, 3, lpBuffer, lpImgScanline);
					lp = lpImgScanline;
				}
				else
					lp = lpBuffer;
			}
			else
				lp = lpBuffer;
		
	#ifdef UNUSED
			if ( fCompressed ) 
			{
				if (tgaComp8Bit (ofh, lp, npix))
					goto BadWrite;
			}
			else 
	#endif // UNUSED
			{
				pTheFile->Write(lp, bpl);
			}
		}
		fRet = TRUE;
		goto Exit;
	}
	CATCH_ALL(e)
	{
		goto BadWrite;
	}
	END_CATCH_ALL

BadWrite:
	SetError(BEC_errWriteFile);
	goto Exit;

BadRead:
	SetError(BEC_errFrameRead);

Exit:
	/* clean up */
	CloseFile(pTheFile, fRet);

	if (lpBuffer)
		FreeUp (lpBuffer);
	if (lpImgScanline)
		FreeUp( lpImgScanline );
	if (outType.ColorMap && (outType.ColorMap != inType.ColorMap))
		FrameDestroyColorMap(outType.ColorMap);

	ProgressEnd();

	return (fRet);
}
Esempio n. 9
0
LPFRAME DIBToPaletteFrame( LPTR lpDIBMem, BOOL bForceRGB )
{
	FRMDATATYPE FrameDataType;
	LPBITMAPINFO lpInfo;
	LPCOLORMAP lpColorMap;
	LPRGBQUAD lpRGBQColorMap;
	LPFRAME lpFrame;
	HPTR lpSrcLine;
	HPTR lpSrc;
	LPTR lpDst;
	BOOL bGrayMap;
	int iColorMapEntries;
	int iResolution;
	int iFrameXSize;
	int iFrameYSize;
	int iSrcWidth;
	int iDstWidth;
	int iCount;
	int y;
	int i;

	lpInfo = (LPBITMAPINFO)lpDIBMem;

	// Get the important bitmap information
	iFrameXSize = lpInfo->bmiHeader.biWidth;
	iFrameYSize = lpInfo->bmiHeader.biHeight;
	iResolution = ((lpInfo->bmiHeader.biXPelsPerMeter) * 254L) / 10000L;

	// Make sure that we have something to do
	if ((iFrameXSize <= 0) || (iFrameYSize <= 0))
	{
		return(NULL);
	}

	// Validate the image resolution
	if (iResolution <= 0)
	{
		iResolution = 75;
	}

	lpRGBQColorMap = &lpInfo->bmiColors[0];
	bGrayMap = TRUE;

	if (lpInfo->bmiHeader.biBitCount == 4)
		iColorMapEntries = 16;
	else
		iColorMapEntries = 256;

	// Find out whether or not this is a grayscale image
	for(i=0;i<iColorMapEntries;i++)
	{
		if (bGrayMap)
		{
			if ((lpRGBQColorMap[i].rgbBlue != lpRGBQColorMap[i].rgbRed) ||
				(lpRGBQColorMap[i].rgbBlue != lpRGBQColorMap[i].rgbRed))
			{
				bGrayMap = FALSE;
				break;
			}
		}
	}

	if (bGrayMap)
	{
		FrameDataType = FDT_GRAYSCALE;
		bForceRGB     = FALSE;
	}
	else
	{
		if (bForceRGB)
		{
			FrameDataType = FDT_RGBCOLOR;
		}
		else
		{
			FrameDataType = FDT_PALETTECOLOR;
		}
	}

	// Create the new image frame
	lpFrame = FrameOpen(FrameDataType, iFrameXSize, iFrameYSize, iResolution);

	if (!lpFrame) return(NULL);

	// Add the colormap to the frame if necessary
	if (!bGrayMap)
	{
		// Allocate space for the colormap

		lpColorMap = (LPCOLORMAP)Alloc( sizeof(COLORMAP)+ sizeof(RGBS) * 256);

		if (!lpColorMap)
		{
			FrameClose(lpFrame);
			return(NULL);
		}

		lpColorMap->NumEntries = 256;

		for(i=0;i<iColorMapEntries;i++)
		{
			lpColorMap->RGBData[i].red   = lpRGBQColorMap[i].rgbRed;
			lpColorMap->RGBData[i].green = lpRGBQColorMap[i].rgbGreen;
			lpColorMap->RGBData[i].blue  = lpRGBQColorMap[i].rgbBlue;
		}

		for(i=iColorMapEntries;i<256;i++)
		{
			lpColorMap->RGBData[i].red   = 0;
			lpColorMap->RGBData[i].green = 0;
			lpColorMap->RGBData[i].blue  = 0;
		}

		if (FrameDataType == FDT_RGBCOLOR)
			if (!FrameSetColorMap( lpFrame, lpColorMap ))
			{
				FrameClose( lpFrame );
				return(NULL);
			}
	}

	// Find the DIB data pointer and width
	lpSrcLine = lpDIBMem + lpInfo->bmiHeader.biSize + 
		iColorMapEntries * (sizeof(RGBQUAD));
//OLD VERSION USED  lpInfo->bmiHeader.biClrUsed instead of iColorMapEntries
// some 4 bit DIB's don't set biCLrUsed that way

	if (lpInfo->bmiHeader.biBitCount == 4)
		iSrcWidth = ((lpInfo->bmiHeader.biWidth+7)/8)*4;
	else
		iSrcWidth = ((lpInfo->bmiHeader.biWidth+3)/4)*4;

	iDstWidth = FrameByteWidth( lpFrame );

	if (bForceRGB)
	{
		// Copy the DIB data into the RGB Frame
		if (lpInfo->bmiHeader.biBitCount == 4)
		{
			for(y=iFrameYSize-1;y >= 0;y--)
			{
				lpSrc = lpSrcLine;
				lpDst = FramePointer( lpFrame, 0, y, TRUE );

				iCount = (iFrameXSize+1)/2;

				while(iCount-- > 0)
				{
					*lpDst++ = lpColorMap->RGBData[(*lpSrc & 0xF0)>>4].red;
					*lpDst++ = lpColorMap->RGBData[(*lpSrc & 0xF0)>>4].green;
					*lpDst++ = lpColorMap->RGBData[(*lpSrc & 0xF0)>>4].blue;

					*lpDst++ = lpColorMap->RGBData[(*lpSrc & 0x0F)].red;
					*lpDst++ = lpColorMap->RGBData[(*lpSrc & 0x0F)].green;
					*lpDst++ = lpColorMap->RGBData[(*lpSrc & 0x0F)].blue;
					lpSrc++;
				}

				lpSrcLine += iSrcWidth;
			}
		}
		else
		{
			for(y=iFrameYSize-1;y >= 0;y--)
			{
				lpSrc = lpSrcLine;
				lpDst = FramePointer( lpFrame, 0, y, TRUE );

				iCount = iFrameXSize;

				while(iCount-- > 0)
				{
					*lpDst++ = lpColorMap->RGBData[*lpSrc].red;
					*lpDst++ = lpColorMap->RGBData[*lpSrc].green;
					*lpDst++ = lpColorMap->RGBData[*lpSrc].blue;
					lpSrc++;
				}

				lpSrcLine += iSrcWidth;
			}
		}
	}
Esempio n. 10
0
static LPTR FrameToColorDIB( LPFRAME lpFrame, LPRECT lpRect )
{
	int y, bpl;
	LPTR lpSrc, lpDIBMem, lpConvertLine;
	HPTR hpDstLine;
	DWORD lCount, lImageSize, lInfoSize;
	int dx, dy;
	LPBITMAPINFO lpInfo;
	FRMTYPEINFO SrcTypeInfo, DstTypeInfo;
	CFrameTypeConvert TypeConvert;

	if ( !lpFrame )
		return( NULL );

	FrameGetTypeInfo(lpFrame, &SrcTypeInfo);
	FrameSetTypeInfo(&DstTypeInfo, FDT_RGBCOLOR);

	dx = (lpRect->right  - lpRect->left) + 1;
	dy = (lpRect->bottom - lpRect->top)  + 1;

	lInfoSize = sizeof(BITMAPINFOHEADER);
	bpl = dx * 3;  // Always 24-bit color out

	bpl        = 4 * ((bpl + 3) / 4); // DIB packing
	lImageSize = (long)bpl * dy;
	lCount     = lInfoSize + lImageSize;

	// Allocate the memory to hold the DIB
	if ( !(lpDIBMem = Alloc( lCount )) )
	{
		FrameSetError( ERR_MALLOC );
		return( NULL );
	}

	if ( !(lpConvertLine = Alloc( bpl )) )
	{
		FreeUp(lpDIBMem);
		FrameSetError( ERR_MALLOC );
		return( NULL );
	}

	lpInfo = (LPBITMAPINFO)lpDIBMem;
	lpInfo->bmiHeader.biSize          = sizeof(BITMAPINFOHEADER);
	lpInfo->bmiHeader.biWidth         = dx;
	lpInfo->bmiHeader.biHeight        = dy;
	lpInfo->bmiHeader.biPlanes        = 1;
	lpInfo->bmiHeader.biCompression   = BI_RGB;
	lpInfo->bmiHeader.biBitCount      = 24;
	lpInfo->bmiHeader.biSizeImage     = lImageSize;
	lpInfo->bmiHeader.biXPelsPerMeter = (10000L * (long) FrameResolution(lpFrame)) / 254L;
	lpInfo->bmiHeader.biYPelsPerMeter = (10000L * (long) FrameResolution(lpFrame)) / 254L;
	lpInfo->bmiHeader.biClrUsed       = 0;
	lpInfo->bmiHeader.biClrImportant  = 0;

	hpDstLine = (HPTR)lpDIBMem;
	hpDstLine += lInfoSize;

	if (!TypeConvert.Init(SrcTypeInfo, DstTypeInfo, dx))
	{
		FreeUp(lpDIBMem);
		FreeUp(lpConvertLine);
		FrameSetError( ERR_MALLOC );
		return( NULL );
	}

	// This goes backwards...
	for (y = lpRect->bottom; y >= lpRect->top; y--)
	{
		lpSrc = FramePointer(lpFrame, lpRect->left, y, NO);
		if (lpSrc)
		{
			TypeConvert.ConvertData(lpSrc, lpConvertLine, y, dx);
			swapBGR( lpConvertLine, lpConvertLine, dx);
			CopyToHuge(lpConvertLine, hpDstLine, bpl);
		}
		hpDstLine += bpl;
	}

	FreeUp(lpConvertLine);

	return( lpDIBMem );
}
Esempio n. 11
0
static LPTR FrameToPaletteDIB( LPFRAME lpFrame, LPRECT lpRect )
{
	int y, bpl, i;
	LPTR lpSrc, lpDIBMem;
	HPTR lpDstLine;
	HPTR lpDst;
	DWORD lCount, lImageSize, lInfoSize;
	int iCount, dx, dy;
	LPBITMAPINFO lpInfo;

	if ( !lpFrame )
		return( NULL );

	dx = (lpRect->right  - lpRect->left) + 1;
	dy = (lpRect->bottom - lpRect->top)  + 1;

	bpl = dx;

	lInfoSize = sizeof(BITMAPINFOHEADER) + 256*sizeof(RGBQUAD);
	bpl = 4 * ((bpl + 3)/4); // DIB packing

	lImageSize = (long)bpl * dy;
	lCount     = lInfoSize + lImageSize;

	// Allocate the memory to hold the DIB
	if ( !(lpDIBMem = Alloc( lCount )) )
	{
		FrameSetError( ERR_MALLOC );
		return( NULL );
	}

	lpInfo = (LPBITMAPINFO)lpDIBMem;
	lpInfo->bmiHeader.biSize          = sizeof(BITMAPINFOHEADER);
	lpInfo->bmiHeader.biWidth         = dx;
	lpInfo->bmiHeader.biHeight        = dy;
	lpInfo->bmiHeader.biPlanes        = 1;
	lpInfo->bmiHeader.biCompression   = BI_RGB;
	lpInfo->bmiHeader.biBitCount      = 8;
	lpInfo->bmiHeader.biSizeImage     = lImageSize;
	lpInfo->bmiHeader.biXPelsPerMeter = (10000L * (long) FrameResolution(lpFrame)) / 254L;
	lpInfo->bmiHeader.biYPelsPerMeter = (10000L * (long) FrameResolution(lpFrame)) / 254L;
	lpInfo->bmiHeader.biClrUsed       = 256;
	lpInfo->bmiHeader.biClrImportant  = 256;

	if (FrameType(lpFrame) == FDT_GRAYSCALE)
	{
		for (i = 0; i < 256; ++i)
		{
			lpInfo->bmiColors[i].rgbBlue     = i;
			lpInfo->bmiColors[i].rgbGreen    = i;
			lpInfo->bmiColors[i].rgbRed      = i;
			lpInfo->bmiColors[i].rgbReserved = 0;
		}
	}
	else
	{
		LPCOLORMAP lpColorMap;

		lpColorMap = FrameGetColorMap( lpFrame );

		if (!lpColorMap)
		{
			for (i = 0; i < 256; ++i)
			{
				lpInfo->bmiColors[i].rgbBlue     = i;
				lpInfo->bmiColors[i].rgbGreen    = i;
				lpInfo->bmiColors[i].rgbRed      = i;
				lpInfo->bmiColors[i].rgbReserved = 0;
			}
		}
		else
		{
			for (i = 0; i < 256; ++i)
			{
				lpInfo->bmiColors[i].rgbBlue     = lpColorMap->RGBData[i].blue;
				lpInfo->bmiColors[i].rgbGreen    = lpColorMap->RGBData[i].green;
				lpInfo->bmiColors[i].rgbRed      = lpColorMap->RGBData[i].red;
				lpInfo->bmiColors[i].rgbReserved = 0;
			}
		}
	}

	lpDstLine = (HPTR)lpDIBMem;
	lpDstLine += lInfoSize;

	// This goes backwards...
	for (y = lpRect->bottom; y >= lpRect->top; y--)
	{
		lpDst = lpDstLine;
		lpSrc = FramePointer(lpFrame, lpRect->left, y, NO);

		if (lpSrc)
		{
			iCount = dx;

			while (iCount-- > 0)
				*lpDst++ = *lpSrc++;
		}
		lpDstLine += bpl;
	}

	return( lpDIBMem );
}
Esempio n. 12
0
	const IRTree::IExp* CFrame::ThisPointerExp() const
	{
		return new IRTree::CMem( new IRTree::CTemp( *FramePointer() ) );
	}
Esempio n. 13
0
int TiffWriteFrame(
	int      oFile,
	LPSTR     lpFileName,
	LPOBJECT lpObject,
	LPFRAME  lpFrame,
	LPRECT   lpRect,
	int      flag,
	BOOL     fCompressed,
	BOOL     bEscapable)
{
	TAG    tag;
	int    y, bpl, npix, nlin, ofp;
	LPLONG lngptr,boffptr;
	LPWORD shtptr;
	DWORD  byteoffset;
	WORD   i, numtags, photomet, samples;
	BYTE   bpp;
	LPWORD lpRed, lpGreen, lpBlue;
	RGBS   RGBmap[256];
	LPTR   lp, lpBuffer, lpOutputPointer, lpImgScanline;
	FNAME  temp;
	RECT   rSave;
	BOOL   compressInit;
#ifdef STATIC16 // only in new framelib
	CFrameTypeConvert FrameTypeConvert;
	FRMTYPEINFO SrcTypeInfo;	
	FRMTYPEINFO DstTypeInfo;	
#endif

	lpBuffer      = NULL;
	lpImgScanline = NULL;

	if (!lpFrame)
		return( -1 );

	ProgressBegin(1,0);

	if ((ofp = oFile) < 0)
		bEscapable = !FileExists(lpFileName);

	if ((ofp = oFile) < 0 && (ofp = _lcreat(lpFileName,0)) < 0)
	{
		Message( IDS_EWRITE, lpFileName );
		goto Exit;
	}

	if (lpRect)
		rSave = *lpRect;
	else
	{
		rSave.top    = rSave.left = 0;
		rSave.bottom = FrameYSize(lpFrame)-1;
		rSave.right  = FrameXSize(lpFrame)-1;
	}

	npix = RectWidth(&rSave);
	nlin = RectHeight(&rSave);

	switch(flag)
	{
		case IDC_SAVELA :
		case IDC_SAVESP :
			bpp      = 1;
			bpl      = ((npix + 7) / 8);
			numtags  = 11;
			photomet = 1;
			samples  = 1;
		break;

		case IDC_SAVECT :
			bpp      = 8;
			bpl      = npix;
			numtags  = 11;
			photomet = 1;
			samples  = 1;
		break;

		case IDC_SAVE4BITCOLOR :
		case IDC_SAVE8BITCOLOR :
			bpp      = 8;
			bpl      = npix;
			numtags  = 12;
			photomet = 3;
			samples  = 1;
		break;

		case IDC_SAVE24BITCOLOR :
			bpp      = 24;
			bpl      = npix * 3;
			numtags  = 11;
			photomet = 2;
			samples  = 3;
		break;

		case IDC_SAVE32BITCOLOR :
			bpp      = 32;
			bpl      = npix * 4;
			numtags  = 11;
			photomet = 5;
			samples  = 4;
		break;

		default :
			goto Exit;
		break;
	}

	compressInit = NO;

	if ( bpp == 1 )
	{
		AllocLines( &lpBuffer,      1, npix, 2 );
		AllocLines( &lpImgScanline, 1, npix, 1 );
	}
	else
	{
		AllocLines( &lpBuffer,      1, max(bpl, FrameByteWidth(lpFrame)), 1 );
		AllocLines( &lpImgScanline, 1, max(bpl, FrameByteWidth(lpFrame)), 1 );
	}

	if ( !lpBuffer || !lpImgScanline )
	{
		Message( IDS_EMEMALLOC );
		_lclose( ofp );
		goto Exit;
	}

	/* first location where any extra data can be stored */
	/* 10 byte header + all tag data (12 bytes each) + 4 bytes (null ifd) */
	byteoffset = 10 + (numtags * sizeof(TAG)) + 4;

	shtptr = (LPWORD)LineBuffer[0];
	SetNextWord(&shtptr, 0x4949);   /* byte order is LSB,MSB */
	SetNextWord(&shtptr, 0x2a);     /* tiff version number */
	SetNextWord(&shtptr, 8);        /* byte offset to first image file directory LSW */
	SetNextWord(&shtptr, 0);        /* byte offset to first image file directory MSW */
	SetNextWord(&shtptr, numtags);  /* number of entries in IFD */

	tag.tagno  = 0xff;    /* tag 0xff, subfile type */
	tag.type   = 3;       /* field type is short */
	tag.length = 1;       /* number of values */
	tag.value  = 1;       /* value */
#ifdef _MAC
	SwapTag(&tag);
#endif	
	lmemcpy((LPTR)shtptr,(LPTR)&tag.tagno,12);
	shtptr += 6;

	tag.tagno  = 0x100;   /* tag 0x100, number of pixels */
	tag.type   = 3;       /* field type is short */
	tag.length = 1;       /* number of values */
	tag.value  = npix;    /* value */
#ifdef _MAC
	SwapTag(&tag);
#endif	
	lmemcpy((LPTR)shtptr,(LPTR)&tag.tagno,12);
	shtptr += 6;

	tag.tagno  = 0x101;   /* tag 0x101, number of lines */
	tag.type   = 3;       /* field type is short */
	tag.length = 1;       /* number of values */
	tag.value  = nlin;    /* value */
#ifdef _MAC
	SwapTag(&tag);
#endif	
	lmemcpy((LPTR)shtptr,(LPTR)&tag.tagno,12);
	shtptr += 6;

	tag.tagno  = 0x102;   /* tag 0x102, bits per sample */
	tag.type   = 3;       /* field type is short */
	tag.length = samples; /* number of values */

	if ( samples == 3 || samples == 4)
	{
		tag.value = byteoffset;	/* deferred value */
		byteoffset += (samples*sizeof(short));
	}
	else
		tag.value = bpp;  /* value */

#ifdef _MAC
	SwapTag(&tag);
#endif	
	lmemcpy((LPTR)shtptr,(LPTR)&tag.tagno,12);
	shtptr += 6;

	tag.tagno  = 0x103;   /* tag 0x103, compression */
	tag.type   = 3;       /* field type is short */
	tag.length = 1;       /* number of values */
	tag.value  = (fCompressed ? 5:1); /* value */
#ifdef _MAC
	SwapTag(&tag);
#endif	
	lmemcpy((LPTR)shtptr,(LPTR)&tag.tagno,12);
	shtptr += 6;

	tag.tagno  = 0x106;	  /* tag 0x106,photometric inter.(0 = black) */
	tag.type   = 3;	      /* field type is short */
	tag.length = 1;	      /* number of values */
	tag.value  = photomet;	/* value */
#ifdef _MAC
	SwapTag(&tag);
#endif	
	lmemcpy((LPTR)shtptr,(LPTR)&tag.tagno,12);
	shtptr += 6;

	tag.tagno  = 0x111;   /* tag 0x111, strip byte offsets */
	tag.type   = 4;       /* field type is long */
	tag.length = 1;       /* number of values */
	tag.value  = 0;       /* dummy location of the start of image data */
#ifdef _MAC
	SwapTag(&tag);
#endif	
	lmemcpy((LPTR)shtptr,(LPTR)&tag.tagno,12);
	boffptr = (LPLONG)(shtptr+4);  // make boffptr point at tag.value
	shtptr += 6;

	tag.tagno  = 0x115;   /* tag 0x115, samples per pixel*/
	tag.type   = 3;       /* field type is short */
	tag.length = 1;       /* number of values */
	tag.value  = samples; /* value */
#ifdef _MAC
	SwapTag(&tag);
#endif	
	lmemcpy((LPTR)shtptr,(LPTR)&tag.tagno,12);
	shtptr += 6;

	tag.tagno  = 0x11a;   /* tag 0x11a, xresolution */
	tag.type   = 5;       /* field type is rational */
	tag.length = 1;       /* number of values */
	tag.value = byteoffset;	/* deferered value */
	byteoffset += 8;
#ifdef _MAC
	SwapTag(&tag);
#endif	
	lmemcpy((LPTR)shtptr,(LPTR)&tag.tagno,12);
	shtptr += 6;

	tag.tagno  = 0x11b;   /* tag 0x11b, yresolution */
	tag.type   = 5;       /* field type is rational */
	tag.length = 1;       /* number of values */
	tag.value  = byteoffset; /* deferred value */
	byteoffset += 8;
#ifdef _MAC
	SwapTag(&tag);
#endif	
	lmemcpy((LPTR)shtptr,(LPTR)&tag.tagno,12);
	shtptr += 6;

	tag.tagno  = 0x11c;   /* tag 0x11c, planar configuration */
	tag.type   = 3;       /* field type is short */
	tag.length = 1;       /* number of values */
	tag.value  = 1;       /* value */
#ifdef _MAC
	SwapTag(&tag);
#endif	
	lmemcpy((LPTR)shtptr,(LPTR)&tag.tagno,12);
	shtptr += 6;

	if ( photomet == 3 ) // Palette color map
	{
		tag.tagno  = 0x140;      /* tag 0x140, colormap */
		tag.type   = 3;          /* field type is short */
		tag.length = 3*256;      /* number of values */
		tag.value  = byteoffset; /* value */
		byteoffset += (2*3*256);
#ifdef _MAC
	SwapTag(&tag);
#endif	
		lmemcpy((LPTR)shtptr,(LPTR)&tag.tagno,12);
		shtptr += 6;
	}

	// Copy the NULL Image File Directory pointer
	SetNextWord(&shtptr, 0); /* pointer to next IFD */
	SetNextWord(&shtptr, 0);

	// Copy out the Bits Per Sample, if multiple samples
	if ( samples == 3 )  // The bits per pixel per sample
	{
		SetNextWord(&shtptr, 8);
		SetNextWord(&shtptr, 8);
		SetNextWord(&shtptr, 8);
	}

	// Copy out the Bits Per Sample, if multiple samples
	if ( samples == 4 )  // The bits per pixel per sample
	{
		SetNextWord(&shtptr, 8);
		SetNextWord(&shtptr, 8);
		SetNextWord(&shtptr, 8);
		SetNextWord(&shtptr, 8);
	}

	// Copy out the X and Y resolution fields
	lngptr = (LPLONG)shtptr;

#ifdef PPVIDEO
	SetNextLong(&lngptr, FrameResolution(lpFrame) * 2); /* xreso numerator */
	SetNextLong(&lngptr, 2);							/* xreso denominator */
	SetNextLong(&lngptr, FrameResolution(lpFrame) * 2); /* yreso numerator */
	SetNextLong(&lngptr, 2);							/* yreso denominator */
#else
	SetNextLong(&lngptr, FrameResolution(lpFrame));		/* xreso numerator */
	SetNextLong(&lngptr, 1);							/* xreso denominator */
	SetNextLong(&lngptr, FrameResolution(lpFrame));		/* yreso numerator */
	SetNextLong(&lngptr, 1);							/* yreso denominator */
#endif

	*boffptr = byteoffset;
#ifdef _MAC
	swapl((LPDWORD)boffptr);
#endif	

	// Write out the tags, the bpp, and the resolutions
	i = (LPTR)lngptr - (LPTR)LineBuffer[0];
	if ( _lwrite(ofp, LineBuffer[0], i) != i )
		goto BadWrite;

	// Write the color palette, if necessary
	if ( photomet == 3 ) // Palette color map
	{
		if (!OptimizeBegin(lpObject, lpFrame, RGBmap, 256, 
			NULL /*(LPROC)AstralClockCursor*/,  // No Progress report
			NO, Convert.fOptimize, Convert.fScatter, Convert.fDither, npix))
			goto BadWrite;

		lpRed   = (LPWORD)LineBuffer[0];
		lpGreen = lpRed   + 256;
		lpBlue  = lpGreen + 256;
		for ( i=0; i<256; i++ )
		{
			*lpRed++   = (WORD)RGBmap[i].red   << 8;
			*lpGreen++ = (WORD)RGBmap[i].green << 8;
			*lpBlue++  = (WORD)RGBmap[i].blue  << 8;
		}
		if ( _lwrite(ofp, LineBuffer[0], 2*3*256) != 2*3*256 )
			goto BadWrite;
	}

	if ( fCompressed )
	{
		if ( CompressLZW( ofp, NULL, 0 ) < 0 ) /* Initialize */
			goto BadWrite;
		compressInit = YES;
	}

	switch(bpp)
	{
		case 1 :
			for( y=rSave.top; y<=rSave.bottom; y++ )
			{
				if (AstralClockCursor( y-rSave.top, nlin, bEscapable ))
					goto Cancelled;

				if ( lpObject )
				{
					if (!ImgGetLine( NULL, lpObject, rSave.left, y,
						(rSave.right - rSave.left) + 1, lpImgScanline))
						goto BadRead;
					lp = lpImgScanline;
				}
				else
				{
					if ( !(lp = FramePointer( lpFrame, rSave.left, y, NO )) )
						goto BadRead;
				}

				if (FrameDepth(lpFrame) == 0)
				{
					if (flag == IDC_SAVESP)
						diffuse( 0, i, 0, NULL, lp, npix, lpBuffer );
					else
						con2la( lp, npix, lpBuffer );
				}
				else
				{
					ConvertData( lp, FrameDepth(lpFrame), npix, lpBuffer+npix, 1 );
					if ( flag == IDC_SAVESP )
						diffuse( 0, i, 0, NULL, lpBuffer+npix, npix, lpBuffer );
					else
						con2la( lpBuffer+npix, npix, lpBuffer );
				}

				if ( fCompressed )
				{
					if ( CompressLZW( ofp, lpBuffer, bpl ) < 0 )
						goto BadWrite;
				}
				else
				{
					if ( _lwrite( ofp, (LPSTR)lpBuffer, bpl ) != bpl )
						goto BadWrite;
				}
			}
		break;

		case 8 :
			for( y=rSave.top; y<=rSave.bottom; y++ )
			{
				if (AstralClockCursor( y-rSave.top, nlin, bEscapable ))
					goto Cancelled;

				if ( lpObject )
				{
					if (!ImgGetLine( NULL, lpObject, rSave.left, y,
						(rSave.right - rSave.left) + 1, lpImgScanline))
						goto BadRead;
					lp = lpImgScanline;
				}
				else
				{
					if ( !(lp = FramePointer( lpFrame, rSave.left, y, NO )) )
						goto BadRead;
				}

				if (FrameDepth(lpFrame) == 0)
				{
					if ( photomet == 3 ) // If we are storing palette color
						OptimizeData(0, y, npix, lp, lpBuffer, 1 );
					else
						ConvertData( lp, 1, npix, lpBuffer, 1 );
				}
				else
				{
					if ( photomet == 3 ) // If we are storing palette color
						OptimizeData(0, y, npix, lp, lpBuffer, FrameDepth(lpFrame));
					else
						ConvertData( lp, FrameDepth(lpFrame), npix, lpBuffer, 1 );
				}
					
				if ( fCompressed )
				{
					if ( CompressLZW( ofp, lpBuffer, bpl ) < 0 )
						goto BadWrite;
				}
				else
				{
					if ( _lwrite( ofp, (LPSTR)lpBuffer, bpl ) != bpl )
						goto BadWrite;
				}
			}
		break;

		case 24 :
			for( y=rSave.top; y<=rSave.bottom; y++ )
			{
				if (AstralClockCursor( y-rSave.top, nlin, bEscapable ))
					goto Cancelled;

				if ( lpObject )
				{
					if (!ImgGetLine( NULL, lpObject, rSave.left, y,
						(rSave.right - rSave.left) + 1, lpImgScanline))
						goto BadRead;
					lp = lpImgScanline;
				}
				else
				{
					if ( !(lp = FramePointer( lpFrame, rSave.left, y, NO )) )
						goto BadRead;
				}

				if (FrameType(lpFrame) != FDT_RGBCOLOR)
				{
					if (FrameType(lpFrame) != FDT_LINEART)
					{
#ifdef STATIC16
						SrcTypeInfo.DataType = FrameType(lpFrame);
						SrcTypeInfo.ColorMap = NULL;
						SrcTypeInfo.DataType = FDT_RGBCOLOR;
						SrcTypeInfo.ColorMap = NULL;

						FrameTypeConvert.Init(SrcTypeInfo, DstTypeInfo, npix);
						FrameTypeConvert.ConvertData((LPTR)lp, (LPTR)lpBuffer, y, npix);
#else					
						FrameTypeConvert(
							(LPTR)lp, FrameType(lpFrame), NULL,
							y,
							(LPTR)lpBuffer, FDT_RGBCOLOR, NULL,
							npix);
#endif							
					}
					else
					{
#ifdef STATIC16
						SrcTypeInfo.DataType = FDT_GRAYSCALE;
						SrcTypeInfo.ColorMap = NULL;
						SrcTypeInfo.DataType = FDT_RGBCOLOR;
						SrcTypeInfo.ColorMap = NULL;

						FrameTypeConvert.Init(SrcTypeInfo, DstTypeInfo, npix);
						FrameTypeConvert.ConvertData((LPTR)lp, (LPTR)lpBuffer, y, npix);
#else					
						FrameTypeConvert(
							(LPTR)lp, FDT_GRAYSCALE, NULL,
							y,
							(LPTR)lpBuffer, FDT_RGBCOLOR, NULL,
							npix);
#endif							
					}

					lpOutputPointer = lpBuffer;
				}
				else
				{
					lpOutputPointer = lp;
				}

				if ( fCompressed )
				{
					if ( CompressLZW( ofp, lpOutputPointer, bpl ) < 0 )
						goto BadWrite;
				}
				else
				{
					if ( _lwrite( ofp, (LPSTR)lpOutputPointer, bpl ) != bpl )
						goto BadWrite;
				}
			}
		break;

		case 32 :
			for( y=rSave.top; y<=rSave.bottom; y++ )
			{
				if (AstralClockCursor( y-rSave.top, nlin, bEscapable ))
					goto Cancelled;

				if ( lpObject )
				{
					if (!ImgGetLine( NULL, lpObject, rSave.left, y,
						(rSave.right - rSave.left) + 1, lpImgScanline))
						goto BadRead;
					lp = lpImgScanline;
				}
				else
				{
					if ( !(lp = FramePointer( lpFrame, rSave.left, y, NO )) )
						goto BadRead;
				}

				if (FrameType(lpFrame) != FDT_CMYKCOLOR)
				{
					if (FrameType(lpFrame) != FDT_LINEART)
					{
#ifdef STATIC16
						SrcTypeInfo.DataType = FrameType(lpFrame);
						SrcTypeInfo.ColorMap = NULL;
						SrcTypeInfo.DataType = FDT_CMYKCOLOR;
						SrcTypeInfo.ColorMap = NULL;

						FrameTypeConvert.Init(SrcTypeInfo, DstTypeInfo, npix);
						FrameTypeConvert.ConvertData((LPTR)lp, (LPTR)lpBuffer, y, npix);
#else					
						FrameTypeConvert(
							(LPTR)lp, FrameType(lpFrame), NULL,
							y,
							(LPTR)lpBuffer, FDT_CMYKCOLOR, NULL,
							npix);
#endif							
					}
					else
					{
#ifdef STATIC16
						SrcTypeInfo.DataType = FDT_GRAYSCALE;
						SrcTypeInfo.ColorMap = NULL;
						SrcTypeInfo.DataType = FDT_CMYKCOLOR;
						SrcTypeInfo.ColorMap = NULL;

						FrameTypeConvert.Init(SrcTypeInfo, DstTypeInfo, npix);
						FrameTypeConvert.ConvertData((LPTR)lp, (LPTR)lpBuffer, y, npix);
#else					
						FrameTypeConvert(
							(LPTR)lp, FDT_GRAYSCALE, NULL,
							y,
							(LPTR)lpBuffer, FDT_CMYKCOLOR, NULL,
							npix);
#endif							
					}

					lpOutputPointer = lpBuffer;
				}
				else
				{
					lpOutputPointer = lp;
				}

				if ( fCompressed )
				{
					if ( CompressLZW( ofp, lpOutputPointer, bpl ) < 0 )
						goto BadWrite;
				}
				else
				{
					if ( _lwrite( ofp, (LPSTR)lpOutputPointer, bpl ) != bpl )
						goto BadWrite;
				}
			}
		break;
	}

	if ( compressInit )
		if ( CompressLZW( ofp, NULL, 0 ) < 0 ) /* Terminate */
			goto BadWrite;

	compressInit = NO;
	OptimizeEnd();

	if (ofp != oFile)
		_lclose(ofp);

	if (lpBuffer)
		FreeUp( lpBuffer );

	if (lpImgScanline)
		FreeUp( lpImgScanline );

	ProgressEnd();

	return( 0 );

BadWrite:
	Message( IDS_EWRITE, lpFileName );
	goto BadTiff;

BadRead:
	Message( IDS_EREAD, (LPTR)Control.RamDisk );

Cancelled:
BadTiff:
	if ( compressInit )
		if ( CompressLZW( ofp, NULL, 0 ) < 0 ) /* Terminate */
			goto BadWrite;

	compressInit = NO;

	OptimizeEnd();

	if (ofp != oFile)
		_lclose(ofp);

	lstrcpy(temp,lpFileName);
	FileDelete(temp);

Exit:

	if (lpBuffer)
		FreeUp( lpBuffer );

	if (lpImgScanline)
		FreeUp( lpImgScanline );

	ProgressEnd();

	return( -1 );
}
Esempio n. 14
0
BOOL CWriteBitmap::CTWrite()
   {
	RECT              rSave;
	FRMTYPEINFO       inType, outType;
	LPFRAME           lpFrame;
	CFrameTypeConvert TypeConvert;
	LPOBJECT          lpObject;
	CFile 	         theFile;
	CFile*	         pTheFile = NULL;
	BOOL              fRet = FALSE;
	LPTR              lpTH, lp, lp2,lpBuffer, lpImgScanline;
	int               i,x,j,y, LineSize, npix, nlin;
   double            dbl;
   int               NumOfChannels = 4;

	if (m_lpObjList)
	   {
		lpObject = m_lpObjList->lpHead;
		if (lpObject)
			lpFrame = ObjGetEditFrame(lpObject);
	   }
	else
	   {
		lpFrame = m_lpFrame;
		lpObject = NULL;
	   }

	ASSERT(lpFrame);

	if (m_fSrcArea)
		rSave = m_rSrcArea;
	else
	   {
		rSave.top    = rSave.left = 0;
		rSave.bottom = FrameYSize(lpFrame)-1;
		rSave.right  = FrameXSize(lpFrame)-1;
	   }

	npix = RectWidth(&rSave);
	nlin = RectHeight(&rSave);
	inType = FrameTypeInfo(lpFrame);
	// cause FramePointer never returns line art
	if (inType.DataType == FDT_LINEART)
		inType.DataType = FDT_GRAYSCALE;
   
	if (inType.DataType == FDT_GRAYSCALE)
      {
      NumOfChannels = 1;
	   FrameSetTypeInfo(&outType, FDT_GRAYSCALE);
      }
   else
	   FrameSetTypeInfo(&outType, FDT_CMYKCOLOR);
		// initialize stuff to do the type conversion
	ProgressBegin(1);
	if ((pTheFile = OpenFile()) == NULL)
	{
		ProgressEnd();
		return(FALSE);
	}

   if (npix & 1) // odd pixels
      LineSize = npix + 1;
   else
      LineSize = npix;

	AllocLines(&lpBuffer, 1, max(LineSize*NumOfChannels, FrameByteWidth(lpFrame)), 1);
	AllocLines(&lpImgScanline, 1, max(LineSize*NumOfChannels, FrameByteWidth(lpFrame)), 1);
	if (!lpBuffer || !lpImgScanline)
	   {
	   SetError(BEC_errMemory);
		goto Exit;
	   }

   if (!(lpTH = Alloc(1024)))
	   {
	   SetError(BEC_errMemory);
	   return(NULL);
	   }

   clr( (LPTR)lpTH, 1024);
   
   set(lpTH, 80, ' ');
   lstrcpy((LPSTR)lpTH, m_lpFileName);
   lpTH[lstrlen(m_lpFileName)] = ' ';
   lpTH[80] = 'C';
   lpTH[81] = 'T';
	pTheFile->Write(lpTH, 1024);  // write first cluster

   clr( (LPTR)lpTH, 84);
   lpTH[0] = 1;               // inches
   lpTH[1] = NumOfChannels;   // 
   if (NumOfChannels == 1)
      *((LPWORD)&lpTH[2]) = 0x0800;
   else
      *((LPWORD)&lpTH[2]) = 0x0F00;
   dbl = nlin / (double)lpFrame->Resolution;
   sprintf((LPSTR)&lpTH[4], "%+.7E",dbl);
   lpTH[6] = lpTH[5];
   lpTH[5] = '.';
   if (lpTH[15] == '+')
      lpTH[17] = lpTH[18] + 1;
   else
      {
      lpTH[17] = lpTH[18] - 1;
      lpTH[15] = '+';
      }
   dbl = npix / (double)lpFrame->Resolution;
   sprintf((LPSTR)&lpTH[18], "%+.7E",dbl);
   lpTH[20] = lpTH[19];
   lpTH[19] = '.';
   if (lpTH[29] == '+')
      lpTH[31] = lpTH[32] + 1;
   else
      {
      lpTH[31] = lpTH[32] - 1;
      lpTH[29] = '+';
      }
   sprintf((LPSTR)&lpTH[32], "%+12d",nlin);
   lpTH[32] = '+';
   for (i=33; i < 44;i++)
      if (lpTH[i] == ' ' || lpTH[i] == '+')
         lpTH[i] = '0';
   sprintf((LPSTR)&lpTH[44], "%+12d",npix);
   lpTH[44] = '+';
   for (i=45; i < 56;i++)
      if (lpTH[i] == ' ' || lpTH[i] == '+')
         lpTH[i] = '0';
   lpTH[56] = 0;                 // scan direction
	pTheFile->Write(lpTH, 1024);  // write second cluster, Parameter Block
	TRY
	   {
	   if (!TypeConvert.Init(inType, outType, npix, DT_DEFAULT))
	      {
		   SetError(BEC_errMemory);
		   goto Exit;
		   }
		for( y=rSave.top; y <= rSave.bottom; y++)
		   {
			if (Progress( y-rSave.top, nlin, m_bEscapable ))
				goto Cancelled;
			if (lpObject)
			   {
				if (!ObjGetLine( lpObject, rSave.left, y,
					(rSave.right - rSave.left) + 1, lpImgScanline))
					goto BadRead;
				lp = lpImgScanline;
			   }
			else
			   {
				if ( !(lp = FramePointer( lpFrame, rSave.left, y, NO )) )
					goto BadRead;
			   }
			// convert the data to the new type
			TypeConvert.ConvertData(lp, lpBuffer, y, npix);
         lp2 = lpBuffer;
         for (x=0; x < npix; x++)
            for (j=0; j < NumOfChannels; j++)
               *(lpImgScanline + j * LineSize + x) = 255 - *lp2++;
			pTheFile->Write( lpImgScanline, LineSize*NumOfChannels);
         }
		fRet = TRUE;
		goto Exit;
	   }
	CATCH_ALL(e)
	   {
		goto BadWrite;
	   }
	END_CATCH_ALL


BadWrite:
   SetError(BEC_errWriteFile);
	goto Exit;

BadRead:
	SetError(BEC_errFrameRead);

Cancelled:
Exit:
	CloseFile(pTheFile, fRet);

	if (lpTH)
		FreeUp (lpTH);
	if (lpBuffer)
		FreeUp(lpBuffer);
	if (lpImgScanline)
		FreeUp(lpImgScanline);
	ProgressEnd();

	return( fRet );
   }
Esempio n. 15
0
void grabber( LPSTR lpExtName, int port, HINSTANCE hInstance, HWND hWindow )
{

	HWND hWnd;
/*
	special conditions:
		hand scan interface --	
			with hand scanners the dialog box has a scan
			frame which gets filled with image data.  the
			dialog box must remain up during reads, so we
			use the exported frame_open, cacheptr, and
			frame_close to create the frame instead of 
			device reads.  Devopen just returns devcaps,
			devstart does everything else.
	
		special willow gs --	
			the gs board has 4 different buffers, which
			contain the following: 0-even pix/even lines,
			1-odd pix/even lines, 2-even pix/odd lines,
			3-odd pix/odd lines.
			each call to devread will layer the data so
			that the buffers will be combined correctly.
	
	Device Requirements Byte Decoding:

		XXXXXXX1b =  need to take over display
		XXXXXXX0b =  no need to take over display
		XXXXXX1Xb =  special willow gs read
		XXXXXX0Xb =  no special read 
		XXXX00XXb =  image depth, special case palette color 8-bit
		XXXX01XXb =  depth == 1
		XXXX10XXb =  depth == 2
		XXXX11XXb =  depth == 3
		X1XXXXXXb = special hand scan i/f 
		X0XXXXXXb = standard grab i/f
		XX1XXXXXb = don't free DLL after exit
		XX0XXXXXb = free DLL after exit 
		1XXXXXXXb = putting data from cache to external device
		0XXXXXXXb = putting data from external device into cache
		*/

	BYTE devreq; // device requirements
	LPFRAME lpFrame, lpOldFrame;
	BYTE depth;
	int lncnt,Datatype;
	HMODULE hDLL;
	LPIMAGE lpImage;

	if ( !(hDLL = (HMODULE)LoadGrabberLibrary(lpExtName)) ) {
		Message( IDS_EBADDRIVER, NULL );
		return;
	}

	if ( !(lpImage = GetActiveImage()))
		lpFrame = NULL;
	else
		lpFrame = ImgGetBaseEditFrame(lpImage);

   lpfnDevName     = (DEVNAMEPROC)GetProcAddress(hDLL, MAKEINTRESOURCE(301));
   lpfnDevOpen     = (DEVOPENPROC)GetProcAddress(hDLL, MAKEINTRESOURCE(302));
   lpfnDevCall     = (DEVCALLPROC)GetProcAddress(hDLL, MAKEINTRESOURCE(303));
   lpfnDevClose    = (DEVCLOSEPROC)GetProcAddress(hDLL, MAKEINTRESOURCE(304));
   lpfnAcquireProc = (DLGPROC)GetProcAddress(hDLL, MAKEINTRESOURCE(305));

	/* get device's intentions -- is this a put to or read from cache */
	DevInfo.hInst = hInstance;  /* set the data structures */
	DevInfo.hPw = hWindow;
	DevInfo.bFile_is_open = ( lpFrame != NULL );

	if(DevInfo.bFile_is_open)
		{
		DevInfo.bImg_type = (lpImage->DataType==IDC_SAVECT ? TRUE : FALSE);
		/* pass the current filename */
		lstrcpy(DevInfo.cfname, lpImage->CurFile); 
		}

	if(!DevOpen(&DevInfo)) {
		DevCall(DEV_MSG, (LPTR)&DevMsg);
		
		/* if MsgNo == 0, then user cancelled */
		if(DevMsg.MsgNo) {
			if(DevMsg.MsgNo > 0) {
				Message( DevMsg.MsgNo );
			} else {
				/* print the driver's message */
				Print("%ls", (LPTR)DevMsg.szMsg);
			}
		}
		return; 
	}

	bKeepDLL = (DevInfo.device_caps & 0x20);
	devreq = DevInfo.device_caps;
	
	/* doing a put cache to an external device */
	if(!(devreq & 0x80)) {
		/* fill up the device info data structure */
		DevInfo.npix = FrameXSize( lpFrame );
		DevInfo.nlin = FrameYSize( lpFrame );
		DevInfo.bpl =  FrameXSize( lpFrame );
		DevInfo.xres = DevInfo.yres = FrameResolution( lpFrame );
		DevInfo.bpp = 8;
	} else {
		DevInfo.port = port; /* set the port for devices which require it */
#ifndef WIN32
		DevInfo.vgaaddr = GetA000H(); /* set the VGA buffer address */
#endif
	}

	/* see if we need to take over display */
	if(devreq & 1) {
		/* Hide the Cursor */
		ShowCursor( FALSE );

		/* Create the acquire window: it doesn't have the visable bit set */
		AstralDlg( YES, hInstance, hWindow, IDD_GRAB, AcquireProc);
		AstralDlgShow( IDD_GRAB );

		/* Enter the picture window command processor */
		SetCapture( AstralDlgGet( IDD_GRAB ) );

		/* set the data structures */
		DevInfo.hInst = hInstance;  
		DevInfo.hPw   = AstralDlgGet( IDD_GRAB );

		/* call display driver disable */
#ifndef WIN32
		PicwinOn((LPSTR)palette1);
#endif
	}

	if(devreq & 0x40) { // devstart does everything
		DevInfo.FpPtr = (LPTRPROC)MakeProcInstance(
			(FARPROC)grabber_frame_ptr, DevInfo.hInst);

		DevInfo.FoPtr = (LPTRPROC)MakeProcInstance(
			(FARPROC)grabber_frame_open, DevInfo.hInst);

		DevInfo.FsPtr = (LPTRPROC)MakeProcInstance(
			(FARPROC)grabber_frame_set, DevInfo.hInst);

		DevInfo.FcPtr = (LPROC)MakeProcInstance(
			(FARPROC)grabber_frame_close, DevInfo.hInst);

		DevInfo.CcPtr = (LPROC)MakeProcInstance(
			(FARPROC)grabber_AstralClockCursor, DevInfo.hInst);
	}

	DevInfo.bLineArtAsGray = Control.LineArtAsGray;
 
	if(!DevCall(DEV_START, (LPTR)&DevInfo)) { /* if get, fill struct */
		back_to_windows(devreq & 1); /* restore if true */

		DevCall(DEV_MSG, (LPTR)&DevMsg);

		/* if MsgNo == 0, then user cancelled */
		if(DevMsg.MsgNo) {
			if(DevMsg.MsgNo > 0) {
				Message( DevMsg.MsgNo );
			} else {
				/* print the driver's message */
				Print("%ls", (LPTR)DevMsg.szMsg);
			}
		}

		if(devreq & 0x40) { // devstart does everything
			FreeProcInstance((FARPROC)DevInfo.FpPtr);
			FreeProcInstance((FARPROC)DevInfo.FoPtr);
			FreeProcInstance((FARPROC)DevInfo.FsPtr);
			FreeProcInstance((FARPROC)DevInfo.FcPtr);
			FreeProcInstance((FARPROC)DevInfo.CcPtr);
		}

		DevClose(); /* close the device */
		return;
	}

	/* DEV_START returned ok, now get or put image data if not done */

	if((devreq & 0xc0) == 0x80) { // putting data into the cache with devreads
		if(((devreq & 4) == 4) || ((devreq & 0x0c) == 0)) {
			depth = 1;
		} else {
			if((devreq & 8) == 8) {
				depth = 2;
			} else {
				if((devreq & 0x0c) == 0x0c) {
					depth = 3;
				}
			}
		}

		lpOldFrame = frame_set( NULL );
	
		if(!(lpFrame = FrameOpen(
				(FRMDATATYPE)depth,DevInfo.npix,DevInfo.nlin,DevInfo.xres))) {

			back_to_windows(devreq & 1); /* Restore if true */
	
			FrameError(IDS_EIMAGEOPEN);
			return;
		}
	
		frame_set(lpFrame);
	
		if(!(devreq & 2))	{
			for ( lncnt=0; lncnt<DevInfo.nlin; lncnt++ ) {
				DevData.ImageAddress = FramePointer(lpFrame, 0, lncnt, YES);
				if(!DevCall(DEV_READ, (LPTR)&DevData)) {
		         back_to_windows(devreq & 1); /* Restore if true */
					DevCall(DEV_MSG, (LPTR)&DevMsg);
	
					/* if MsgNo == 0, then user cancelled */
					if(DevMsg.MsgNo) {
						Print("Unable to get data from device");
					} else {
						DevInfo.nlin = lncnt;  // hand scanner, get total lines
					}
					return;
				}
			}
		} else { /* special willow gs reader */
	
			/* read even bytes, even lines */
			for ( lncnt=0; lncnt<DevInfo.nlin; lncnt+=2 ) {
				DevData.ImageAddress = FramePointer(lpFrame, 0, lncnt, YES);
				if(!DevCall(DEV_READ0, (LPTR)&DevData)) {
					back_to_windows(devreq & 1); /* Restore if true */
					Print("Unable to get data from device");
					return;
				}
			}
	
			/* read odd bytes, even lines */
			for ( lncnt=0; lncnt<DevInfo.nlin; lncnt+=2 ) {
				DevData.ImageAddress = FramePointer(lpFrame, 1, lncnt, YES);
				if(!DevCall(DEV_READ1, (LPTR)&DevData)) {
					back_to_windows(devreq & 1); /* Restore if true */
					Print("Unable to get data from device");
					return;
				}
			}
	
			/* read even bytes, odd lines */
			for ( lncnt=1; lncnt<DevInfo.nlin; lncnt+=2 ) {
				DevData.ImageAddress = FramePointer(lpFrame, 0, lncnt, YES);
				if(!DevCall(DEV_READ2, (LPTR)&DevData)) {
					back_to_windows(devreq & 1); /* Restore if true */
					Print("Unable to get data from device");
					return;
				}
			}
	
			/* read odd bytes, odd lines */
			for ( lncnt=1; lncnt<DevInfo.nlin; lncnt+=2 ) {
				DevData.ImageAddress = FramePointer(lpFrame, 1, lncnt, YES);
				if(!DevCall(DEV_READ3, (LPTR)&DevData)) {
					back_to_windows(devreq & 1); /* Restore if true */
					Print("Unable to get data from device");
					return;
				}
			}
		}
		
		FrameClose( lpOldFrame );
	
		back_to_windows(devreq & 1); /* Restore if true */
	
		if(DevInfo.bpp == 1) {
			Datatype = IDC_SAVELA;
		} else {
			if(DevInfo.bpp == 8) {
				Datatype = IDC_SAVECT;
			} else {
				Datatype = IDC_SAVE24BITCOLOR;
			}
		}
	
		/* Setup the new image and bring up the new image window */
        LPIMAGE lpNewImage = CreateImage(NULL, lpFrame, NULL, 
           NULL, Control.DefaultFileType, Datatype, 
           IMG_DOCUMENT, NULL);
        if (lpNewImage)
        {
            if (PictPubApp.OpenDocumentFile((LPSTR)lpNewImage->CurFile,
               lpNewImage))         
            {
               	/* only version of image is in the cache */
            	/* so insure user is asked about saving when done */
                lpNewImage->fChanged = TRUE;
            }
            else
                DestroyImage(lpNewImage);
        }
	
		DevClose(); /* close the device */
	} else {
        LPIMAGE lpNewImage = NULL;

		/* enable the frame created by DevStart */
		lpFrame = frame_set(NULL);

		/* putting data to external device with DevWrites */
		if((devreq & 0xc0) == 0) {
			for ( lncnt=0; lncnt<DevInfo.nlin; lncnt++ ) {
				AstralClockCursor( lncnt, DevInfo.nlin, NO );
				DevData.ImageAddress = FramePointer(lpFrame, 0, lncnt, NO);
				if(!DevCall(DEV_WRITE, (LPTR)&DevData)) {
					Print("Unable to put data to device");
					return;
				}
			}
		} else {
			/* devstart has created a frame with image data */
			FreeProcInstance((FARPROC)DevInfo.FpPtr);
			FreeProcInstance((FARPROC)DevInfo.FoPtr);
			FreeProcInstance((FARPROC)DevInfo.FsPtr);
			FreeProcInstance((FARPROC)DevInfo.FcPtr);

			if(DevInfo.bpp == 1) {
				Datatype = IDC_SAVELA;
			} else {
				if(DevInfo.bpp == 8) {
					Datatype = IDC_SAVECT;
				} else {
					Datatype = IDC_SAVE24BITCOLOR;
				}
			}

			back_to_windows(devreq & 1); /* Restore if true */

			/* enable the frame created by DevStart */
			lpFrame = frame_set(NULL);

			/* DevInfo.nlin returns the actual line count */
			if(FrameYSize(lpFrame) <= DevInfo.nlin) {
				/* Setup the new image and bring up the new image window */
            {
                lpNewImage = CreateImage(NULL, lpFrame, NULL, 
                   NULL, Control.DefaultFileType, Datatype, 
                   IMG_DOCUMENT, NULL);
                if (lpNewImage)
                {
                    if (!PictPubApp.OpenDocumentFile((LPSTR)lpNewImage->CurFile,
                       lpNewImage))         
                    {
                        DestroyImage(lpNewImage);
                        lpNewImage = NULL;
                    }
                }
            }

			} else {
				/* create a new frame of the right size and copy  */
				/* the right number of lines to it */

				lpOldFrame = FrameOpen(
					FrameType(lpFrame),
					FrameXSize(lpFrame), 
					DevInfo.nlin,
					FrameResolution(lpFrame));

				AstralCursor( IDC_WAIT );

				for(lncnt=0; lncnt<DevInfo.nlin; lncnt++) {
					FrameCopyLine(lpFrame, lpOldFrame, lncnt);
				}

				FrameClose(lpFrame);
				lpFrame = lpOldFrame;
				AstralCursor( NULL );
				/* Setup the new image and bring up the new image window */
                lpNewImage = CreateImage(NULL, lpFrame, NULL, 
                   NULL, Control.DefaultFileType, Datatype, 
                   IMG_DOCUMENT, NULL);
                if (lpNewImage)
                {
                    if (!PictPubApp.OpenDocumentFile((LPSTR)lpNewImage->CurFile,
                       lpNewImage))         
                    {
                        DestroyImage(lpNewImage);
                        lpNewImage = NULL;
                    }
                }

			}
			/* only version of image is in the cache */
			/* so insure user is asked about saving when done */
            if (lpNewImage)    
                lpNewImage->fChanged = TRUE;

			DevClose(); /* close the device */
		}
	}
}
Esempio n. 16
0
static BOOL FAR MazeToolProc (HWND hWnd,LONG lParam,WORD wMsg)
{
    HDC     hDC;
    LPFRAME lpFrame;
    LPTR    lpLine;
    POINT   pt;
    RGBS    Pixel;
    static int x1,y1;

    pt.x = LOWORD(lParam);
    pt.y = HIWORD(lParam);
    switch (wMsg)
    {
    case WM_LBUTTONDOWN:
        if (!bTrack)
        {
            lpFrame = ImgGetBaseEditFrame (lpImage);
            lpLine = FramePointer (lpFrame,pt.x,pt.y,FALSE);
            FrameGetRGB (lpFrame,lpLine,&Pixel,1);
            if (Pixel.green && !(Pixel.red & Pixel.blue)) // start green pel
            {
//                SoundStartID (IDC_LINES,NO,0);
                SoundStartResource ("icons",NO,0);
                MazeTrailPoints[0].x = x1 = pt.x;
                MazeTrailPoints[0].y = y1 = pt.y;
                nNumTrailPoints = 1;
                if (bShowSolution || bSolved)
                {
                    bShowSolution = bSolved = FALSE;
                    InvalidateRect (hWnd,NULL,FALSE);
                    UpdateWindow (hWnd);
                }
                bTrack = TRUE;
            }
            else if (!AnimateProc(hWnd,lParam,wMsg))
                SoundStartResource ("WRONGANSWER1",NO,0);
        }
        break;
    case WM_MOUSEMOVE:
        if (!bTrack)
            break;
        if (!fAppActive || GetUpdateRect (hWnd,NULL,FALSE))
        {
            InvertLine (hWnd,x1,y1,x1,y1);
            break;
        }
        InvertLine (hWnd,x1,y1,pt.x,pt.y);
        if (!LBUTTON || (pt.x == x1 && pt.y == y1))
            break;
        // else button is down, so fall through to anchor a point
    case WM_LBUTTONUP:
        if (bTrack)
        {
            if (PathIsClear (x1,y1,pt.x,pt.y))
            {
                lpFrame = ImgGetBaseEditFrame (lpImage);
                lpLine = FramePointer (lpFrame,pt.x,pt.y,FALSE);
                FrameGetRGB (lpFrame,lpLine,&Pixel,1);
                if (Pixel.red && !(Pixel.green & Pixel.blue)) // end red pel
                {
                    SoundStartResource ("GOODANSWER1",NO,0);
					StartAnimation(hWnd);
                    bSolved = TRUE;
                    bTrack = FALSE;
                }
                else
                {
                    hDC = GetDC (hWnd);
                    DrawLineEx (hDC,x1,y1,pt.x,pt.y,
                        hMazePen ? hMazePen : (HPEN)GetStockObject (BLACK_PEN),FALSE);
                    ReleaseDC (hWnd,hDC);
                    x1 = pt.x;
                    y1 = pt.y;
                    if (nNumTrailPoints < MAX_LINEPOINTS)
                    {
                        MazeTrailPoints[nNumTrailPoints].x = x1;
                        MazeTrailPoints[nNumTrailPoints].y = y1;
                        nNumTrailPoints++;
                    }
                }
            }
            else
                SoundStartResource ("WRONGANSWER1",NO,0);
        }
        break;
    case WM_PAINT:
        if (bTrack)
        {
            int i;

            hDC = GetDC (hWnd);
            pt.x = MazeTrailPoints[0].x;
            pt.y = MazeTrailPoints[0].y;
            for (i = 1; i < nNumTrailPoints; i++)
            {
                DrawLineEx (hDC,pt.x,pt.y,
                    MazeTrailPoints[i].x,MazeTrailPoints[i].y,
                    hMazePen ? hMazePen : (HPEN)GetStockObject (BLACK_PEN),FALSE);
                pt.x = MazeTrailPoints[i].x;
                pt.y = MazeTrailPoints[i].y;
            }
            ReleaseDC (hWnd,hDC);
        }
        break;
    }
    return TRUE;
}
Esempio n. 17
0
BOOL PSPrint(
	LPIMAGE lpImage,
	LPFRAME lpFrame,
	BYTE    cSep,
	int     xSrc,
	int     ySrc,
	int     dxSrc,
	int     dySrc,
	int     xDest,
	int     yDest,
	int     dxDest,
	int     dyDest,
	int     iPrResX,
	int     iPrResY )
{
int y, yline, ystart, ylast, x, depth;
LFIXED yrate, yoffset;
LPTR lpBuffer[5], p1Buf, p2Buf, p3Buf, p4Buf;
LPSTR lpAngle, lpRuling;
LPTR lpImageData;
BOOL Negative, Asciize;
STRING szAngle, szRuling;
long lSize;
LPFRAME lpBaseFrame;

#define C_ANGLE Halftone.ScreenAngle[0]
#define M_ANGLE Halftone.ScreenAngle[1]
#define Y_ANGLE Halftone.ScreenAngle[2]
#define K_ANGLE Halftone.ScreenAngle[3]
#define C_RULING Halftone.ScreenRuling[0]
#define M_RULING Halftone.ScreenRuling[1]
#define Y_RULING Halftone.ScreenRuling[2]
#define K_RULING Halftone.ScreenRuling[3]

ProgressBegin(1,0);

lpAngle = szAngle;
lpRuling = szRuling;
Negative = Page.Negative;
Asciize = !Page.BinaryPS;

PS_ID( IDS_PS_DICTDEF );

/* Send the definition of the read data function */
if ( Asciize )
{
	PS_ID( IDS_PS_HEXDATA );
}
else
{
	PS_ID( IDS_PS_BINDATA );
}

if ( !Halftone.DoHalftoning )
	goto HalftoningDone;

/* Send the definition of the spot function */
if ( Halftone.DotShape == IDC_ELLIPSEDOT )
	{
	PS_ID( IDS_PS_ELLDOT1 );
	PS_ID( IDS_PS_ELLDOT2 );
	}
else
if ( Halftone.DotShape == IDC_SQUAREDOT )
	{
	PS_ID( IDS_PS_SQUDOT );
	}
else
if ( Halftone.DotShape == IDC_CIRCLEDOT )
	{
	PS_ID( IDS_PS_CIRDOT );
	}
else
if ( Halftone.DotShape == IDC_TRIANGLEDOT )
	{
	PS_ID( IDS_PS_TRIDOT );
	}
else
if ( Halftone.DotShape == IDC_PROPELLERDOT )
	{
	PS_ID( IDS_PS_PROPDOT );
	}

if ( Page.OutputType == IDC_PRINT_BLACKSEPS ||
     Page.OutputType == IDC_PRINT_GRAY )
	{ // Setup the "image" screen angles and freqs based on the sep
	if ( cSep == 'C' )
		{
		FixedAscii( C_ANGLE,  lpAngle,  -2 );
		FixedAscii( C_RULING, lpRuling, -2 );
		}
	else
	if ( cSep == 'M' )
		{
		FixedAscii( M_ANGLE,  lpAngle,  -2 );
		FixedAscii( M_RULING, lpRuling, -2 );
		}
	else
	if ( cSep == 'Y' )
		{
		FixedAscii( Y_ANGLE,  lpAngle,  -2 );
		FixedAscii( Y_RULING, lpRuling, -2 );
		}
	else
	//if ( cSep == 'K' || cSep == 'X' || !cSep )
		{
		FixedAscii( K_ANGLE,  lpAngle,  -2 );
		FixedAscii( K_RULING, lpRuling, -2 );
		}
	PS_ID2( IDS_PS_SETSCREEN, lpRuling, lpAngle );
	}
else
	{ // Setup the "colorimage" screen angles and frequencies
	PS_ID( IDS_PS_COLOREXT );
	PS_ID( IDS_PS_STARTBLOCK );

	FixedAscii( C_RULING, lpRuling, -2 );
	FixedAscii( C_ANGLE,  lpAngle,  -2 );
	PS_ID2( IDS_PS_SETSPOT, lpRuling, lpAngle );

	FixedAscii( M_RULING, lpRuling, -2 );
	FixedAscii( M_ANGLE,  lpAngle,  -2 );
	PS_ID2( IDS_PS_SETSPOT, lpRuling, lpAngle );

	FixedAscii( Y_RULING, lpRuling, -2 );
	FixedAscii( Y_ANGLE,  lpAngle,  -2 );
	PS_ID2( IDS_PS_SETSPOT, lpRuling, lpAngle );

	FixedAscii( K_RULING, lpRuling, -2 );
	FixedAscii( K_ANGLE,  lpAngle,  -2 );
	PS_ID2( IDS_PS_SETSPOT, lpRuling, lpAngle );
	PS_ID( IDS_PS_SETCOLORSCREEN );
	PS_ID( IDS_PS_ENDBLOCK );

	PS_ID( IDS_PS_STARTBLOCK );
	FixedAscii( K_RULING, lpRuling, -2 );
	FixedAscii( K_ANGLE,  lpAngle,  -2 );
	PS_ID2( IDS_PS_SETSCREEN, lpRuling, lpAngle );
	PS_ID( IDS_PS_ENDBLOCK );
	PS_ID( IDS_PS_IFELSE );
	}

HalftoningDone:

// Setup a null transfer curve unless doing seps w/black ink (image operator)
if ( Page.OutputType == IDC_PRINT_BLACKSEPS )
{
	PS_ID( IDS_PS_BLACKSEPS );
}
else
if ( Page.OutputType == IDC_PRINT_COLORSEPS )
{
	PS_ID( IDS_PS_COLORSEPS );
}
else
{
	PS_ID( IDS_PS_NOINVERT );
}

PS_ID( IDS_PS_CHECKINVERT );

/* Send the destination point (x,y) in spots */
PS_ID2( IDS_PS_TRANSLATE, xDest, yDest );

/* Send the destination size (w,h) in spots */
PS_ID2( IDS_PS_SCALE, dxDest, dyDest );

if (lpImage)
	lpBaseFrame =  ImgGetBaseEditFrame(lpImage);
else 
	lpBaseFrame = lpFrame;
/* Compute how many pixels we're going to send */
/* Never send more than 16 pixels per halftone grid (or 4/grid in x and y) */
if (depth = FrameDepth( lpBaseFrame ))
	{
	if ( iPrResX < 600 )
		dxDest /= 4;
	else	dxDest /= 8;
	if ( iPrResY < 600 )
		dyDest /= 4;
	else	dyDest /= 8;
	}

if (depth == 0) depth = 1;

/* Let the printer do any upsizing */
if ( dySrc < dyDest )
	{
	yrate = UNITY;
	dxDest = dxSrc;
	dyDest = dySrc;
	}
else yrate = FGET( dySrc, dyDest );

/* Send the definition for the line buffers */
PS_ID1( IDS_PS_LINE1, dxDest );
PS_ID1( IDS_PS_LINE2, dxDest );
PS_ID1( IDS_PS_LINE3, dxDest );
PS_ID1( IDS_PS_LINE4, dxDest );
PS_ID1( IDS_PS_LINE5, dxDest );

if ( cSep ) // Plane at a time
{ // cSep is either 'C', 'M', 'Y', 'K', 'X'(gray) or NULL
	if ( Page.OutputType == IDC_PRINT_COLORSEPS )
	{
		PS_ID( IDS_PS_DOCOLORSEPDEF );
	}
	else
	{
		PS_ID( IDS_PS_NOCOLORSEPDEF );
	}

	PS_ID( IDS_PS_DOIMAGEDEF );
	PS_ID( IDS_PS_COLORSEPVAL );

	// Start color image proc
	PS_ID( IDS_PS_STARTBLOCK );
	PS_ID( IDS_PS_STARTBLOCK );

	if ( cSep == 'C' )
	{
		PS_ID( IDS_PS_SEPCYAN );
	}
	else
	if ( cSep == 'M' )
	{
		PS_ID( IDS_PS_SEPMAGENTA );
	}
	else
	if ( cSep == 'Y' )
	{
		PS_ID( IDS_PS_SEPYELLOW );
	}
	else
	if ( cSep == 'K' || cSep == 'X' )
	{
		PS_ID( IDS_PS_SEPBLACK );
	}

	PS_ID( IDS_PS_COLORIMAGE4 );

	PS_ID( IDS_PS_ENDBLOCK );
	PS_ID( IDS_PS_ENDBLOCK );

	// Start gray image proc
	PS_ID( IDS_PS_STARTBLOCK );
	PS_ID( IDS_PS_STARTBLOCK );

	PS_ID( IDS_PS_GETLINE1 );
	PS_ID( IDS_PS_IMAGE );
	PS_ID( IDS_PS_ENDBLOCK );
	PS_ID( IDS_PS_ENDBLOCK );

	PS_ID( IDS_PS_IFELSE );
	PS_ID( IDS_PS_DEF );
}
else
if ( Page.Type == IDC_PRINTER_IS_CMYK )
{
	if (Page.OutputType == IDC_PRINT_COLORGRAY)
	{
		PS_ID( IDS_PS_DOIMAGEDEF );
		PS_ID( IDS_PS_COLOREXT );

		// Start color image proc
		PS_ID( IDS_PS_STARTBLOCK );
			PS_ID( IDS_PS_STARTBLOCK );

				PS_ID( IDS_PS_GETLINE1 );
				PS_ID( IDS_PS_GETLINE2 );
				PS_ID( IDS_PS_GETLINE3 );

				PS_ID( IDS_PS_STARTBLOCK );
					PS_ID( IDS_PS_GETLINE4 );
					PS_ID( IDS_PS_GETLINE5 );
					PS_ID( IDS_PS_POP );
				PS_ID( IDS_PS_ENDBLOCK );

				PS_ID( IDS_PS_COLORIMAGE4 );
			PS_ID( IDS_PS_ENDBLOCK );
		PS_ID( IDS_PS_ENDBLOCK );

		// Start gray image proc
		PS_ID( IDS_PS_STARTBLOCK );
			PS_ID( IDS_PS_STARTBLOCK );
				PS_ID( IDS_PS_STARTBLOCK );
					PS_ID( IDS_PS_DUMPLINE1 );
					PS_ID( IDS_PS_DUMPLINE2 );
					PS_ID( IDS_PS_DUMPLINE3 );
					PS_ID( IDS_PS_STARTBLOCK );
						PS_ID( IDS_PS_GETLINE4 );
						PS_ID( IDS_PS_GETLINE5 );
					PS_ID( IDS_PS_ENDBLOCK );
					PS_ID( IDS_PS_IMAGE );
				PS_ID( IDS_PS_ENDBLOCK );
			PS_ID( IDS_PS_ENDBLOCK );
		PS_ID( IDS_PS_ENDBLOCK );

		PS_ID( IDS_PS_IFELSE );
		PS_ID( IDS_PS_DEF );
	}
	else
	{
		PS_ID( IDS_PS_DOIMAGEDEF );
		PS_ID( IDS_PS_COLOREXT );

		// Start color image proc
		PS_ID( IDS_PS_STARTBLOCK );
			PS_ID( IDS_PS_STARTBLOCK );
				PS_ID( IDS_PS_GETLINE1 );
				PS_ID( IDS_PS_GETLINE2 );
				PS_ID( IDS_PS_GETLINE3 );
				PS_ID( IDS_PS_GETLINE4 );
				PS_ID( IDS_PS_COLORIMAGE4 );
			PS_ID( IDS_PS_ENDBLOCK );
		PS_ID( IDS_PS_ENDBLOCK );

		// Start gray image proc
		PS_ID( IDS_PS_STARTBLOCK );
			PS_ID( IDS_PS_STARTBLOCK );
				PS_ID( IDS_PS_STARTBLOCK );
					PS_ID( IDS_PS_DUMPLINE1 );
					PS_ID( IDS_PS_DUMPLINE2 );
					PS_ID( IDS_PS_DUMPLINE3 );
					PS_ID( IDS_PS_GETLINE4 );
				PS_ID( IDS_PS_ENDBLOCK );
				PS_ID( IDS_PS_NOIMAGE );
			PS_ID( IDS_PS_ENDBLOCK );
		PS_ID( IDS_PS_ENDBLOCK );

		PS_ID( IDS_PS_IFELSE );
		PS_ID( IDS_PS_DEF );
	}
}
else
if ( Page.Type == IDC_PRINTER_IS_RGB )
{
	PS_ID( IDS_PS_DOIMAGEDEF );
	PS_ID( IDS_PS_COLOREXT );

	// Start color image proc
	PS_ID( IDS_PS_STARTBLOCK );
	PS_ID( IDS_PS_STARTBLOCK );

	PS_ID( IDS_PS_GETLINE1 );
	PS_ID( IDS_PS_GETLINE2 );
	PS_ID( IDS_PS_GETLINE3 );

	if ( Page.OutputType == IDC_PRINT_COLORGRAY )
	{
		PS_ID( IDS_PS_DUMPLINE4 );
	}

	PS_ID( IDS_PS_COLORIMAGE3 );
	PS_ID( IDS_PS_ENDBLOCK );
	PS_ID( IDS_PS_ENDBLOCK );

	// Start gray image proc
	PS_ID( IDS_PS_STARTBLOCK );
	PS_ID( IDS_PS_STARTBLOCK );

	PS_ID( IDS_PS_STARTBLOCK );
	PS_ID( IDS_PS_DUMPLINE1 );
	PS_ID( IDS_PS_DUMPLINE2 );

	if ( Page.OutputType == IDC_PRINT_COLORGRAY )
	{
		PS_ID( IDS_PS_DUMPLINE3 );
		PS_ID( IDS_PS_GETLINE4 );
		PS_ID( IDS_PS_ENDBLOCK );
		PS_ID( IDS_PS_IMAGE );
	}
	else
	{
		PS_ID( IDS_PS_GETLINE3 );
		PS_ID( IDS_PS_ENDBLOCK );
		PS_ID( IDS_PS_NOIMAGE );
	}
	PS_ID( IDS_PS_ENDBLOCK );
	PS_ID( IDS_PS_ENDBLOCK );
	PS_ID( IDS_PS_IFELSE );
	PS_ID( IDS_PS_DEF );
}

/* Send the inline image's size, packing, and transform */
PS_ID5( IDS_PS_TRANSFORM, dxDest, dyDest, 8, dxDest, dyDest );

if ( !Asciize )
{
	// The size must include the doimage command that follows
	lSize = (long)dxDest * dyDest * depth;
	PS_ID1( IDS_PS_BEGINBINARY, lSize + 9 + 2 );
}

PS_ID( IDS_PS_DOIMAGE ); // Should be 9 characters

for ( x=0; x<5; x++ )
	lpBuffer[x] = NULL;

if (!AllocLines((LPPTR)&lpImageData, 1, dxSrc, depth))
{
	ProgressEnd();
	return(FALSE);
}

if (!AllocLines((LPPTR)&lpBuffer[0], 1, dxDest, depth))
{
	FreeUp( lpImageData );
	ProgressEnd();
	return( FALSE );
}

if (!AllocLines((LPPTR)&lpBuffer[1], 4, dxDest, 1))
{
	FreeUp(lpBuffer[0]);
	FreeUp( lpImageData );
	ProgressEnd();
	return( FALSE );
}

p1Buf  = lpBuffer[1];
p2Buf  = lpBuffer[2];
p3Buf  = lpBuffer[3];
p4Buf  = lpBuffer[4];

ystart  = ySrc;
yline   = -1;
yoffset = (long)yrate>>1;

for (y=0; y<dyDest; y++)
{
	if (AstralClockCursor( y, dyDest, YES ))
	{
		fAbortPrint = YES;
		break;
	}

	/* Check for user input to abort dialog box */
	(*lpAbortTest)(hPrinterDC, 0);
	if ( fAbortPrint )
		break;

	ylast = yline;
#ifdef WIN32
	yline = ystart + WHOLE( yoffset );
#else
	yline = ystart + HIWORD( yoffset );
#endif
	yoffset += yrate;
	if ( yline != ylast )
	{
		LFIXED rate;

		if (lpImage)
			ImgGetLine( lpImage, NULL, xSrc, yline, dxSrc, lpImageData );
		else
			copy(FramePointer(lpBaseFrame, xSrc, yline, NO), lpImageData, dxSrc*depth);
		rate = FGET( dxSrc, dxDest );

		FrameSample(
			lpBaseFrame,
			lpImageData,
			0,
			lpBuffer[0],
			0,
			dxDest,
			rate);
	}

	if ( cSep )
	{ // cSep is either 'C', 'M', 'Y', 'K', 'X'(gray) or NULL
		if (cSep != 'X')
		{
			LPTR lpOutBuf;
			int  iPlaneOffset;

			switch(cSep)
			{
				case 'C' : lpOutBuf = p1Buf; iPlaneOffset = 0; break;
				case 'M' : lpOutBuf = p2Buf; iPlaneOffset = 1; break;
				case 'Y' : lpOutBuf = p3Buf; iPlaneOffset = 2; break;
				case 'K' : lpOutBuf = p4Buf; iPlaneOffset = 3; break;
			}

			switch(depth)
			{
				case 0 :
				case 1 :
					lpOutBuf = (LPTR)lpBuffer[0];
				break;

				case 3 :
					ClrRGBtoCMYK( (LPRGB)lpBuffer[0],
						p1Buf, p2Buf, p3Buf,p4Buf,dxDest,YES);
				break;

				case 4 :
				{
					LPTR lpSrc  = (LPTR)lpBuffer[0];
					LPTR lpDst  = lpOutBuf;
					int  iCount = dxDest;

					lpSrc += iPlaneOffset;

					while(iCount-- > 0)
					{
						*lpDst++ = *lpSrc;
						lpSrc += 4;
					}
				}
				break;
			}

			if (Negative)
				negate(lpOutBuf, (long)dxDest);
			if ( !SendPSData( Asciize, lpOutBuf, dxDest ) )
				goto ErrorExit;
		}
		else
		{
			ConvertData( lpBuffer[0], depth, dxDest, p1Buf, 1 );
			if (Negative)
				negate(p1Buf, (long)dxDest);
			CorrectGray( p1Buf, dxDest, YES, YES );
			if ( !SendPSData( Asciize, p1Buf, dxDest ) )
				goto ErrorExit;
		}
	}
	else if ( Page.Type == IDC_PRINTER_IS_CMYK )
	{
		switch(depth)
		{
			case 0 :
			case 1 :
				copy( lpBuffer[0], p1Buf, dxDest );
				copy( lpBuffer[0], p2Buf, dxDest );
				copy( lpBuffer[0], p3Buf, dxDest );
				copy( lpBuffer[0], p4Buf, dxDest );
			break;

			case 3 :
				ClrRGBtoCMYK( (LPRGB)lpBuffer[0],
					p1Buf, p2Buf, p3Buf,p4Buf,dxDest,YES);
			break;

			case 4 :
			{
				LPTR lpSrc  = (LPTR)lpBuffer[0];
				LPTR lpDst1 = p1Buf;
				LPTR lpDst2 = p2Buf;
				LPTR lpDst3 = p3Buf;
				LPTR lpDst4 = p4Buf;
				int  iCount = dxDest;

				while(iCount-- > 0)
				{
					*lpDst1++ = *lpSrc++;
					*lpDst2++ = *lpSrc++;
					*lpDst3++ = *lpSrc++;
					*lpDst4++ = *lpSrc++;
				}
			}
			break;
		}

		if (Negative)
		{
			negate(p1Buf, (long)dxDest);
			negate(p2Buf, (long)dxDest);
			negate(p3Buf, (long)dxDest);
			negate(p4Buf, (long)dxDest);
		}

		if ( !SendPSData( Asciize, p1Buf, dxDest ) )
			goto ErrorExit;
		if ( !SendPSData( Asciize, p2Buf, dxDest ) )
			goto ErrorExit;
		if ( !SendPSData( Asciize, p3Buf, dxDest ) )
			goto ErrorExit;
		if ( !SendPSData( Asciize, p4Buf, dxDest ) )
			goto ErrorExit;

		if ( Page.OutputType == IDC_PRINT_COLORGRAY )
		{
			ConvertData( lpBuffer[0], depth, dxDest, p1Buf, 1 );

			if (Negative)
				negate(p1Buf, (long)dxDest);

			CorrectGray( p1Buf, dxDest, YES, YES);

			if ( !SendPSData( Asciize, p1Buf, dxDest ) )
				goto ErrorExit;
		}
	}
	else if ( Page.Type == IDC_PRINTER_IS_RGB )
	{
		switch(depth)
		{
			case 0 :
			case 1 :
				copy( lpBuffer[0], p1Buf, dxDest );
				copy( lpBuffer[0], p2Buf, dxDest );
				copy( lpBuffer[0], p3Buf, dxDest );
			break;

			case 3 :
				UnshuffleRGB( (LPRGB)lpBuffer[0],
					p1Buf, p2Buf, p3Buf, dxDest );
			break;

			case 4 :
			{
				LPCMYK lpCMYK = (LPCMYK)lpBuffer[0];
				LPTR lpDst1 = p1Buf;
				LPTR lpDst2 = p2Buf;
				LPTR lpDst3 = p3Buf;
				RGBS rgb;
				int  iCount = dxDest;

				while(iCount-- > 0)
				{
					CMYKtoRGB(lpCMYK->c, lpCMYK->m, lpCMYK->y, lpCMYK->k, &rgb);
					lpCMYK++;

					*lpDst1++ = rgb.red;
					*lpDst2++ = rgb.green;
					*lpDst3++ = rgb.blue;
				}
			}
			break;
		}

		if (Negative)
		{
			negate( p1Buf, dxDest );
			negate( p2Buf, dxDest );
			negate( p3Buf, dxDest );
		}

		if ( !SendPSData( Asciize, p1Buf, dxDest ) )
			goto ErrorExit;

		if ( !SendPSData( Asciize, p2Buf, dxDest ) )
			goto ErrorExit;

		if ( !SendPSData( Asciize, p3Buf, dxDest ) )
			goto ErrorExit;

		if ( Page.OutputType == IDC_PRINT_COLORGRAY )
		{
			ConvertData( (LPTR)lpBuffer[0], depth, dxDest, p1Buf, 1 );

			if (Negative)
				negate(p1Buf, (long)dxDest);

			CorrectGray( p1Buf, dxDest, YES, YES);

			if ( !SendPSData( Asciize, p1Buf, dxDest ) )
				goto ErrorExit;
		}
	}
}

if ( !Asciize )
{
	PS_ID( IDS_PS_ENDBINARY );
}

/* Send the save restore command */
PS_ID( IDS_PS_MYSAVERESTORE );
PS_ID( IDS_PS_END );

ErrorExit:

if ( lpBuffer[0] )
	FreeUp(lpBuffer[0]);
if ( lpBuffer[1] )
	FreeUp(lpBuffer[1]);
if ( lpImageData )
	FreeUp( lpImageData );
ProgressEnd();
return( TRUE );
}