Esempio n. 1
0
void ResizePuzzleFrame(LPFRAME lpNewFrame)
{
    LPFRAME     lpOldFrame;
    LPFRAME     lpPrevFrame;
    double      fXMult;
    double      fYMult;
    double      fMult;
    int         iXNew;
    int         iYNew;
    int         iXOld;
    int         iYOld;

    lpOldFrame = ImgGetBaseEditFrame(lpImage);
    iXNew = FrameXSize(lpNewFrame);
    iYNew = FrameYSize(lpNewFrame);
    iXOld = FrameXSize(lpOldFrame);
    iYOld = FrameYSize(lpOldFrame);

    fXMult = (double)iXOld / (double)iXNew;
    fYMult = (double)iYOld / (double)iYNew;
        
    if (fXMult < fYMult)
         fMult = fXMult;
    else fMult = fYMult;
    iXNew = (int)((double)iXNew * fMult);
    iYNew = (int)((double)iYNew * fMult);
    
    lpPrevFrame = lpNewFrame;
    lpNewFrame = SizeFrame(
        lpNewFrame, 
        iXNew, 
        iYNew, 
        FrameResolution(lpOldFrame),
		FALSE);
    FrameClose(lpPrevFrame);

    iXNew = (FrameXSize(lpOldFrame) - FrameXSize(lpNewFrame)) / 2;
    iYNew = (FrameYSize(lpOldFrame) - FrameYSize(lpNewFrame)) / 2;
    iXNew = max(0, iXNew);
    iYNew = max(0, iYNew);
    lpPrevFrame = lpNewFrame;
    lpNewFrame = ExpandFrame(lpNewFrame, 
                    FrameXSize(lpOldFrame), /*pix*/ 
                    FrameYSize(lpOldFrame), /*lin*/ 
                    iXNew,                  /*left*/ 
                    iYNew,                  /*top*/ 
					FrameGetBackground(lpOldFrame));

    ImgReplaceBaseEditFrame(lpImage, lpNewFrame);
    FrameClose(lpPrevFrame);
}
Esempio n. 2
0
LOCAL BOOL size_image(LPIMAGE lpImage, LFIXED Width , LFIXED Height, 
	int Resolution, BOOL bSmartSize)
{
	int pix, lin, res;
	LPFRAME lpDataFrame;
	LPFRAME lpAlphaFrame;
	LPOBJECT lpBase;
	LPALPHA lpAlpha;
	RECT rAlpha;
	
	if (!lpImage)
		return(FALSE);
	lpBase = ImgGetBase(lpImage);
	lpAlpha = lpBase->lpAlpha;
	res = Resolution;

	ProgressBegin(1, 0);
	pix = FMUL( res, Width );
	lin = FMUL( res, Height );
	lpAlphaFrame = NULL;
	if (lpDataFrame = SizeFrame(lpBase->Pixmap.EditFrame, pix, lin, res,
								bSmartSize))
	{
		if (lpAlpha)
			lpAlphaFrame = SizeFrame(lpAlpha->Pixmap.EditFrame, pix, lin,
									res, bSmartSize);
	}
	
	if ( !lpDataFrame || (lpAlpha && !lpAlphaFrame))
	{
		if (lpDataFrame)
			FrameClose(lpDataFrame);
		if (lpAlphaFrame)
			FrameClose(lpAlphaFrame);
		ProgressEnd();
		return( FALSE );
	}
	
	lpBase->rObject.right = FrameXSize(lpDataFrame)-1;
	lpBase->rObject.bottom = FrameYSize(lpDataFrame)-1;
	if (lpAlpha)
		MaskRectUpdate(lpAlpha, &rAlpha);
	ProgressEnd();
	
	return( TRUE );
}
Esempio n. 3
0
void TextureFillProc( HWND hWindow, UINT msg, int x, int y, UINT32 Option )
/************************************************************************/
{
FNAME szFileName;
LPIMAGE lpImage;
TEXTUREFILL_PARMS parms;

switch (msg)
    {
    case WM_CREATE:	// The first mouse down message
	// Load the texture
	if (!IsOnImage(hWindow, x, y))
		break;
	if (!LookupExtFile(Texture.TextureName, szFileName, IDN_TEXTURE))
		break;
	if (!FileExists(szFileName))
		{
		Message(IDS_EOPEN, (LPSTR)szFileName);
		break;
		}
    lpImage = (LPIMAGE)GetImagePtr ( hWindow );
	parms.TextureOpacity = Texture.TextureOpacity;
	parms.TextureMergeMode = Texture.TextureMergeMode;
	lstrcpy(parms.TextureName, Texture.TextureName);
	parms.fHorzFlip = Texture.fHorzFlip;
	parms.fVertFlip = Texture.fVertFlip;
	ProcessCommand(lpImage->lpCmdList, IDS_CMD_TEXTUREFILL, &parms);
	break;

	case WM_ACTIVATE:
	if (!Option) // a deactivate
		{
		FrameClose( lpTextureFrame );
		lpTextureFrame = NULL;
		}
	return;
		
    case WM_LBUTTONDOWN:
	break;

    case WM_LBUTTONUP:
	Tool.bActive = NO;
	break;

    case WM_MOUSEMOVE:	// sent when ToolActive is on
	break;

    case WM_LBUTTONDBLCLK:
	break;

    case WM_DESTROY:	// The cancel operation message
	Tool.bActive = NO;
	break;
    }
}
Esempio n. 4
0
LOCAL LPFRAME ConvertFrame(LPFRAME lpSrcFrame, FRMTYPEINFO OutTypeInfo, CFrameTypeConvert *pTypeConvert)
/***********************************************************************/
{
int	y, Xsize, Ysize;
LPFRAME lpDstFrame;
FRMTYPEINFO InTypeInfo;
LPTR lpSrc, lpDst;
CFrameTypeConvert TypeConvert;

Xsize = FrameXSize(lpSrcFrame);
Ysize = FrameYSize(lpSrcFrame);
FrameGetTypeInfo(lpSrcFrame, &InTypeInfo);
if (!pTypeConvert)
	{
	if (!TypeConvert.Init(InTypeInfo, OutTypeInfo, Xsize))
		{
		Message(IDS_EMEMALLOC);
		return(NULL);
		}
	pTypeConvert = &TypeConvert;
	}

lpDstFrame = FrameOpen(OutTypeInfo, Xsize, Ysize, FrameResolution(lpSrcFrame));
if (!lpDstFrame)
	{
	FrameError(IDS_EPROCESSOPEN);
	return(NULL);
	}

ProgressBegin(1, 0);
for (y = 0; y < Ysize; ++y)
	{
	if (AstralClockCursor(y, Ysize, YES))
		{
		FrameClose(lpDstFrame);
		goto ExitError;
		}
	if (!(lpSrc = FramePointerRaw(lpSrcFrame, 0, y, NO)))
		continue;
	if (!(lpDst = FramePointerRaw(lpDstFrame, 0, y, YES)))
		continue;
	pTypeConvert->ConvertData(lpSrc, lpDst, y, Xsize);
	}

ProgressEnd();
return(lpDstFrame);

ExitError:
ProgressEnd();
return(NULL);
}
Esempio n. 5
0
BOOL RenderToClipboard( HWND hWindow, WORD wFormat )
/************************************************************************/
{
DWORD dwValue;
HGLOBAL hMem;
LPTR lpMem;
LPFRAME lpFrame;
int iDataType, iFileType, fNative;

// This routine assumes that the 2 files to read and render
// are identified by Names.ClipImageFile and Names.ClipMaskFile

fNative = ( pOLE && (wFormat == pOLE->cfNative || !wFormat) ); // Native format is a DIB

if ( wFormat == Control.cfImage || !wFormat )
	{
	if ( hMem = ConstructMGXImage( Names.ClipImageFile, Names.ClipMaskFile ) )
			SetClipboardData( Control.cfImage, hMem );
	else	return( FALSE );
	}

if ( wFormat == CF_DIB || wFormat == CF_BITMAP ||
	 wFormat == CF_METAFILEPICT || !wFormat || fNative )
	{
	if ( !(lpFrame = AstralFrameLoad( Names.ClipImageFile, -1, &iDataType,
		 &iFileType )) )
		return(FALSE);
	}
else
	lpFrame = NULL;

if ( wFormat == CF_DIB || !wFormat || fNative )
	{
	if ( lpMem = FrameToDIB( lpFrame, NULL ) )
		{
#ifdef WIN32		
		hMem = GlobalHandle( lpMem );
#else		
		dwValue = GlobalHandle( HIWORD(lpMem) );
		hMem = (HGLOBAL)LOWORD( dwValue );
#endif
		GlobalUnlock(hMem);
		if ( wFormat == CF_DIB || !wFormat )
			SetClipboardData( CF_DIB, hMem );
		if ( fNative )
			SetClipboardData( pOLE->cfNative, hMem );
		}
	else
		{
		FrameClose( lpFrame );
		return(FALSE);
		}
	}

if ( wFormat == CF_BITMAP || (!wFormat && Control.DoBitmap) )
	{
	if ( hMem = FrameToBitmap( lpFrame, NULL ) )
		SetClipboardData( CF_BITMAP, hMem );
	else
		{
		FrameClose( lpFrame );
		return(FALSE);
		}
	}

if ( wFormat == CF_METAFILEPICT || (!wFormat && Control.DoPicture) )
	{
	if ( hMem = FrameToMetafile( lpFrame, NULL ) )
		SetClipboardData( CF_METAFILEPICT, hMem );
	else
		{
		FrameClose( lpFrame );
		return(FALSE);
		}
	}

if ( lpFrame )
	FrameClose( lpFrame );

if ( wFormat == CF_PALETTE || !wFormat )
	{
	if ( hMem = ConstructPalette( lpBltScreen->hPal ) )
		SetClipboardData( CF_PALETTE, hMem );
	}

return( TRUE );
}
Esempio n. 6
0
int GetCompleteMemoryImage( HWND hWnd, TW_SETUPMEMXFER dcMemSetup )
{
	TW_IMAGEINFO   dcImageInfo;
	TW_IMAGEMEMXFER dcImageData;
	TW_UINT16 dcRC;
	LPTR lpBuffer = NULL;
	LPFRAME lpFrame;
	int imageWidth;
	int need_new;
	int save_type, expand;
	FRMDATATYPE Type;

	dcImageData.Memory.Flags  = TWMF_APPOWNS | TWMF_POINTER;
	dcImageData.Memory.Length = dcMemSetup.Preferred;
	dcImageData.Memory.TheMem = LineBuffer[0];

	// Get the image information, nice to know a little about the 
    // image the Source will be sending
	if( !( *lpDSM_Entry )( &appID, &dsID, DG_IMAGE, DAT_IMAGEINFO, MSG_GET,
			( TW_MEMREF )&dcImageInfo ) == TWRC_SUCCESS )
    {
		return( FALSE );
	}

	// We have the information about the type/size/depth of the image
	// Stored in dcImageInfo.
	imageWidth = dcImageInfo.ImageWidth;
	need_new = FALSE;   // If we have to shrink the image.( hand scanners )

	if( dcImageInfo.ImageLength == -1 ) 
    {
		// Unknown length - hand scanner 
		dcImageInfo.ImageLength = HS_MAXLENGTH * dcImageInfo.YResolution.Whole;
		need_new = TRUE;
	}

	if( dcImageInfo.ImageWidth == -1 ) 
    {
		// Unknown width - hand scanner 
		dcImageInfo.ImageWidth = HS_MAXWIDTH * dcImageInfo.XResolution.Whole;
		need_new = TRUE;
	}

	expand = 0;

	lpTwainPalette = ( pTW_PALETTE8 )NULL;

	// Find out the proper file save type for this image.
	switch( dcImageInfo.PixelType ) 
    {
		case TWPT_BW      : 
			if( Control.LineArtAsGray ) 
            {
				// Create Continuous tone
				Type = FDT_GRAYSCALE;
				save_type = IDC_SAVECT;
				expand = 1;
			} 
            else 
            {
				// Line Art
				Type = FDT_LINEART;
				save_type = IDC_SAVELA;
			}
		    break;

		case TWPT_GRAY    : 
			Type = FDT_GRAYSCALE;
			save_type = IDC_SAVECT;
		    break;

		case TWPT_RGB     : 
			Type = FDT_RGBCOLOR;
			save_type = IDC_SAVE24BITCOLOR;
		    break;

		case TWPT_PALETTE :
			lpTwainPalette = ( pTW_PALETTE8 )Alloc( sizeof( TW_PALETTE8 ) +
										( 256 * sizeof( TW_ELEMENT8 )));

			if( lpTwainPalette == ( pTW_PALETTE8 )NULL )
				return( FALSE );

			if( !( *lpDSM_Entry )( &appID, &dsID, DG_IMAGE, DAT_PALETTE8, 
                MSG_GET,( TW_MEMREF )lpTwainPalette ) == TWRC_SUCCESS )
            {
			
				twainError( IDS_UNSUPPORTEDPIXTYPE );
				return( FALSE );
			}

			if( lpTwainPalette->PaletteType != TWPA_RGB ) 
            {
				twainError( IDS_UNSUPPORTEDPIXTYPE );
				return( FALSE );
			}

			Type = FDT_PALETTECOLOR;
			save_type = IDC_SAVE8BITCOLOR;
		    break;

		default : 
			twainError( IDS_INVALIDPIXTYPE );
			return( FALSE );
		    break;
	}

	// Open the new frame.          
	if( !( lpFrame = FrameOpen( 
			Type,
			( WORD )imageWidth,
			( WORD )dcImageInfo.ImageLength,
			( WORD )dcImageInfo.XResolution.Whole ))) 
    {
		// Issue the error message 
		Message( IDS_ESCROPEN,( LPTR )Control.RamDisk );
		return( FALSE );
	}

	if( Type == FDT_PALETTECOLOR )
	{
		int i;
		LPCOLORMAP lpColorMap = FrameGetColorMap( lpFrame );

		int NumColors = lpTwainPalette->NumColors;
		if( NumColors > 256 )
			NumColors = 256;

		for( i = 0; i < NumColors; ++i )
		{
			lpColorMap->RGBData[i].red = lpTwainPalette->Colors[i].Channel1;			
			lpColorMap->RGBData[i].green = lpTwainPalette->Colors[i].Channel2;			
			lpColorMap->RGBData[i].blue = lpTwainPalette->Colors[i].Channel3;			

            if( fInvert )
            {
			    lpColorMap->RGBData[i].red   ^= 0xFF;
			    lpColorMap->RGBData[i].green ^= 0xFF;
			    lpColorMap->RGBData[i].blue  ^= 0xFF;
            }
		}
        lpColorMap->NumEntries = NumColors;
	}

	if( dcImageInfo.Planar ) 
        ImagePlane = 0;

	while( dcRC != TWRC_XFERDONE ) 
    {
		dcRC = ( *lpDSM_Entry )( &appID, &dsID,
				DG_IMAGE, DAT_IMAGEMEMXFER, MSG_GET,( TW_MEMREF )&dcImageData );

		switch( dcRC ) 
        {
			case TWRC_SUCCESS:
			case TWRC_XFERDONE: 
				if( dcImageData.YOffset == 0 ) 
                    ImagePlane++;

				StoreImageRect( lpFrame, dcImageInfo, dcImageData, Type, expand );
			    break;

			case TWRC_CANCEL:
			case TWRC_FAILURE:

			default: 
				// something wrong, abort the transfer and delete the image
				if( dcRC == TWRC_FAILURE ) 
                {
					twainError( IDS_TWAINFAILURE );
				}

				// Close the garbage frame 
				FrameClose( lpFrame );

				return( FALSE );
			    break;
		}
	}

	// Bring up the new image window.
	SendMessage( hWnd, PM_XFERDONE, 
               ( unsigned short )save_type,( unsigned long )lpFrame );

	return( TRUE );
}
Esempio n. 7
0
void EXPORT grabber_frame_close( LPFRAME lpFrame )
/************************************************************************/
{
FrameClose(lpFrame);
}
Esempio n. 8
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. 9
0
BOOL ConvertImage(LPIMAGE lpImage, LPCONVERT_PARMS lpParms)
/***********************************************************************/
{
BOOL fRet = FALSE;
LPFRAME lpDstFrame, lpBaseFrame;
LPOBJECT lpBase, lpObject;
BOOL fError, fOptimize, fProgressSet;
INTERNAL_DATA data;
int	inDepth, iMaxWidth, nColors, i;
LPCOLORMAP lpColorMap;
LPRGB lpRGB;
FRMTYPEINFO InTypeInfo, OutTypeInfo;
CFrameTypeConvert TypeConvert;
DITHER_TYPE DitherType = DT_DEFAULT;

if (ImgInMaskEditMode(lpImage))
	return(TRUE);

lpColorMap = NULL;

lpBase = ImgGetBase(lpImage);
lpBaseFrame = ObjGetEditFrame(lpBase);
inDepth = FrameDepth(lpBaseFrame);

OutTypeInfo = lpParms->cmsInfo.dst;
FrameGetTypeInfo(lpBaseFrame, &InTypeInfo);

// are we try to convert to a color managed image?
if (Control.CMSEnabled && IsDstPTSelected(&OutTypeInfo.ptInfo))
	{
	// see if our image already has a color managed source
	if (!IsSrcPTSelected(&InTypeInfo.ptInfo))
		{
		// nope, see if the source passed in is valid for this image
		if (IsSrcPTSelected(&lpParms->cmsInfo.src.ptInfo) &&
			(lpParms->cmsInfo.src.DataType == InTypeInfo.DataType))
			{	
			InTypeInfo = lpParms->cmsInfo.src;
			}
		// go get a source from the user
		else
			{
			CMSINFO CmsInfo2;
			if( CmsGetSrcPTType( &InTypeInfo, &CmsInfo2) )
				InTypeInfo = CmsInfo2.src;
			}
		}
	}
else
 	FrameSetTypeInfo(&InTypeInfo, InTypeInfo.DataType, InTypeInfo.ColorMap);

// no conversion necessary
if (FrameTypeInfoEqual(InTypeInfo, OutTypeInfo))
	return(TRUE);

DitherType = lpParms->DitherType;
fOptimize = lpParms->ConvertType == CT_OPTIMIZED;
fProgressSet = FALSE;


if ( OutTypeInfo.DataType == FDT_PALETTECOLOR/* && inDepth >= 3 */)
	{
	if (lpParms->ConvertType == CT_CUSTOM)
		{
		FNAME szFileName;

		if ( !LookupExtFileN( lpParms->szPalette, szFileName, IDN_PALETTE, NO ) )
			return(FALSE);
		if (!(lpColorMap = Palette_ReadColorMap(szFileName)))
			return(FALSE);
		}
	else
		{
		// allocate a map to carry around with image
		lpColorMap = FrameCreateColorMap();
		if (!lpColorMap)
			{
			Message(IDS_EMEMALLOC);
			goto MemError;
			}

		lpColorMap->NumEntries = lpParms->iLevels;

		if (InTypeInfo.DataType == FDT_GRAYSCALE && lpColorMap->NumEntries == 256 &&
			fOptimize)
			{
			DitherType = DT_NONE;
			lpRGB = lpColorMap->RGBData;
			for (i = 0; i < lpColorMap->NumEntries; ++i)
				{
				lpRGB->red = lpRGB->green = lpRGB->blue = i;
				++lpRGB;
				}
			}
		else
			{
			// 1. CreateOptimizedPalette phase - only if fOptimize
			// 2. Mapping phase
			ProgressBegin(fOptimize ? 2 : 1,
					lpParms->Common.idDirty-IDS_UNDOFIRST+IDS_PROGFIRST);
			fProgressSet = TRUE;
			if (fOptimize)
				ProgressBegin(1, 0);
			if (!CreateOptimizedPalette(lpBase, ObjGetEditFrame(lpBase),
									lpColorMap->RGBData, &lpColorMap->NumEntries,
									fOptimize,
									fOptimize ? AstralClockCursor : NULL))
				{
				if (fOptimize)
					ProgressEnd();
				Message(IDS_EMEMALLOC);
				goto ExitFalse;
				}
			if (fOptimize)
				ProgressEnd();
			}
		}
	if (lpColorMap->NumEntries <= 16)
		lpColorMap->NumEntries = 16;
	else
		lpColorMap->NumEntries = 256;
	FrameSetTypeInfo(&OutTypeInfo, FDT_PALETTECOLOR, lpColorMap);
	}

if (!fProgressSet)
	ProgressBegin(1, lpParms->Common.idDirty-IDS_UNDOFIRST+IDS_PROGFIRST);
fProgressSet = TRUE;
	
iMaxWidth = 0;
lpObject = NULL;
while (lpObject = ImgGetNextObject(lpImage, lpObject, YES, NO))
	{
	if (RectWidth(&lpObject->rObject) > iMaxWidth)
		iMaxWidth = RectWidth(&lpObject->rObject);
	}
if (!TypeConvert.Init(InTypeInfo, OutTypeInfo, iMaxWidth, DitherType))
	{
	Message(IDS_EMEMALLOC);
	goto ExitFalse;
	}

if (ImgMultipleObjects(lpImage))
	{
	ProgressBegin(ImgCountObjects(lpImage), 0);
	
	if ( !ImgEditInit(lpImage, ET_ALLOBJECTS, UT_NEWDATA|UT_COLORMAP, lpBase) )
		goto ExitFalse;

	fError = NO;
	lpObject = NULL;
	while (lpObject = ImgGetNextObject(lpImage, lpObject, YES, NO))
		{
		lpDstFrame = ConvertFrame(ObjGetEditFrame(lpObject), OutTypeInfo, &TypeConvert);
		if (!lpDstFrame)
			{
			fError = YES;
			break;
			}
 		ImgEditedObjectFrame( lpImage, lpObject, lpParms->Common.idDirty, NULL,
						lpDstFrame, NULL);
		}

	if (fError)
		{
		lpObject = NULL;
		while (lpObject = ImgGetNextObject(lpImage, lpObject, YES, NO))
			{
			if (lpObject->Pixmap.UndoFrame)
				{
		 		lpDstFrame = lpObject->Pixmap.EditFrame;
		 		lpObject->Pixmap.EditFrame = lpObject->Pixmap.UndoFrame;
		 		lpObject->Pixmap.UndoFrame = NULL;
		 		FrameClose(lpDstFrame);
		 		}
			}
		}
	ProgressEnd();
	}
else
	{
	if ( !ImgEditInit(lpImage, ET_OBJECT, UT_NEWDATA|UT_COLORMAP, lpBase) )
		goto ExitFalse;

	ProgressBegin(1, 0);
	lpDstFrame = ConvertFrame(lpBaseFrame, OutTypeInfo, &TypeConvert);
	ProgressEnd();

	if (!lpDstFrame)
		goto ExitFalse;
	/* Setup the new image and bring up the new image window */
	ImgEditedObjectFrame( lpImage, lpBase, lpParms->Common.idDirty, NULL,
						lpDstFrame, NULL);
	}

switch (lpParms->cmsInfo.dst.DataType)
	{
	case FDT_LINEART:
		lpImage->DataType = IDC_SAVELA;
		break;
	case FDT_GRAYSCALE:
		lpImage->DataType = IDC_SAVECT;
		break;
	case FDT_PALETTECOLOR:
		lpImage->DataType = IDC_SAVE8BITCOLOR;
		break;
	case FDT_RGBCOLOR:
		lpImage->DataType = IDC_SAVE24BITCOLOR;
		break;
	case FDT_CMYKCOLOR:
		lpImage->DataType = IDC_SAVE32BITCOLOR;
		break;
	}
ImgColorMapChanged(lpImage);
lpParms->Common.UpdateType = UT_DATATYPE;

fRet = TRUE;

ExitFalse:
if (fProgressSet)
	ProgressEnd();
MemError:
if (lpColorMap)
	FrameDestroyColorMap(lpColorMap);
return(fRet);
}
Esempio n. 10
0
void COlelistBox::OnLButtonDown(UINT nFlags, CPoint point)
{
	FNAME       *lpResult;
    CDataItem   *pDataItem;
    LPIMAGE      lpImage = GetActiveImage();
	CServerDoc  *pDoc = PictPubApp.GetDocument(lpImage);
	int          num;
    CRect        r,rr;
    BOOL         bCreateDoc = (pDoc == NULL);
    CPoint       p;

	CListBox::OnLButtonDown(nFlags, point);
    FORWARD_WM_LBUTTONUP(GetSafeHwnd(), point.x, point.y, nFlags, ::SendMessage);

	lpResult = ExtBsr_GetSelection(GetParent()->GetSafeHwnd(), &num);

    if (!lpResult || num != 1)
    	return;
	lstrcpy(Names.Clipboard, lpResult[0]);
	if (LookupExtFileN(Names.Clipboard, Names.PasteImageFile, 
		IDN_CLIPBOARD, NO))
	{
		if (bCreateDoc)
		{
			LPFRAME lpFrame = FrameOpen(FDT_GRAYSCALE, 1, 1, 72);
			if (lpFrame)
			{
	            POSITION    Pos;
				lpImage = CreateImage(NULL,lpFrame,NULL,NULL,
						IDN_PP,IDC_SAVECT,IMG_DOCUMENT,NULL);
				if (!lpImage)
				{
					FrameClose(lpFrame);
					return;
				}
				pDoc = (CServerDoc*)PictPubApp.OpenDocumentFile(
					lpImage->CurFile, lpImage, FALSE);
				if (!pDoc)
				{
					DestroyImage(lpImage);
					return;
				}
		 	}
			else
				return;
		}

		if (pDoc)
		{
		    pDataItem = new CDataItem(pDoc, Names.Clipboard, YES);
		    GetParent()->GetWindowRect(&r);
		    ClientToScreen(&point);
		    GetItemRect(GetCurSel(), &rr);
		    ClientToScreen(&rr);
		    p.x = rr.Width() / 2;
		    p.y = rr.Height() / 2;
		
		    // NOTE!!the pDataItem will be internally destroyed once the drag/drop 
		    // operation is completed therefore we do not need to delete the pDataItem
		    pDataItem->DoDragDrop(&rr, p, FALSE, DROPEFFECT_COPY, &r);
		
		    if (bCreateDoc)
				pDoc->OnCloseDocument();
		}
    }
    else if(Names.Clipboard[0])
    {
  	  	// deleted the file...notify the browser
  		UpdatePasteFromFile(NULL);
	} 
}
Esempio n. 11
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. 12
0
BOOL CReadBitmap::GIFRead()
/************************************************************************/
{
    GIFHDR		   hdr;
    GIFDESC		   ImDesc;
    GIFMAP		   GlobalMap;
    GIFMAP		   LocalMap;
    BYTE		      cTemp;
    LPTR		      lpFileLine, lpLineBuffer, lpOut;
    LPFRAME		   lpFrame;
    FILEBUF		   ifd;		/* file descriptor (buffered) */
    BOOL		      graymap;
    int			   i;
    int			   sy;
    int			   xres;		/* pixels per inch */
    int			   npix;		/* image width (pixels) */
    int			   nlin;		/* image height (pixels) */
    BYTE		      codeSize;
    int			   iCodeSize;
    int			   iRowMapIndex;
    BOOL		      compressInit;
    LPLZW_STUFF   lpLZW;
	FRMTYPEINFO inType, outType;
	LPCOLORMAP lpColorMap;
	CFrameTypeConvert TypeConvert;
	CFile 	theFile;
	CFile*	pTheFile;
	BOOL	fRet = FALSE;

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

	TRY
	{
    	lpFileLine = NULL;
    	lpFrame = NULL;
    	lpLineBuffer = NULL;
    	compressInit = NO;
		lpColorMap = NULL;

    	if (!(lpLineBuffer = Alloc (BUF_SIZE)))
	      	goto Exit;

    	FileFDOpenRdr (&ifd, pTheFile, lpLineBuffer, BUF_SIZE);

		/* initialize the Global and local color maps */
    	gifInitColorMap (&GlobalMap);
    	gifInitColorMap (&LocalMap);

		/* read gif file header */
    	if (gifReadHeader (&ifd, &hdr))
		goto BadRead;

		/* get global color map, if any */
    	if (hdr.GlobalMap) {
		if (gifReadColorMap (&ifd, hdr.bpp, &GlobalMap))
	    	goto BadRead;
    	}
		
		/* look for start of image */
    	while (1) {
		FileFDRead (&ifd, (LPTR) &cTemp, 1);
		if (ifd.err)
	    	goto BadRead;

    	/* test for image separator character */
		if (cTemp == GIFImSep)
	    	break;

    	/* test for terminator character (no image blocks in file?) */
		if (cTemp == GIFImSep)
	    	goto BadRead;

    	/* test for extension block character */
		if (cTemp == GIFExtBlk) {

		/* Skip over the extension block */

		/* read function code */
	    	FileFDRead (&ifd, (LPTR) &cTemp, 1);

	    	do {
	    	/* read byte count */
			FileFDRead (&ifd, (LPTR) &cTemp, 1);

	    	/* skip data bytes */
			if (cTemp)
		    	FileFDSeek (&ifd, (long) cTemp, 1);
	    	} while (cTemp);
		}
    	}

	/* now at the start of the first image */
    	if (gifReadImDesc (&ifd, &ImDesc))
		goto BadRead;

	/* read local color map, if any */
    	if (ImDesc.LocalMap) {
		if (gifReadColorMap (&ifd, ImDesc.bpp, &LocalMap))
	    	goto BadRead;
    	}
    	else {
		LocalMap = GlobalMap;
		ImDesc.bpp = hdr.bpp;
    	}

	/* check for gray map */
    	graymap = TRUE;
    	for (i = 0; (i < LocalMap.Length) && graymap; i++)
		graymap = (LocalMap.Map[i].red == LocalMap.Map[i].green)
		    	&& (LocalMap.Map[i].red == LocalMap.Map[i].blue);

		lpColorMap = FrameCreateColorMap();
		if (!lpColorMap)
		{
			SetError(BEC_errMemory);
			goto Exit;
		}
		lpColorMap->NumEntries = LocalMap.Length;
		for (i = 0; i < LocalMap.Length; ++i)
			lpColorMap->RGBData[i] = LocalMap.Map[i];


	/* get width of image in pixels */
    	npix = ImDesc.ImWidth;
    	nlin = ImDesc.ImHeight;
    	xres = 75;

		if (hdr.bpp == 1)
			FrameSetTypeInfo(&inType, FDT_LINEART);
		else
			FrameSetTypeInfo(&inType, FDT_PALETTECOLOR, lpColorMap);

		if (!SetupTypes(&inType, &outType, graymap))
			goto Exit;

		FrameSetTypeInfo(&inType, FDT_PALETTECOLOR, lpColorMap);

		if (!TypeConvert.Init(inType, outType, npix, m_DitherType))
		{			   
			SetError(BEC_errMemory);
			goto Exit;	
		}

	/* allocate space for one line of the image (file) */
    	if ( !AllocLines (&lpFileLine, 1, npix, 1)) {
		SetError(BEC_errMemory);
		goto BadWrite;
    	}

	/* Create the image frame store */
    	lpFrame = FrameOpen(outType, npix, nlin, xres);
    	if ( !lpFrame ) {
		SetError(BEC_errFrameOpen);
		goto Exit;
    	}

	/* convert the image */
    	if (FileFDRead (&ifd, &codeSize, 1) == -1)
		goto BadRead;

    	iCodeSize = codeSize;

    	if (FileFDSeek (&ifd, 0L, 1) == -1)
		goto BadRead;

    	if ( !( lpLZW = DecompressLZW_GIF (ifd.pFile, NULL, 0, iCodeSize, NULL)))
		goto BadRead;
    	compressInit = YES;
    	if (ImDesc.Interlaced)
		iRowMapIndex = 1;
    	else
		iRowMapIndex = 0;

		sy = gifRowMap [iRowMapIndex].first;
		for (i = 0; i < nlin; i++)
		{
			if (Progress (i, nlin, YES))
				goto Exit;
			if (!(DecompressLZW_GIF (ifd.pFile, lpFileLine, npix, iCodeSize, lpLZW)))
				goto BadRead;
			if ( !(lpOut = FramePointerRaw(lpFrame, 0, sy, YES)) )
				goto BadWrite;
			TypeConvert.ConvertData(lpFileLine, lpOut, sy, npix);
			sy += gifRowMap [iRowMapIndex].step;
			if (sy >= ImDesc.ImHeight)
			{
	    		iRowMapIndex++;
		    	sy = gifRowMap [iRowMapIndex].first;
			}
		}

		m_iWidth = npix;
		m_iHeight = nlin;
		m_iRes = xres;
		m_lpFrame = lpFrame;
		fRet = TRUE;
		goto Exit;
	}
	CATCH_ALL(e)
	{
		goto BadRead;
	}
	END_CATCH_ALL

	ProgressEnd();
	return (TRUE);

BadRead:
	SetError(BEC_errFileRead);
    goto Exit;

BadWrite:
	SetError(BEC_errFrameRead);

Exit:
    if (compressInit)
 	   DecompressLZW_GIF (ifd.pFile, NULL, 0, iCodeSize, lpLZW);
    compressInit = NO;
    if ( lpFileLine )
	FreeUp( lpFileLine );
    if ( lpLineBuffer )
	FreeUp (lpLineBuffer);
	if ( lpColorMap )
		FrameDestroyColorMap(lpColorMap);
	CloseFile(pTheFile);

	if (!fRet && lpFrame)
		FrameClose(lpFrame);

	ProgressEnd();
    return(fRet);
}
Esempio n. 13
0
BOOL CReadBitmap::CTRead()
   {
   LPCTHEADER  lpTH;
   LPFRAME     lpFrame;
   BOOL        fConvert = FALSE, fRet = FALSE;
   CFile 	   theFile;
   CFile*	   pTheFile;
   FRMTYPEINFO inType, outType;
   LPTR        lpIn, lpIn2,lpOut, lpFrmLine;
   int         x,y,j;
   UINT        bytes_read;
   BOOL        GrayScale;
   BITMAP_ERROR_CODE err;
    CFrameTypeConvert	Convert;

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

   lpFrame = NULL;
   if ( !(lpTH = ReadCTHeader(pTheFile, m_lpFileName, &err)))
   {
   		SetError(err);
	   goto Exit;
	}

   GrayScale = lpTH->ColSepMask == 8 && lpTH->NumColSep == 1;
	if (GrayScale)
		FrameSetTypeInfo(&inType, FDT_GRAYSCALE, NULL);
    else 
		FrameSetTypeInfo(&inType, FDT_CMYKCOLOR, NULL);

	if (!SetupTypes(&inType, &outType))
		goto Exit;

	fConvert = !FrameTypeInfoEqual( inType, outType );

	if( fConvert )
		{
		if( !Convert.Init( inType, outType, lpTH->Pixels ) )
			{
			SetError(BEC_errMemory);
			goto Exit;
			}
		}
   /* Create the image frame store */
   if ( !(lpFrame = FrameOpen(outType, lpTH->Pixels, lpTH->Lines, lpTH->Resolution)))
	   {
	   SetError(BEC_errFrameOpen);
      goto Exit;
      }

  	pTheFile->Seek (2048, CFile::begin);
	for (y=0; y < lpTH->Lines; y++)
		{
		if ( Progress(y, lpTH->Lines, YES))
			goto Exit;

      TRY
	      {
		   bytes_read = pTheFile->Read(lpTH->lpCTLine, lpTH->LineSize);
         }
      CATCH_ALL(e)
	      {
			goto BadRead;
	      }
      END_CATCH_ALL
		if (bytes_read != lpTH->LineSize)
			goto BadRead;

		if ( !(lpFrmLine = FramePointerRaw( lpFrame, 0, y, YES)))
			goto BadWrite;
		lpIn  = lpTH->lpCTLine;
      lpOut = lpFrmLine;

      lpIn2 = lpIn;
      for (x=0; x < lpTH->Pixels; x++)
			{
         j = 0;
         if (!GrayScale)
            {
            if (lpTH->ColSepMask & 0x1)  // cyan
               {
               j  += lpTH->ChannelSize;
               *lpOut++ = 255 - *lpIn2;
               }
            else
               *lpOut++ = 0;
            if (lpTH->ColSepMask & 0x2)  // magenta
               {
               *lpOut++ = 255 - *(lpIn2 + j);
               j  += lpTH->ChannelSize;
               }
            else
               *lpOut++ = 0;
            if (lpTH->ColSepMask & 0x4)  // yellow
               {
               *lpOut++ = 255 - *(lpIn2 + j);
               j  += lpTH->ChannelSize;
               }
            else
               *lpOut++ = 0;
            }
         if (lpTH->ColSepMask & 0x8)  // black
            *lpOut++ = 255 - *(lpIn2 + j);
         else
            *lpOut++ = 0;
         lpIn2++;
			}
		if( fConvert )
			Convert.ConvertData( lpFrmLine, lpFrmLine, y, lpTH->Pixels );
		}
   m_iWidth       = lpTH->Pixels;
   m_iHeight      = lpTH->Lines;
   m_iRes         = (int)lpTH->Resolution;
   m_lpFrame      = lpFrame;

   fRet = TRUE;
   goto Exit;

BadRead:
	SetError(BEC_errFileRead);
goto Exit;

BadWrite:
	SetError(BEC_errFrameRead);

Exit:
   FreeCTHeader(lpTH);
   CloseFile(pTheFile);
   if (!fRet && lpFrame)
	   FrameClose(lpFrame);

   ProgressEnd();
   return( fRet );
   }