Ejemplo n.º 1
0
static void ObjInitObject(LPOBJECT lpObject,
                          LPFRAME lpFrame,
                          LPMASK lpAlpha,
                          BOOL NoUndo)
/************************************************************************/
{
    PixmapSetup(&lpObject->Pixmap, lpFrame, NoUndo);
    lpObject->lpAlpha = lpAlpha;

    lpObject->DataUndoType = 0;
    lpObject->DataUndoNotRedo = YES;
    lpObject->DataDirty = NO;
    lpObject->AlphaUndoType = 0;
    lpObject->AlphaUndoNotRedo = YES;
    lpObject->AlphaDirty = NO;
    lpObject->fBothDirty = NO;

    lpObject->lpUndoAlpha = NULL;
    AstralSetRectEmpty(&lpObject->rUndoObject);
    lpObject->UndoResolution = 0;
    lpObject->fUndoSelected = NO;

    lpObject->fTransform = NO;
    AstralSetRectEmpty(&lpObject->rTransform);
    lpObject->fPasteIntoMask = NO;
    lpObject->fUndoDeleted = NO;
    lpObject->fUndoFailed = NoUndo;
    lpObject->InitUndoType = 0;
    lpObject->UndoColorMap = NULL;
    lpObject->bLocked = NO;
    lpObject->lpUndoText   = NULL;
    lpObject->lpText   = NULL;
    lpObject->dwObjectID = 0;
    lpObject->szObjectName[0] = '\0';
}
Ejemplo n.º 2
0
BOOL ReadObjData( LPSTR lpFileName, LPOBJECTLIST lpObjList, int outDepth,
		LPINT lpDataType, LPRECT lpScaleRect, LPINT lpFullFileX, LPINT lpFullFileY, LPINT lpFullResolution)

