Esempio n. 1
0
void InitSpin( HWND hDlg, LFIXED fSetX, LFIXED fSetY, int flag)
/************************************************************************/
{
LPIMAGE	lpImage;
LPFRAME	lpFrame;
LFIXED	fMin, fMax;
RECT		iRect;
int 		res;

if( !( lpImage = GetActiveImage() ) )
	return;
lpFrame = ImgGetBaseEditFrame( lpImage );

ImgGetImageRect( lpImage, &iRect );

res = FrameResolution( lpFrame );

if (flag & 1)
   {
   fMax = FGET( iRect.right, res );
   fMin = FGET( -iRect.right, res );
   InitDlgItemSpinFixed( hDlg, IDC_POS_X, fSetX, YES, fMin, fMax );
   }

if (flag & 2)
   {
   fMax = FGET( iRect.bottom, res );
   fMin = FGET( -iRect.bottom, res );
   InitDlgItemSpinFixed( hDlg, IDC_POS_Y, fSetY, YES, fMin, fMax );
   }
SetUnitLabels(hDlg);
}
Esempio n. 2
0
BOOL CExpandImageDlg::PreDoModal (LPVOID lpVoid)
{
	LPIMAGE lpImage = NULL;
	LPFRAME lpFrame;
	
	if(lpImage = GetImage())
	{	
		lpFrame = ImgGetBaseEditFrame(lpImage);
		m_Units = m_SaveUnits = Control.Units; 
		m_Crop.top = m_Crop.left = 0;  
		m_Crop.right = lpImage->npix - 1; 
		m_Crop.bottom = lpImage->nlin - 1; 
		m_Resolution = m_CropResolution = m_OrigResolution = FrameResolution(lpFrame);
		m_Depth = FrameDepth(lpFrame);
	 
	}
	else
	{
		m_Resolution = m_CropResolution = 75;
		m_Depth = 1;
	
	}
	
	m_Width = m_OrigWidth = FGET(m_Crop.right - m_Crop.left + 1, m_CropResolution);
	m_Height = m_OrigHeight = FGET(m_Crop.bottom - m_Crop.top + 1, m_CropResolution);
	m_Left = m_Top = 0;
	m_FillColor.gray = 255;


	return CPPViewModalDlg::PreDoModal();

}
Esempio n. 3
0
LOCAL BOOL Pos_OnInitDialog(HWND hDlg, HWND hWndFocus, LPARAM lParam)
/************************************************************************/
{
RECT     rSel;
LPIMAGE  lpImage;
LPFRAME	lpFrame;
LFIXED   XPos, YPos;
int 		res;

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

lpFrame = ImgGetBaseEditFrame( lpImage );
res = FrameResolution( lpFrame );
ImgGetSelObjectRect(lpImage, &rSel, YES);
XPos = FGET(rSel.left, res); 
YPos = FGET(rSel.top, res); 

CheckComboItem( hDlg, IDC_PREF_UNITS, IDC_PREF_UNITINCHES,
	IDC_PREF_UNITPIXELS,	IDC_PREF_UNITINCHES );

lpPosParms = (LPPOSOBJECTS_PARMS)lParam;

Edit.SaveUnits = Control.Units;

SetUnitResolution( 0 );

InitSpin( hDlg, XPos, YPos,3);

CenterPopup( hDlg );
return(TRUE);
}
Esempio n. 4
0
void View1TO1()
   {
   int x, y, res, ratio;
   LFIXED fixed;
   HDC hDC;
   HWND hWnd;
   LPDISPLAY lpDisplay;
   LPIMAGE lpImage;

	if (hWnd = GetActiveDoc())
      {
	   lpImage = GetImagePtr(hWnd);
	   lpDisplay = GetDisplayPtr(hWnd);
	   hDC = GetDC( PictPubApp.Get_hWndAstral() );
	   x = GetDeviceCaps( hDC, HORZRES ); // in pixels
	   ReleaseDC( PictPubApp.Get_hWndAstral(), hDC );
	   fixed = FGET( FUNITY, Control.ScreenWidth );
	   if (res = FMUL( x, fixed)) // in pixels/inch
         {
	      ratio = ( 100L * res ) / FrameResolution(ImgGetBaseEditFrame(lpImage));
	      x = ( lpDisplay->FileRect.left 
		   + lpDisplay->FileRect.right ) / 2;
	      y = ( lpDisplay->FileRect.top 
		   + lpDisplay->FileRect.bottom ) / 2;
	      Zoom( hWnd, x, y, ratio, NO, View.ZoomWindow );
         }
      }
   }
