Beispiel #1
0
static LPTR FrameToLineArtDIB( LPFRAME lpFrame, LPRECT lpRect )
{
	int y, bpl, fbpl, i;
	LPTR lpDIBMem;
	HPTR lpDst;
	HPTR lpDstLine;
	LPTR lpSrc;
	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+7)/8;

	lInfoSize = sizeof(BITMAPINFOHEADER) + 2*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      = 1;
	lpInfo->bmiHeader.biSizeImage     = lImageSize;
	lpInfo->bmiHeader.biXPelsPerMeter = (10000L * (long) FrameResolution(lpFrame)) / 254L;
	lpInfo->bmiHeader.biYPelsPerMeter = (10000L * (long) FrameResolution(lpFrame)) / 254L;
	lpInfo->bmiHeader.biClrUsed       = 2;
	lpInfo->bmiHeader.biClrImportant  = 2;

	for (i = 0; i < 2; i++)
	{
		lpInfo->bmiColors[i].rgbBlue     = (i&1) ? 0xFF : 0x00;
		lpInfo->bmiColors[i].rgbGreen    = (i&1) ? 0xFF : 0x00;
		lpInfo->bmiColors[i].rgbRed      = (i&1) ? 0xFF : 0x00;
		lpInfo->bmiColors[i].rgbReserved = 0;
	}

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

	fbpl = FrameByteWidth( lpFrame );

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

		if (lpSrc)
		{
			if (bpl > fbpl)
			{
				iCount = fbpl;

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

				iCount = bpl-fbpl;

				while (iCount-- > 0)
					*lpDst++ = 0;
			}
			else
			{
				iCount = bpl;

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

		lpDstLine += bpl;
	}

	return( lpDIBMem );
}
Beispiel #2
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;
			}
		}
	}
Beispiel #3
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 );
}
Beispiel #4
0
LPFRAME DIBToLineArtFrame( LPTR lpDIBMem, BOOL bForceRGB )
{
	LPBITMAPINFO lpInfo;
	LPFRAME lpFrame;
	HPTR lpSrc;
	HPTR lpSrcLine;
	LPTR lpDst;
	int iResolution;
	int iFrameXSize;
	int iFrameYSize;
	int iPixelFlavor;
	int iSrcWidth;
	int iDstWidth;
	int iCount;
	int y;

	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;
	}

	// Find out whether or not we need to invert
	iPixelFlavor = (lpInfo->bmiColors[0].rgbBlue == 0);

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

	if (!lpFrame) return(NULL);

	// Find the DIB data pointer and width
	lpSrcLine = lpDIBMem + lpInfo->bmiHeader.biSize + 
		lpInfo->bmiHeader.biClrUsed * (sizeof(RGBQUAD));

	iSrcWidth = ((lpInfo->bmiHeader.biWidth+31)/32) * 4;

	iDstWidth = FrameByteWidth( lpFrame );

	// Copy the DIB data into the Frame
	for(y=iFrameYSize-1;y >= 0;y--)
	{
		lpSrc = lpSrcLine;
		lpDst = FramePointerRaw( lpFrame, 0, y, TRUE );

		iCount = iDstWidth;

		if (iPixelFlavor)
		{
			while(iCount-- > 0)
			{
				*lpDst++ = *lpSrc++;
			}
		}
		else
		{
			while(iCount-- > 0)
			{
				*lpDst++ = (*lpSrc++)^0xFF;
			}
		}
		lpSrcLine += iSrcWidth;
	}

	return(lpFrame);
}
Beispiel #5
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 );
   }