int tifwrt( LPSTR lpFileName, LPOBJECT lpObject, LPFRAME lpFrame, LPRECT lpRect, int flag, BOOL fCompressed) { int iRet; int ofp; BOOL bEscapable; bEscapable = !FileExists(lpFileName); if ((ofp = _lcreat(lpFileName,0)) < 0) { Message( IDS_EWRITE, lpFileName ); return(-1); } iRet = TiffWriteFrame( ofp, lpFileName, lpObject, lpFrame, lpRect, flag, fCompressed, bEscapable); _lclose(ofp); return(iRet); }
int objwrt(LPIMAGE lpImage, LPSTR lpFileName, int idFileType, LPRECT lpRect, int flag, BOOL fCompressed) /************************************************************************/ { LPOBJECT lpObject; int ofp; LPLONG lngptr; LPWORD shtptr; FNAME temp; BOOL bEscapable; int nObjects, i, nPasses; long lObjStart; WORD wBytes; LPOBJOFFSETS lpOffsets; if (!lpImage) return( -1 ); lpObject = NULL; nObjects = nPasses = 0; while (lpObject = ImgGetNextObject(lpImage, lpObject, YES, NO)) { if (lpObject->lpAlpha && (nObjects || Save.bSaveMask)) ++nPasses; ++nObjects; ++nPasses; } if (!(lpOffsets = (LPOBJOFFSETS)Alloc(sizeof(OBJOFFSETS)*nObjects))) { Message(IDS_EMEMALLOC); return(-1); } bEscapable = !FileExists(lpFileName); #ifdef _MAC // The Mac file system can't handle the following pathname: // Bad ---> "DIR:FILE.EXT" // Needs to be -> ":DIR:FILE.EXT" // Add the additional ':' here to specify starting at our directory. if (lpFileName[0] != ':') { STRING szName; lstrcpy(szName, lpFileName); lstrcpy(lpFileName+1, szName); lpFileName[0] = ':'; } #endif if ((ofp = _lcreat(lpFileName,0)) < 0) { FreeUp((LPTR)lpOffsets); Message( IDS_EOPEN, lpFileName ); return(-1); } ProgressBegin(nPasses, 0); // Fill in header info shtptr = (LPWORD)LineBuffer[0]; SetNextWord(&shtptr, 0x4949); /* byte order is LSB,MSB */ SetNextWord(&shtptr, OBJ_VERSION); /* Version Number */ SetNextWord(&shtptr, ImgCountObjects(lpImage)); /* Number of Objects */ lngptr = (LPLONG)shtptr; SetNextLong(&lngptr, OBJ_DATA_SIZE); /* size of object data */ SetNextLong(&lngptr, OBJ_HDR_SIZE); /* start of object data */ // Write out header info wBytes = (LPTR)lngptr - (LPTR)LineBuffer[0]; if ( _lwrite(ofp, LineBuffer[0], wBytes) != wBytes ) goto BadWrite; lObjStart = _llseek (ofp, 0L, 1); wBytes = OBJ_DATA_SIZE * ImgCountObjects(lpImage); if ( _lwrite(ofp, LineBuffer[0], wBytes) != wBytes ) goto BadWrite; lpObject = NULL; i = 0; while (lpObject = ImgGetNextObject(lpImage, lpObject, YES, NO)) { lpOffsets[i].lDataOffset = _llseek (ofp, 0L, 1); lpOffsets[i].lAlphaOffset = 0L; if (TiffWriteFrame(ofp, lpFileName, NULL, lpObject->Pixmap.EditFrame, NULL, flag, fCompressed, bEscapable) < 0) goto BadWrite; if (!lpObject->lpAlpha || (!i && !Save.bSaveMask)) { ++i; continue; } lpOffsets[i].lAlphaOffset = _llseek (ofp, 0L, 1); if (TiffWriteFrame(ofp, lpFileName, NULL, lpObject->lpAlpha->Pixmap.EditFrame, NULL, IDC_SAVECT, fCompressed, bEscapable) < 0) goto BadWrite; ++i; } // fill in object data information and write it _llseek (ofp, lObjStart, 0); lpObject = NULL; i = 0; while (lpObject = ImgGetNextObject(lpImage, lpObject, YES, NO)) { shtptr = (LPWORD)LineBuffer[0]; SetNextWord(&shtptr, lpObject->ObjectType); SetNextWord(&shtptr, lpObject->rObject.left); SetNextWord(&shtptr, lpObject->rObject.top); SetNextWord(&shtptr, lpObject->rObject.right); SetNextWord(&shtptr, lpObject->rObject.bottom); SetNextWord(&shtptr, lpObject->Opacity); SetNextWord(&shtptr, lpObject->MergeMode); SetNextWord(&shtptr, lpObject->wGroupID); SetNextWord(&shtptr, idFileType); if (lpObject->lpAlpha) { SetNextWord(&shtptr, lpObject->lpAlpha->bInvert); SetNextWord(&shtptr, lpObject->lpAlpha->rMask.left); SetNextWord(&shtptr, lpObject->lpAlpha->rMask.top); SetNextWord(&shtptr, lpObject->lpAlpha->rMask.right); SetNextWord(&shtptr, lpObject->lpAlpha->rMask.bottom); } else { SetNextWord(&shtptr, 0); SetNextWord(&shtptr, 0); SetNextWord(&shtptr, 0); SetNextWord(&shtptr, 0); SetNextWord(&shtptr, 0); } lngptr = (LPLONG)shtptr; SetNextLong(&lngptr, lpOffsets[i].lDataOffset); SetNextLong(&lngptr, lpOffsets[i].lAlphaOffset); shtptr = (LPWORD)lngptr; SetNextWord(&shtptr, lpObject->fSelected); SetNextWord(&shtptr, lpObject->ObjectDataID); lngptr = (LPLONG)shtptr; SetNextLong(&lngptr, lpObject->dwObjectData); shtptr = (LPWORD)lngptr; ++i; // Write out Object data wBytes = OBJ_DATA_SIZE;; if ( _lwrite(ofp, LineBuffer[0], wBytes) != wBytes ) goto BadWrite; } FreeUp( (LPTR)lpOffsets ); _lclose(ofp); ProgressEnd(); return( 0 ); BadWrite: _lclose(ofp); FreeUp( (LPTR)lpOffsets ); lstrcpy(temp,lpFileName); FileDelete(temp); if (nPasses) ProgressEnd(); return( -1 ); }