Esempio n. 5
0
void StatusOfRectangle(
/***********************************************************************/
LPRECT lpRect,
LFIXED fScale)
{
STRING szUnit, szString1, szString2, szString3, szString4;
LPSTR lpUnit;
RECT rFile;
int Resolution;

OrderRect( lpRect, &rFile );
if ( fScale )
	{
	Resolution = 1000;
	ScaleRect( &rFile, fScale );
	}
else
if (lpImage)
	Resolution = FrameResolution( ImgGetBaseEditFrame(lpImage) );
if ( AstralStr( Control.Units-IDC_PREF_UNITINCHES+IDS_INCHES, &lpUnit ) )
	{
	lstrcpy( szUnit, lpUnit );
	MessageStatus( IDS_RECT_STATUS,
		Unit2String( FGET( RectWidth(&rFile), Resolution ), szString1 ),
		Unit2String( FGET( RectHeight(&rFile), Resolution ), szString2),
		(LPSTR)szUnit,
		Unit2String( FGET( rFile.left, Resolution ), szString3 ),
		Unit2String( FGET( rFile.top, Resolution ), szString4 ) );
	}
}
Esempio n. 6
0
VOID CSizeImageDlg::DoSizeInits( )
{
    HWND hDlg = GetSafeHwnd();
    LPFRAME lpFrame;
    LPIMAGE lpImage = GetImage();
    FRMDATATYPE Type = FDT_RGBCOLOR;

    ImgGetInfo(lpImage, NULL, NULL, NULL, &Type);

    /* Be careful to set all values before doing a SetDlg... with them */
    /* The Edit structure is a temorary holding area for sizing dialog boxes */
    m_Distortable = NO;
    m_MaintainSize = NO;
    m_ScaleX = m_ScaleY = 100;
    if ( lpImage )
    {
	    lpFrame = ImgGetBaseEditFrame(lpImage);
	    m_Crop.left  = m_Crop.top = 0;
	    m_Crop.right = lpImage->npix - 1;
	    m_Crop.bottom = lpImage->nlin - 1;
	    m_Resolution = m_CropResolution = m_OrigResolution =
  				          FrameResolution(lpFrame);
	    m_Depth = FrameDepth(lpFrame);
    }
    else
    {
	    m_Resolution = m_CropResolution = 75;
	    m_Depth = 1;
    }
    m_Angle = 0;
    m_Width  = FGET( CROPWIDTH(), m_CropResolution );
    m_Height = FGET( CROPHEIGHT(), m_CropResolution );

    CheckDlgButton( IDC_DISTORT, m_Distortable);
    CheckDlgButton( IDC_SMARTSIZE, m_SmartSize );
    CheckDlgButton( IDC_MAINTAINSIZE, m_MaintainSize );
 
    ControlEnable(hDlg, IDC_DISTORT, !m_MaintainSize);
    ControlEnable(hDlg, IDC_MAINTAINSIZE, !m_Distortable );
    ControlEnable( hDlg, IDC_SMARTSIZE, !m_MaintainSize && 
        !m_Distortable && CANDOTRANSPARENCY(Type));

    InitDlgItemSpinFixed( hDlg, IDC_HEIGHT, m_Height, YES, 0L, FGET(9999,1) );
    InitDlgItemSpinFixed( hDlg, IDC_WIDTH, m_Width, YES, 0L, FGET(9999,1) );
    InitDlgItemSpin( hDlg, IDC_SCALEX, m_ScaleX, YES, 1, 10000 );
    InitDlgItemSpin( hDlg, IDC_SCALEY, m_ScaleY, YES, 1, 10000 );
    InitDlgItemSpin( hDlg, IDC_RES, m_Resolution, NO, 1, 10000 );

    ImageMemory( hDlg, IDC_MEMORY, m_Width, m_Height, m_Resolution,
	    m_Depth );

    CheckComboItem(hDlg, IDC_PREF_UNITS, IDC_PREF_UNITFIRST,
	                     IDC_PREF_UNITLAST, m_Units);

    SetUnitLabels();
}
Esempio n. 7
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. 8
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. 9
0
void FloodProc( HWND hWindow, UINT msg, int x, int y, UINT32 Option )
/************************************************************************/
{
FRMDATATYPE type;
int res;
FLOOD_PARMS parms;
LPIMAGE lpImage;
RECT rArea;

switch (msg)
    {
    case WM_CREATE:	// The first mouse down message
	if (!IsOnImage(hWindow, x, y))
		break;
	Display2File(hWindow,&x, &y);
	lpImage = (LPIMAGE)GetImagePtr(hWindow);
	type = FrameType(ImgGetBaseEditFrame(lpImage));
	res = FrameResolution(ImgGetBaseEditFrame(lpImage));
	parms.FloodOpacity = Fill.FloodOpacity;
	parms.FloodMergeMode = Fill.FloodMergeMode;
	GetActiveColorFromType(type, &parms.Color);
	parms.iBaseRes = res;
	parms.x = x;
	parms.y = y;
	rArea.left = rArea.right = x;
	rArea.top = rArea.bottom = y;
	Measure(lpImage, &rArea, &parms.InColor);
	parms.FloodRange = Fill.FloodRange;
	parms.FloodFade = Fill.FloodFade;
	parms.idFloodColorModel = Fill.idFillColorModel;
	ProcessCommand(lpImage->lpCmdList, IDS_CMD_FLOOD, &parms);
	break;

    case WM_LBUTTONDOWN:
	break;

    case WM_LBUTTONUP:
	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. 10
0
int CSizeImageDlg::SetUnitResolution( int res )
{
	int OldUnitRes;
	LPIMAGE lpImage = GetImage();

	OldUnitRes = m_UnitRes;

	if ( !(m_UnitRes = res) )
	{
		m_UnitRes =
			( lpImage ? FrameResolution(ImgGetBaseEditFrame(lpImage)) : 1000 );
	}
	// setup control library
	SetUnitInfo((UNIT_TYPE)(m_Units-IDC_PREF_UNITINCHES), m_UnitRes, m_Points);

	return( OldUnitRes );
}
Esempio n. 11
0
void CImage::AddNewObject(LPOBJECT lpObject, BOOL fSetObjRes)
{
LPOBJECT lpBase = GetBase();
lpObject->dwObjectID = ++dwObjectID;
ObjAddTail( &ObjList, (LPPRIMOBJECT)lpObject ); // Add to the image's list
ObjDeselectAll(&ObjList); // Deselect anything currently selected
ObjSelectObject( (LPPRIMOBJECT)lpObject, YES ); // Select the new object
if (lpBase)
	{
	if(fSetObjRes)
		{
		int res = FrameResolution(ObjGetEditFrame(lpBase));
		FrameSetResolution(ObjGetEditFrame(lpObject), res);
		if (lpObject->lpAlpha)
			FrameSetResolution(AlphaGetEditFrame(lpObject->lpAlpha), res);
		}
	}
}
Esempio n. 12
0
//  Gets the current mask if any.
//  If no mask exists then create one using fOn and fNoUndo.
//  bCreated is TRUE if a new mask was created. 
LPMASK CImage::GetMaskEx(BOOL fOn, BOOL fNoUndo, LPINT bCreated, LPRECT lpUpdateRect)
{
    LPMASK lpMask;
    LPFRAME lpFrame;
    FRMTYPEINFO TypeInfo;
    FRMDATATYPE FrameType = FDT_GRAYSCALE;

    AstralSetRectEmpty(lpUpdateRect);
    if (lpMask = GetMask())
    {
        if (bCreated)
            *bCreated = FALSE;
        return(lpMask);
    }
    lpFrame = GetBaseEditFrame();
    FrameGetTypeInfo(lpFrame, &TypeInfo);
    if (TypeInfo.DataType == FDT_LINEART && Mask.OneBitMask)
       FrameType = FDT_LINEART;
    if (!(lpMask = MaskCreate(NULL, FrameXSize(lpFrame),
                                FrameYSize(lpFrame),
                                fOn, 
                                fNoUndo, FrameType)))
    {
        Message( IDS_EMEMALLOC );
        return(NULL);
    }
	// sync up the resolution of the image data and the mask
	// don't ever rely on the mask's resolution being correct
	// cause other size can change the image data resolution
	// without changing the mask's resolution.  Also, there are
	// other places the mask gets created without syncing up
	// the resolution.  I am doing it here so we can begin
	// to track it correctly (Ted)
	FrameSetResolution(AlphaGetEditFrame(lpMask), FrameResolution(lpFrame));
    if (bCreated)
        *bCreated = TRUE;
    if (!Control.UseMaskAndObjects)
        GetObjectMarqueeRect(this, lpUpdateRect);
    SetMask(lpMask);
    return(lpMask);
}
Esempio n. 13
0
LPOBJECT CImage::AddFrameObject(LPFRAME lpFrame, LPMASK lpAlpha, LPRECT lpRect)
{
LPOBJECT lpObject, lpBase;
RECT    rObject;

lpBase = GetBase();
if (lpRect)
    rObject = *lpRect;
else
    SetRect(&rObject, 0, 0, FrameXSize(lpFrame)-1, FrameYSize(lpFrame)-1);
lpObject = ObjCreateFromFrame(ST_PERMANENT, lpFrame, lpAlpha,
                            &rObject, Control.NoUndo);
if (lpObject)
    ObjAddTail(&ObjList, (LPPRIMOBJECT)lpObject);
if (lpBase)
	{
	int res = FrameResolution(ObjGetEditFrame(lpBase));
	FrameSetResolution(ObjGetEditFrame(lpObject), res);
	if (lpObject->lpAlpha)
		FrameSetResolution(AlphaGetEditFrame(lpObject->lpAlpha), res);
	}
return(lpObject);
}
Esempio n. 14
0
void CImage::ObjEditUndo(LPOBJECT lpObject, BOOL fUndoData, BOOL fUndoAlpha)
{
RECT rTemp;
BOOL fSelected, Resolution, fDeleted, fBase, bLocked;
LPALPHA lpAlpha, lpTemp;
LPOBJECT lpNext;
int XSize, YSize;
int tempDataType;
LPCOLORMAP lpColorMap;
int        GroupID;

lpAlpha = lpObject->lpAlpha;
fBase = lpObject == GetBase();
if (fUndoData && lpObject->DataDirty)
	{
	if (lpObject->DataUndoType & UT_RESOLUTION)
		Resolution = FrameResolution(lpObject->Pixmap.EditFrame);
	if (lpObject->DataUndoType & UT_COLORMAP)
		{
		if (lpColorMap = FrameGetColorMap(ObjGetEditFrame(lpObject)))
			lpColorMap = FrameCopyColorMap(lpColorMap);
		else
			lpColorMap = NULL;
		}
	if (lpObject->DataUndoType & (UT_DATA|UT_NEWDATA))
		{
		PixmapEditUndo(&lpObject->Pixmap);
		if (fBase)
			{
			npix = FrameXSize(ObjGetEditFrame(lpObject));
			nlin = FrameYSize(ObjGetEditFrame(lpObject));
			if (lpObject->DataUndoType & UT_NEWDATA)
				{
				tempDataType = DataType;
				DataType = UndoDataType;
				UndoDataType = tempDataType;
				}
			}
		}
	if (lpObject->DataUndoType & UT_OBJECTRECT)
		{
		rTemp = lpObject->rObject;
		lpObject->rObject = lpObject->rUndoObject;
		lpObject->rUndoObject = rTemp;
		}
	if (lpObject->DataUndoType & UT_RESOLUTION)
		{
		FrameSetResolution( lpObject->Pixmap.EditFrame,
							lpObject->UndoResolution);
		lpObject->UndoResolution = Resolution;
		}
	if (lpObject->DataUndoType & UT_UNDOTEXTDATA)
		{
      	if (lpObject->lpUndoText)
      		{
      		CTextObject *pTmp    = lpObject->lpUndoText;
      		lpObject->lpUndoText = lpObject->lpText;
      		lpObject->lpText     = pTmp;
      		}
    	}
	if (lpObject->DataUndoType & UT_COLORMAP)
		{
		if (lpObject->UndoColorMap)
			{
			FrameSetColorMap( ObjGetEditFrame(lpObject), lpObject->UndoColorMap);
			FrameDestroyColorMap(lpObject->UndoColorMap);
			}
		lpObject->UndoColorMap = lpColorMap;
		}
	if (lpObject->DataUndoType & UT_SELECTION)
		{
		fSelected = lpObject->fSelected;
		lpObject->fSelected = lpObject->fUndoSelected;
		lpObject->fUndoSelected = fSelected;
		}
	if (lpObject->DataUndoType & UT_LOCKOBJECTS)
		{
		bLocked = lpObject->bLocked;
		lpObject->bLocked = lpObject->bUndoLocked;
		lpObject->bUndoLocked = bLocked;
		}
	if (lpObject->DataUndoType & UT_GROUPOBJECTS)
		{
		GroupID = lpObject->wGroupID;
		lpObject->wGroupID = lpObject->UndoGroupID;
		lpObject->UndoGroupID = GroupID;
		}
	if (lpObject->DataUndoType & UT_DELETEOBJECTS)
		{
		lpNext = lpObject;
		while (lpNext = GetNextObject(lpNext, YES, NO, YES))
			{
			if (lpNext->fUndoDeleted || lpNext->fDeleted)
				{
				fDeleted = lpNext->fDeleted;
				lpNext->fDeleted = lpNext->fUndoDeleted;
				lpNext->fUndoDeleted = fDeleted;
				}
			}
		}
	if (fBase && lpObject->DataUndoType & UT_MOVEOBJECTS)
		{
		lpNext = lpObject;
		while (lpNext = GetNextObject(lpNext, YES, NO, NO))
			{
			rTemp = lpNext->rObject;
			lpNext->rObject = lpNext->rUndoObject;
			lpNext->rUndoObject = rTemp;
			}
		}
	lpObject->DataUndoNotRedo = !lpObject->DataUndoNotRedo;
	if (!fUndoAlpha)
		fUndoAlpha = lpObject->fBothDirty;
	}
else if (fUndoAlpha && lpObject->fBothDirty)
	fUndoAlpha = NO;

if (fUndoAlpha && lpObject->AlphaDirty)
	{
	if (lpAlpha)
		{
		if (lpObject->AlphaUndoType & (UT_ALPHA|UT_NEWALPHA))
			{
			PixmapEditUndo(&lpAlpha->Pixmap);
			rTemp = lpAlpha->rMask;
			lpAlpha->rMask = lpAlpha->rUndoMask;
			lpAlpha->rUndoMask = rTemp;
			}
		}
	if (lpObject->AlphaUndoType & (UT_CREATEMASK|UT_DELETEMASK))
		{
		lpTemp = lpObject->lpAlpha;
		lpObject->lpAlpha = lpObject->lpUndoAlpha;
		lpObject->lpUndoAlpha = lpTemp;
		}
	lpObject->AlphaUndoNotRedo = !lpObject->AlphaUndoNotRedo;
	}
lpAlpha = lpObject->lpAlpha;
// check to make sure the mask is still the same size
if (fUndoData && fBase && lpObject->Pixmap.fNewFrame)
	{
	// we just undid to a different size frame bag mask delete undo
	if (lpObject->lpUndoAlpha && !lpObject->fBothDirty)
		ObjEditApply(lpObject, NO, YES, NO);
	if (lpAlpha)
		{
		XSize = FrameXSize(lpAlpha->Pixmap.EditFrame);
		YSize = FrameYSize(lpAlpha->Pixmap.EditFrame);
		if (XSize != FrameXSize(lpObject->Pixmap.EditFrame) ||
			YSize != FrameYSize(lpObject->Pixmap.EditFrame))
			{
			ObjEditInit(lpObject, UT_DELETEMASK);
			// dont free mask if it was stored for later undo/redo
			if (!lpObject->lpUndoAlpha)
				MaskClose(lpObject->lpAlpha);
			lpObject->fBothDirty = YES;
			lpObject->AlphaDirty = lpObject->DataDirty;
			lpObject->lpAlpha = NULL;
			}
		}
	}
}
Esempio n. 15
0
BOOL CImage::ObjEditInit(LPOBJECT lpObject, UNDO_TYPE UndoType)
{
LPALPHA lpAlpha;
LPOBJECT lpNext;
BOOL fBase, fDataInit, fAlphaInit;
LPCOLORMAP lpColorMap;

// See if this objects the base, and get alpha channel of object
fBase = (lpObject == GetBase());
lpAlpha = lpObject->lpAlpha;

//
// HANDLE INITIALIZATION OF OBJECT DATA
//

fDataInit = (UndoType & UT_DATAUNDO) != 0;
if (fDataInit && !(Control.NoUndo || fDisableUndos))
	{
	// Apply any changes that have been made if in auto apply mode
	// or if in manual apply mode and changes have been undone
	// the init flag is set only if we are doing an edit in place change
	// to the data so we get rid of any useless undo's
	if (!Control.UseApply || ( Control.UseApply && !lpObject->DataUndoNotRedo ) )
		ObjEditApply(lpObject, YES, !fBase, (UndoType & UT_DATA) != 0);

	// Save undo information for the specific type of operation
 	if (UndoType & UT_UNDOTEXTDATA && !(lpObject->DataUndoType & UT_UNDOTEXTDATA))
		lpObject->lpUndoText = new CTextObject(*lpObject->lpText);
	if (UndoType & UT_OBJECTRECT && !(lpObject->DataUndoType & UT_OBJECTRECT))
		lpObject->rUndoObject = lpObject->rObject;
	if (UndoType & UT_RESOLUTION && !(lpObject->DataUndoType & UT_RESOLUTION))
		lpObject->UndoResolution = FrameResolution(ObjGetEditFrame(lpObject));
	if (UndoType & UT_COLORMAP && !(lpObject->DataUndoType & UT_COLORMAP))
		{
		if (lpColorMap = FrameGetColorMap(ObjGetEditFrame(lpObject)))
			lpObject->UndoColorMap = FrameCopyColorMap(lpColorMap);
		else
			lpObject->UndoColorMap = NULL;
		}
	if (UndoType & UT_SELECTION && !(lpObject->DataUndoType & UT_SELECTION))
		lpObject->fUndoSelected = lpObject->fSelected;
	// Size base is a special case for the base and base only
	if (UndoType & UT_DATA)
		{
		// init the data pixmap for editing
		if (!lpObject->Pixmap.UndoFrame)
			if (!PixmapInitUndo(&lpObject->Pixmap))
				return(FALSE);
		}
	if (UndoType & UT_NEWDATA)
		{
		if (fBase)
			UndoDataType = DataType;
		}
	if (fBase && UndoType & UT_MOVEOBJECTS &&
		!(lpObject->DataUndoType & UT_MOVEOBJECTS))
		{
		lpNext = lpObject;
		while (lpNext = GetNextObject(lpNext, YES, NO, NO))
			{
			ObjEditApply(lpNext, TRUE, TRUE, FALSE);
			lpNext->rUndoObject = lpNext->rObject;
			}
		}
	// Delete objects is a special case for the base and base only
	if (fBase && UndoType & UT_DELETEOBJECTS &&
		!(lpObject->DataUndoType & UT_DELETEOBJECTS))
		{
		lpNext = lpObject;
		while (lpNext = GetNextObject(lpNext, YES, NO, YES))
			lpNext->fUndoDeleted = NO;
		}
	if (UndoType & UT_GROUPOBJECTS && !(lpObject->DataUndoType & UT_GROUPOBJECTS))
		lpObject->UndoGroupID = lpObject->wGroupID;
	if (UndoType & UT_LOCKOBJECTS &&	!(lpObject->DataUndoType & UT_LOCKOBJECTS))
		lpObject->bUndoLocked = lpObject->bLocked;
	}

// now that we have successfully initialized everything set UndoTypes
if (fDataInit)
	{
	lpObject->DataUndoNotRedo = YES;
	lpObject->DataUndoType |= (UndoType & UT_DATAUNDO);
	}

//
// HANDLE INITIALIZATION OF OBJECT ALPHA
//
fAlphaInit = (UndoType & UT_ALPHAUNDO) != 0;
if (fAlphaInit && !(Control.NoUndo  || fDisableUndos) && (!fBase || Control.UndoMasks))
	{
	// Apply any changes that have been made if in auto apply mode
	// or if in manual apply mode and changes have been undone or
	// apply any changes only to the mask
	// or if it is a change to both data and mask and
	// both were not dirty before
	// Initialize the data undo if the object is not the base and we didn't
	// already do a data init
	// the init flag is set only if we are doing an edit in place change
	// to the alpha so we get rid of any useless undo's
	if (!Control.UseApply ||
		(Control.UseApply && !lpObject->AlphaUndoNotRedo) ||
		(fBase && (!fDataInit || !lpObject->fBothDirty)))
		ObjEditApply(lpObject, fDataInit ? NO : !fBase, YES,
					(UndoType & UT_ALPHA) != 0);

	// Save undo information for the specific type of operation
	if (lpAlpha)
		{
		if (!lpObject->AlphaUndoType)
			{
			if (UndoType & UT_ALPHA)
				{
				// init the data pixmap for editing
				if (!lpAlpha->Pixmap.UndoFrame)
					if (!PixmapInitUndo(&lpAlpha->Pixmap))
						return(FALSE);
				lpAlpha->rUndoMask = lpAlpha->rMask;
				}
			if (UndoType & UT_NEWALPHA)
				lpAlpha->rUndoMask = lpAlpha->rMask;
			if (fBase && UndoType & UT_CREATEMASK)
				lpObject->lpUndoAlpha = NULL;
			if (fBase && UndoType & UT_DELETEMASK)
				lpObject->lpUndoAlpha = lpAlpha;
			if (UndoType & UT_ALPHAUNDO)
				{
				lpObject->AlphaUndoNotRedo = YES;
				lpObject->AlphaUndoType |= (UndoType & UT_ALPHAUNDO);
				}
			}
		}
	}

return(TRUE);
}
Esempio n. 16
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. 17
0
BOOL ExportImageDLL( LPSTR lpExportFile )
{
	HMODULE   hModule;
	FARPROC  lpClockCursor = NULL;
	FARPROC  lpDataPointer = NULL;
	EXPORTPROC    lpStartProc;
	EXPORTPROC    lpProcessProc;
	EXPORTPROC    lpEndProc;
	LPFRAME  lpFrame;

	EXPPARMS parms;
	BOOL     fSuccess = FALSE;
	LPIMAGE lpImage;

	lpImage = GetActiveImage();

	if (!lpImage)
		goto Exit;

	lpFrame = ImgGetBaseEditFrame(lpImage);

	if (!lpFrame)
		goto Exit;

	if (!(hModule = (HMODULE)AstralLoadLibrary(lpExportFile)))
		goto Exit;

	lpStartProc   = (EXPORTPROC)GetProcAddress(hModule, "_ExportStart");
	lpProcessProc = (EXPORTPROC)GetProcAddress(hModule, "_ExportProcess");
	lpEndProc     = (EXPORTPROC)GetProcAddress(hModule, "_ExportEnd");

	if ( !lpStartProc || !lpProcessProc || !lpEndProc )
		goto Exit;

	iExportXSize = FrameXSize( lpFrame );
	iExportYSize = FrameYSize( lpFrame );
	iExportDepth = FrameDepth( lpFrame );
	iExportResolution = FrameResolution( lpFrame );

	lpClockCursor = MakeProcInstance( (FARPROC)ExportClockCursor, PictPubApp.Get_hInstAstral() );
	lpDataPointer = MakeProcInstance( (FARPROC)ExportDataPointer, PictPubApp.Get_hInstAstral() );

	AllocLines( &lpExportBuffer, 1, iExportXSize, max(1, iExportDepth));

	parms.hInstance      = PictPubApp.Get_hInstAstral();
	parms.hWnd           = GetActiveWindow();
	parms.lpszFileName   = lpImage->CurFile;
	parms.XSize          = iExportXSize;
	parms.YSize          = iExportYSize;
	parms.Depth          = iExportDepth;
	parms.Resolution     = iExportResolution;
	parms.StatusCallback = (LPROC)lpClockCursor;
	parms.DataPointer    = (LPTRPROC)lpDataPointer;

	if (!lpClockCursor || !lpDataPointer || !lpExportBuffer)
		goto Exit;


	if ((*lpStartProc)((LPEXPPARMS)&parms))
	{
		MessageStatus( IDS_PLEASEWAIT );
		if ((*lpProcessProc)((LPEXPPARMS)&parms))
		{
			fSuccess = TRUE;
			(*lpEndProc)((LPEXPPARMS)&parms);
		}
	}

Exit:

	if (lpClockCursor)
		FreeProcInstance((FARPROC)lpClockCursor);

	if (lpDataPointer)
		FreeProcInstance((FARPROC)lpDataPointer);

	if (lpExportBuffer)
		FreeUp(lpExportBuffer);

	lpExportBuffer = NULL;

	if (hModule)
		FreeLibrary(hModule);

	MessageStatus( 0 );

	return(fSuccess);
}
Esempio n. 18
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. 19
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 );
}
Esempio n. 20
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. 21
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. 22
0
void VignetteProc( HWND hWindow, UINT msg, int x, int y, UINT32 Option )
/************************************************************************/
{
RECT Rect;
BOOL fShift;
POINT pt;
static int Type, Style;
static BOOL fConstrain;
static RECT SelectRect;
int res;
FRMDATATYPE type;
LPIMAGE lpImage;
STRING szString;
GRADIENT_PARMS parms;

switch (msg)
    {
    case WM_CREATE:	// The first mouse down message
	if (!IsOnImage(hWindow, x, y))
		break;
	ImgGetInfo(GetActiveImage(), NULL, NULL, NULL, &type);
	if (type == FDT_LINEART)
		{
		AstralStrEx( IDC_TOOLNAMESTART+IDC_VIGNETTE, szString, sizeof(szString) );
		Message(IDS_NOTWITHLINEART, (LPSTR)szString);
		break;
		}
	AstralUpdateWindow(hWindow);
	Tool.bActive = YES;
//	SetMaskingState( x, y );
	break;

    case WM_LBUTTONDOWN:
	Type = Vignette.Gradient;
	fConstrain = ( Type == IDC_VIGSQUARE || Type == IDC_VIGCIRCLE );
	AstralSetRectEmpty( &SelectRect );
	if ( Type == IDC_VIGCIRCLE || Type == IDC_VIGELLIPSE )
		Style = SL_ELLIPSE;
	else
	if ( Type == IDC_VIGRADIAL || Type == IDC_VIGLINEAR )
		Style = SL_LINE;
	else
		Style = SL_BOX;
	pt.x = x; pt.y = y;
	StartSelection( hWindow, NULL, &SelectRect, Style | SL_SPECIAL,
		pt, 0L );
	break;

    case WM_LBUTTONUP:
	Tool.bActive = NO;
	Rect = SelectRect; // make a copy before it gets ordered
	EndSelection( hWindow, NULL, &SelectRect, Style, YES );
    lpImage = (LPIMAGE)GetImagePtr ( hWindow );
	res = FrameResolution(ImgGetBaseEditFrame(lpImage));
	type = FrameType(ImgGetBaseEditFrame(lpImage));

	parms.VigOpacity = Vignette.VigOpacity;
	parms.VigMergeMode = Vignette.VigMergeMode;
	parms.iBaseRes = res;
	parms.x1 = Rect.left;
	parms.y1 = Rect.top;
	parms.x2 = Rect.right;
	parms.y2 = Rect.bottom;
	GetActiveColorFromType(type, &parms.StartColor);
	GetAlternateColorFromType(type, &parms.EndColor);
	parms.Gradient = Vignette.Gradient;
	parms.RepeatCount = Vignette.RepeatCount;
	parms.SoftTransition = Vignette.SoftTransition;
	parms.Midpoint = Vignette.Midpoint;
	parms.VigColorModel = Vignette.VigColorModel;
	ProcessCommand(lpImage->lpCmdList, IDS_CMD_GRADIENT, &parms);
	break;

    case WM_MOUSEMOVE:	// sent when ToolActive is on
	fShift = SHIFT;
	pt.x = x; pt.y = y;
	UpdateSelection( hWindow, NULL, &SelectRect, Style,
		pt, fConstrain^CONSTRAINASPECT, 1L, 1L,
		MOVEKEY||Window.fRButtonDown, FROMCENTER);
	break;

    case WM_LBUTTONDBLCLK:
	break;

    case WM_DESTROY:	// The cancel operation message
	if (!Tool.bActive)
		break;
	Tool.bActive = NO;
	EndSelection( hWindow, NULL, &SelectRect, Style, YES );
	break;
    }
}
Esempio n. 23
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. 24
0
static void ObjEditUndo(LPIMAGE lpImage, LPOBJECT lpObject, BOOL fUndoData, BOOL fUndoAlpha)
/***********************************************************************/
{
RECT rTemp;
BOOL fSelected, Resolution, fDeleted, fBase;
LPALPHA lpAlpha, lpTemp;
LPOBJECT lpNext;
int XSize, YSize;
int tempDataType;

lpAlpha = lpObject->lpAlpha;
fBase = lpObject == ImgGetBase(lpImage);
if (fUndoData && lpObject->DataDirty)
	{
	if (lpObject->DataUndoType & UT_RESOLUTION)
		Resolution = FrameResolution(lpObject->Pixmap.EditFrame);
	if (lpObject->DataUndoType & (UT_DATA|UT_NEWDATA))
		{
		PixmapEditUndo(&lpObject->Pixmap);
		if (fBase)
			{
			lpImage->npix = FrameXSize(ObjGetEditFrame(lpObject));
			lpImage->nlin = FrameYSize(ObjGetEditFrame(lpObject));
			if (lpObject->DataUndoType & UT_NEWDATA)
				{
				tempDataType = lpImage->DataType;
				lpImage->DataType = lpImage->UndoDataType;
				lpImage->UndoDataType = tempDataType;
				}
			}
		}
	if (lpObject->DataUndoType & UT_OBJECTRECT)
		{
		rTemp = lpObject->rObject;
		lpObject->rObject = lpObject->rUndoObject;
		lpObject->rUndoObject = rTemp;
		}
	if (lpObject->DataUndoType & UT_RESOLUTION)
		{
		FrameSetResolution( lpObject->Pixmap.EditFrame,
							lpObject->UndoResolution);
		lpObject->UndoResolution = Resolution;
		}
	if (lpObject->DataUndoType & UT_SELECTION)
		{
		fSelected = lpObject->fSelected;
		lpObject->fSelected = lpObject->fUndoSelected;
		lpObject->fUndoSelected = fSelected;
		}
	if (lpObject->DataUndoType & UT_DELETEOBJECTS)
		{
		lpNext = lpObject;
		while (lpNext = ImgGetNextObjectEx(lpImage, lpNext, YES, NO, YES))
			{
			if (lpNext->fUndoDeleted || lpNext->fDeleted)
				{
				fDeleted = lpNext->fDeleted;
				lpNext->fDeleted = lpNext->fUndoDeleted;
				lpNext->fUndoDeleted = fDeleted;
				}
			}
		}
	if (fBase && lpObject->DataUndoType & UT_MOVEOBJECTS)
		{
		lpNext = lpObject;
		while (lpNext = ImgGetNextObjectEx(lpImage, lpNext, YES, NO, NO))
			{
			rTemp = lpNext->rObject;
			lpNext->rObject = lpNext->rUndoObject;
			lpNext->rUndoObject = rTemp;
			}
		}
	lpObject->DataUndoNotRedo = !lpObject->DataUndoNotRedo;
	if (!fUndoAlpha)
		fUndoAlpha = lpObject->fBothDirty;
	}
else if (fUndoAlpha && lpObject->fBothDirty)
	fUndoAlpha = NO;

if (fUndoAlpha && lpObject->AlphaDirty)
	{
	if (lpAlpha)
		{
		if (lpObject->AlphaUndoType & (UT_ALPHA|UT_NEWALPHA))
			{
			PixmapEditUndo(&lpAlpha->Pixmap);
			rTemp = lpAlpha->rMask;
			lpAlpha->rMask = lpAlpha->rUndoMask;
			lpAlpha->rUndoMask = rTemp;
			}
		}
	if (lpObject->AlphaUndoType & (UT_CREATEMASK|UT_DELETEMASK))
		{
		lpTemp = lpObject->lpAlpha;
		lpObject->lpAlpha = lpObject->lpUndoAlpha;
		lpObject->lpUndoAlpha = lpTemp;
		}
	lpObject->AlphaUndoNotRedo = !lpObject->AlphaUndoNotRedo;
	}
lpAlpha = lpObject->lpAlpha;
// check to make sure the mask is still the same size
if (fUndoData && fBase && lpObject->Pixmap.fNewFrame)
	{
	// we just undid to a different size frame bag mask delete undo
	if (lpObject->lpUndoAlpha && !lpObject->fBothDirty)
		ObjEditApply(lpImage, lpObject, NO, YES, NO);
	if (lpAlpha)
		{
		XSize = FrameXSize(lpAlpha->Pixmap.EditFrame);
		YSize = FrameYSize(lpAlpha->Pixmap.EditFrame);
		if (XSize != FrameXSize(lpObject->Pixmap.EditFrame) ||
			YSize != FrameYSize(lpObject->Pixmap.EditFrame))
			{
			ObjEditInit(lpImage, lpObject, UT_DELETEMASK);
			lpObject->fBothDirty = YES;
			lpObject->AlphaDirty = lpObject->DataDirty;
			lpObject->lpAlpha = NULL;
			}
		}
	}
}
Esempio n. 25
0
BOOL GradientImage( LPIMAGE lpImage, LPGRADIENT_PARMS lpParms)
{
	LPFRAME lpFrame;
	RECT rMask;
	LPINT lpD;
	FRMTYPEINFO TypeInfo;
	int dx, dy, iCount;
	int index, prev, next, pi, ni;
	long ldx, ldy, x, y, xs, xe, ys, ye, asqrd, bsqrd, r;
	LPDATAPROC lpVignetteProc;
	ENGINE Engine;
	BOOL   DoHSL;
	GRADIENT_DATA data;
	int res;

   FRMDATATYPE type;
	ImgGetInfo(lpImage, NULL, NULL, NULL, &type);
	if (type == FDT_LINEART)
		return(FALSE);
	if (!(lpFrame = ImgGetBaseEditFrame(lpImage)))
		return(FALSE);
	res = FrameResolution(lpFrame);
	data.x1 = lpParms->x1;
	data.y1 = lpParms->y1;
	data.x2 = lpParms->x2;
	data.y2 = lpParms->y2;
	ResConvertUL(lpParms->iBaseRes, res, &data.x1, &data.y1);
	ResConvertLR(lpParms->iBaseRes, res, &data.x2, &data.y2);
	dx = data.x2 - data.x1;
	dy = data.y2 - data.y1;
	data.SoftTransition = lpParms->SoftTransition;
	data.lpPaletteLUT = NULL;

	if (lpParms->Gradient == IDC_VIGLINEAR || lpParms->Gradient == IDC_VIGRADIAL)
	{
		if (abs(dx) <= 3 && abs(dy) <= 3)
			return(FALSE);
	}
	else
	{
		if (abs(dx) <= 3 || abs(dy) <= 3)
			return(FALSE);
	}

	data.xc = (data.x1 + data.x2) / 2;
	data.yc = (data.y1 + data.y2) / 2;

	if ( (data.nRepetitions = lpParms->RepeatCount) <= 0 )
		data.nRepetitions = 1;

	FrameGetTypeInfo(lpFrame, &TypeInfo);

	DoHSL = (lpParms->VigColorModel+IDC_FIRST_MODEL) != IDC_MODEL_RGB &&
				(TypeInfo.DataType > FDT_GRAYSCALE);

	switch (lpParms->Gradient)
	{
		case IDC_VIGLINEAR:
			data.D = lsqrt(((long)dx*(long)dx)+((long)dy*(long)dy));
			data.sine = FGET(-dy, data.D);
			data.cosine = FGET(dx, data.D);
			data.xr = WHOLE(( rotx(data.x2, data.y2, data.x1, data.y1,
            data.cosine, data.sine) ));
			lpVignetteProc = (LPDATAPROC)linear_vignette_proc;
		break;

		case IDC_VIGRADIAL:
			data.D = lsqrt(((long)dx*(long)dx)+((long)dy*(long)dy));
			lpVignetteProc = (LPDATAPROC)radial_vignette_proc;
		break;

		case IDC_VIGCIRCLE:
			data.x1 = data.xc;
			data.y1 = data.yc;
			data.y2 = data.yc;
			dx = data.x2 - data.x1;
			dy = data.y2 - data.y1;
			if (!dx && !dy)
				return(FALSE);
			data.D = lsqrt(((long)dx*(long)dx)+((long)dy*(long)dy));
			lpVignetteProc = (LPDATAPROC)radial_vignette_proc;
		break;

		case IDC_VIGSQUARE:
		case IDC_VIGRECTANGLE:
			data.ymin = min(data.y1, data.y2);
			data.ymax = max(data.y1, data.y2);
			data.xmin = min(data.x1, data.x2);
			data.xmax = max(data.x1, data.x2);

			ldx = data.xmin-data.xc;		// upper left
			ldy = data.ymin-data.yc;
			data.m1 = (256L * ldy) / ldx;
			data.b1 = data.ymin - ((data.m1 * data.xmin)/256L);
			data.D1 = lsqrt((ldx*ldx)+(ldy*ldy));

			ldx = data.xmax-data.xc;		// upper right
			ldy = data.ymin-data.yc;
			data.m2 = (256L * ldy) / ldx;
			data.b2 = data.ymin - ((data.m2 * data.xmax)/256L);
			data.D2 = lsqrt((ldx*ldx)+(ldy*ldy));

			ldx = data.xmax-data.xc;		// lower right
			ldy = data.ymax-data.yc;
			data.m3 = (256L * ldy) / ldx;
			data.b3 = data.ymax - ((data.m3 * data.xmax)/256L);
			data.D3 = lsqrt((ldx*ldx)+(ldy*ldy));

			ldx = data.xmin-data.xc;		// lower left
			ldy = data.ymax-data.yc;
			data.m4 = (256L * ldy) / ldx;
			data.b4 = data.ymax - ((data.m4 * data.xmin)/256L);
			data.D4 = lsqrt((ldx*ldx)+(ldy*ldy));

			lpVignetteProc = (LPDATAPROC)rectangle_vignette_proc;
		break;

		case IDC_VIGELLIPSE:
			if ( !(data.lpD = (LPINT)Alloc((long)sizeof(int)*(TSIZE+1))) )
			{
				Message(IDS_EMEMALLOC);
				return(FALSE);
			}
			iCount = TSIZE+1;
			lpD = data.lpD;
			while (--iCount >= 0)
				*lpD++ = -1;				
			data.ymin = min(data.y1, data.y2);
			data.ymax = max(data.y1, data.y2);
			data.xmin = min(data.x1, data.x2);
			data.xmax = max(data.x1, data.x2);
			data.ea = dx/2;
			data.eb = dy/2;
			if (!data.ea || !data.eb)
			{
				FreeUp((LPTR)data.lpD);
				return(FALSE);
			}
			asqrd = data.ea*data.ea;
			bsqrd = data.eb*data.eb;

			// fill in a table with radius information for the
			// ellipse.  The radius for a given point would be
			// starting from the center of the ellipse, going 
			// through to point, and where it intersects the 
			// edge of the ellipse.  We need the radius for
			// the D value used in the ellipse_proc, which is
			// the maximum distance used for determining how to
			// calculate the gradient, which is d/D.  d is the 
			// distance of the point from the center, D is extracted
			// from the table built below.  The index of the table is
			// formed from the ratio of sides of the triangle formed.
			// This is like looking up the angle to see where the
			// point would intersect the circle.  But we calculate
			// the radii ahead of time to speed things up.
			if (data.ea > data.eb)	// step in x
			{
				xs = data.xc - data.xc;
				xe = data.xmax - data.xc;
				for (x = xs; x <= xe; ++x)
				{
					y = ((data.eb*(long)lsqrt(asqrd - (x*x)))+(data.ea/2))/data.ea;
					r = (x*x)+(y*y);
					if (r <= 0)
						r = 1;
					index = ((x * x * (long)TSIZE)+(r/2)) / r;
					index = bound(abs(index), 0, TSIZE);
					data.lpD[index] = lsqrt(r);
				}
			}
			else		// step in y
			{
				ys = data.yc - data.yc;
				ye = data.ymax - data.yc;
				for (y = ys; y <= ye; ++y)
				{
					x = ((data.ea*(long)lsqrt(bsqrd - (y*y)))+(data.eb/2))/data.eb;
					r = (x*x)+(y*y);
					if (r <= 0)
						r = 1;
					index = ((y * y * (long)TSIZE)+(r/2)) / r;
					index = bound(abs(index), 0, TSIZE);
					data.lpD[index] = lsqrt(r);
				}
			}
			// find the first valid entry in our table
			for (index = 0; index <= TSIZE && data.lpD[index] < 0; ++index)
				;

			// see if we have any entries
			if (index > TSIZE)
			{
				FreeUp((LPTR)data.lpD);
				return(FALSE);
			}

			// fill in all entries before first with value of first
			while (--index >= 0)
				data.lpD[index] = data.lpD[index+1];

			// find last valid entry in table
			for (index = TSIZE; index >= 0 && data.lpD[index] < 0; --index)
				;

			// see if we have any entries
			if (index < 0)
			{
				FreeUp((LPTR)data.lpD);
				return(FALSE);
			}

			// fill in all entries after last with value of last
			while (++index <= TSIZE)
				data.lpD[index] = data.lpD[index-1];

			// interpolate values of all empty cells
			for (index = 0; index <= TSIZE; ++index)
			{
				if (data.lpD[index] < 0)
				{
					pi = index - 1;
					prev = data.lpD[pi];
					ni = index;
					while (data.lpD[ni] < 0)
						++ni;
					next = data.lpD[ni];
					// remember here that (index-pi) == 1
					data.lpD[index] = prev + ((next-prev)/(ni-pi));
				}
			}
			lpVignetteProc = (LPDATAPROC)ellipse_vignette_proc;
		break;

		default:
			return(FALSE);
		break;
	}

	switch(TypeInfo.DataType)
	{
		case FDT_LINEART :
		case FDT_GRAYSCALE :
			data.lpProcessProc = (LPVIGPROC)ProcessVignette8;
		break;

		case FDT_PALETTECOLOR:
			data.lpProcessProc = (LPVIGPROC)ProcessVignette8P;
			data.lpPaletteLUT = CreatePaletteLut15(TypeInfo.ColorMap->RGBData,
					TypeInfo.ColorMap->NumEntries, NULL, NULL);
		break;

		case FDT_RGBCOLOR :
			data.lpProcessProc = (LPVIGPROC)ProcessVignette24;
		break;

		case FDT_CMYKCOLOR :
			data.lpProcessProc = (LPVIGPROC)ProcessVignette32;
		break;
	}

	data.lpMidpointTable = BuildMidPointTable(
							DoHSL,
							TypeInfo.DataType,
							lpParms->Midpoint,
							&lpParms->StartColor,
							&lpParms->EndColor,
							&data );

	ImgGetMaskRect( lpImage, &rMask );
	data.lplD = (LPLONG)Alloc((long)sizeof(long)*(long)RectWidth(&rMask));
	data.lpld = (LPLONG)Alloc((long)sizeof(long)*(long)RectWidth(&rMask));

	if (!data.lpld || !data.lplD || !data.lpMidpointTable ||
		(TypeInfo.DataType == FDT_PALETTECOLOR && !data.lpPaletteLUT))
	{
		if (lpParms->Gradient == IDC_VIGELLIPSE)
			FreeUp((LPTR)data.lpD);
		if (data.lplD)
			FreeUp((LPTR)data.lplD);
		if (data.lpld)
			FreeUp((LPTR)data.lpld);
		if (data.lpMidpointTable)
			FreeUp((LPTR)data.lpMidpointTable);
		if (data.lpPaletteLUT)
			FreeUp(data.lpPaletteLUT);
		return(FALSE);
	}

	SetEngineDraw(&Engine,lpVignetteProc,lpParms->VigOpacity,lpParms->VigMergeMode);
	Engine.lpParam = &data;
	Engine.fThread = NO;
	lpParms->Common.StatusCode = LineEngineSelObj(lpImage,&Engine,lpParms->Common.idDirty);
	if (!AstralIsRectEmpty(&Engine.rUpdate))
	{
		lpParms->Common.UpdateType = UT_AREA;
		lpParms->Common.rUpdateArea = Engine.rUpdate;
	}

	FreeUp((LPTR)data.lpld);
	FreeUp((LPTR)data.lplD);
	FreeUp((LPTR)data.lpMidpointTable);
	if (data.lpPaletteLUT)
		FreeUp(data.lpPaletteLUT);

	if (lpParms->Gradient == IDC_VIGELLIPSE)
		FreeUp((LPTR)data.lpD);
	return(lpParms->Common.StatusCode == SC_SUCCESS);
}