/************************************************************************/
{
LPFRAME lpFrame;
LPOBJECT lpObject;
int ifh;
LPLONG lngptr;
LPWORD shtptr;
int nObjects, i, idFileType, nPasses;
WORD wBytes, wByteOrder, wVersion;
long lObjSize, lObjStart;
LPOBJOFFSETS lpOffsets;
OBJECT Obj;
LFIXED xrate, yrate;
int opix, olin, baseW, baseH;
LPRECT lpLoadRect;

xrate = yrate = UNITY;
lpOffsets = NULL;

if ( !lpObjList )
	return( FALSE );

lpObjList->lpHead = lpObjList->lpTail = NULL;
if ( (ifh = _lopen(lpFileName, OF_READ)) < 0)
	{
	Message( IDS_EOPEN, lpFileName );
	return( FALSE );
	}

// Read in header info
wBytes = OBJ_HDR_SIZE;
if ( _lread(ifh, LineBuffer[0], wBytes) != wBytes )
	goto BadRead;
shtptr = (LPWORD)LineBuffer[0];
wByteOrder = GetNextWord(&shtptr);	/* byte order is LSB,MSB */
if (wByteOrder != TIF_II && wByteOrder != TIF_MM)
	goto BadRead;
wVersion  = GetNextWord(&shtptr);	/* Version Number */
nObjects  = GetNextWord(&shtptr);	/* Number of Objects */
lngptr    = (LPLONG)shtptr;
lObjSize  = GetNextLong(&lngptr);	/* size of object data */
lObjStart = GetNextLong(&lngptr);	/* start of object data */

if (!(lpOffsets = (LPOBJOFFSETS)Alloc(sizeof(OBJOFFSETS)*nObjects)))
	{
	Message(IDS_EMEMALLOC);
	return(FALSE);
	}
_llseek (ifh, lObjStart, 0);
wBytes = (WORD)lObjSize;
nPasses = 0;
for (i = 0; i < nObjects; ++i)
	{
	if ( _lread(ifh, LineBuffer[0], wBytes) != wBytes )
		goto BadRead;
	shtptr = (LPWORD)LineBuffer[0];

	Obj.ObjectType 		= (OBJECT_TYPE)GetNextWord(&shtptr);
	Obj.rObject.left 	= GetNextWord(&shtptr);
	Obj.rObject.top 	= GetNextWord(&shtptr);
	Obj.rObject.right 	= GetNextWord(&shtptr);
	Obj.rObject.bottom 	= GetNextWord(&shtptr);
	Obj.Opacity 		= GetNextWord(&shtptr);
	Obj.MergeMode 		= (MERGE_MODE)GetNextWord(&shtptr);
	Obj.wGroupID 		= GetNextWord(&shtptr);

	if (i==0 && lpScaleRect)
	{
		opix = RectWidth(lpScaleRect);
		olin = RectHeight(lpScaleRect);
		baseW = RectWidth(&Obj.rObject);
		baseH = RectHeight(&Obj.rObject);
		xrate = ScaleToFit(&opix, &olin, baseW, baseH);
		if (opix > baseW || olin > baseH)
		{ // No upsizing allowed
			opix = baseW;
			olin = baseH;
		}
		xrate = FGET( opix, baseW );
		yrate = FGET( olin, baseH );
	}
	// scale the object rect
	Obj.rObject.left	= FMUL(Obj.rObject.left, xrate);
	Obj.rObject.top 	= FMUL(Obj.rObject.top, yrate);
	Obj.rObject.right 	= FMUL(Obj.rObject.right, xrate);
	Obj.rObject.bottom 	= FMUL(Obj.rObject.bottom, yrate);

	if (!(lpObject = ObjCreateFromFrame(ST_PERMANENT, NULL, NULL, &Obj.rObject,
										Control.NoUndo)))
		{
		Message(IDS_EMEMALLOC);
		goto BadRead;
		}
	idFileType                = GetNextWord(&shtptr);
	lpOffsets[i].bInvert      = GetNextWord(&shtptr);
	lpOffsets[i].rMask.left   = GetNextWord(&shtptr);
	lpOffsets[i].rMask.top    = GetNextWord(&shtptr);
	lpOffsets[i].rMask.right  = GetNextWord(&shtptr);
	lpOffsets[i].rMask.bottom = GetNextWord(&shtptr);
	// scale the mask rect
	lpOffsets[i].rMask.left	  = FMUL(lpOffsets[i].rMask.left,   xrate);
	lpOffsets[i].rMask.top 	  = FMUL(lpOffsets[i].rMask.top,    yrate);
	lpOffsets[i].rMask.right  = FMUL(lpOffsets[i].rMask.right,  xrate);
	lpOffsets[i].rMask.bottom = FMUL(lpOffsets[i].rMask.bottom, yrate);
	lngptr = (LPLONG)shtptr;
	lpOffsets[i].lDataOffset  = GetNextLong(&lngptr);
	lpOffsets[i].lAlphaOffset = GetNextLong(&lngptr);
	shtptr = (LPWORD)lngptr;

	// versions after 1.1 saved selected state
	if (wVersion == 0x0101)
		Obj.fSelected = NO;
	else
		Obj.fSelected = GetNextWord(&shtptr);

    if (wVersion < 0x0103 || lObjSize == 41)
    {
        Obj.ObjectDataID = OBJECT_DATA_NONE;
        Obj.dwObjectData = 0;
    }
	else
    {
        Obj.ObjectDataID = GetNextWord(&shtptr);
        Obj.dwObjectData = *(LPDWORD)shtptr;
        shtptr += 2;
    }

	lpObject->ObjectType 	= Obj.ObjectType;
	lpObject->Opacity 		= Obj.Opacity;
	lpObject->MergeMode 	= Obj.MergeMode;
	lpObject->wGroupID 		= Obj.wGroupID;
	lpObject->fSelected 	= Obj.fSelected;
    lpObject->ObjectDataID 	= Obj.ObjectDataID;
    lpObject->dwObjectData 	= Obj.dwObjectData;

	ObjAddTail(lpObjList, (LPPRIMOBJECT)lpObject);

	++nPasses;
	if (lpOffsets[i].lAlphaOffset)
		++nPasses;
	}

ProgressBegin(nPasses, 0);
lpObject = NULL;
i = 0;
while (lpObject = (LPOBJECT)ObjGetNextObject(lpObjList, (LPPRIMOBJECT)lpObject, YES))
	{
	if (lpScaleRect && i!=0)
		{
		lpLoadRect = &lpObject->rObject;
		}
	else
		lpLoadRect = lpScaleRect;
	_llseek (ifh, lpOffsets[i].lDataOffset, 0);
	lpFrame = ReadTiffData(ifh, lpFileName, outDepth, lpDataType,
		NO/*bReadOnly*/, lpLoadRect, NO, lpFullFileX, lpFullFileY,
		lpFullResolution);
	if (i == 0)
		{
		lpDataType = NULL;
		lpFullFileX = NULL;
		lpFullFileY = NULL;
		lpFullResolution = NULL;
		}
	if (!lpFrame)
		goto BadRead;
	PixmapSetup(&lpObject->Pixmap, lpFrame, Control.NoUndo);
	if (!lpOffsets[i].lAlphaOffset)
		{
		++i;
		continue;
		}
	_llseek (ifh, lpOffsets[i].lAlphaOffset, 0);
	lpFrame = ReadTiffData(ifh, lpFileName, outDepth, lpDataType,
		NO/*bReadOnly*/, lpLoadRect, NO, NULL, NULL, NULL);
	if (!lpFrame)
		goto BadRead;
	lpObject->lpAlpha = MaskCreate(lpFrame, 0, 0, OFF, Control.NoUndo);
	if (!lpObject->lpAlpha)
		{
		Message(IDS_EMEMALLOC);
		goto BadRead;
		}
	lpObject->lpAlpha->bInvert = lpOffsets[i].bInvert;
	lpObject->lpAlpha->rMask = lpOffsets[i].rMask;
	++i;
	}

if ( lpOffsets )
	FreeUp( (LPTR)lpOffsets );
_lclose(ifh);
ProgressEnd();
return( TRUE );

BadRead:
while (lpObject = (LPOBJECT)ObjGetNextObject(lpObjList, NULL, YES))
	{
	ObjUnlinkObject(lpObjList, (LPPRIMOBJECT)lpObject);
	ObjFreeUp(lpObject);
	}
_lclose(ifh);
if ( lpOffsets )
	FreeUp( (LPTR)lpOffsets );
if (nPasses)
	ProgressEnd();
Message( IDS_EREAD, lpFileName );
return( FALSE );
}