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); }
BOOL CImage::Create() { // if a command list was not passed in then create one if (!lpCmdList) { // if we don't have a command list, create one lpCmdList = CreateCommandList(); if ( !lpCmdList) return(FALSE); } // link command list back to image lpCmdList->ThreadData.lpImage = this; // setup image information for easy access LPFRAME lpFrame = GetBaseEditFrame(); npix = FrameXSize(lpFrame); nlin = FrameYSize(lpFrame); // if using threading and no command list already existence // create the command thread #ifdef WIN32 if (Control.UseThreading) { lstrcpy(lpCmdList->ThreadData.ThreadInfo.szThreadName, filename(CurFile)); } #endif return(TRUE); }
void CImage::GetImageRect(LPRECT lpRect) { LPFRAME lpFrame; lpFrame = GetBaseEditFrame(); SetRect(lpRect, 0, 0, FrameXSize(lpFrame)-1, FrameYSize(lpFrame)-1); }
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); }
void RemoveCodedBackground() { LPFRAME lpFrame; int x, y; int Width; int Height; LPTR lpSrcLine; BYTE r, g, b; if (!lpImage) return; ImgCombineObjects(lpImage, TRUE, FALSE, TRUE); lpFrame = ImgGetBaseEditFrame(lpImage); if (!lpFrame) return; Width = FrameXSize (lpFrame); Height = FrameYSize (lpFrame); for (y=0;y<Height;y++) { AstralClockCursor( y, Height, NO ); lpSrcLine = FramePointer (lpFrame,0,y,TRUE); for (x=0;x<Width;x++) { RGBS Pixel; FrameGetRGB (lpFrame,lpSrcLine,&Pixel,1); r = Pixel.red; g = Pixel.green; b = Pixel.blue; if (r >= 100 && !g && !b) { // a dot Pixel.red = 255; Pixel.green = 255; Pixel.blue = 255; FrameSetRGB (lpFrame,&Pixel,lpSrcLine,1); } else if ( (r != g) || (g != b) ) { // not white or black Pixel.red = 0; Pixel.green = 0; Pixel.blue = 0; FrameSetRGB (lpFrame,&Pixel,lpSrcLine,1); } lpSrcLine += 3; } // Width } // Height }
void CImage::EditedObjectFrame(LPOBJECT lpObject, int iDirty, LPRECT lpEditRect, LPFRAME lpDataFrame, LPFRAME lpAlphaFrame) { LPALPHA lpAlpha; BOOL fEditedData, fEditedAlpha, fBase; fBase = (lpObject == GetBase()); fEditedData = (lpObject->InitUndoType & UT_DATAUNDO) != 0; fEditedAlpha = (lpObject->InitUndoType & UT_ALPHAUNDO) != 0; if (lpEditRect) OffsetRect(lpEditRect, -lpObject->rObject.left, -lpObject->rObject.top); lpAlpha = lpObject->lpAlpha; if (lpObject->lpText) lpObject->lpText->Dirty = (iDirty == IDS_UNDOEDITTEXT)? FALSE:TRUE; if (fEditedData) { fChanged = YES; if (!(Control.NoUndo || fDisableUndos) && !lpObject->fUndoFailed) lpObject->DataDirty = iDirty; if (lpDataFrame) { PixmapNewFrame(&lpObject->Pixmap, lpDataFrame, lpEditRect, Control.UseApply); if (lpObject == GetBase()) { npix = FrameXSize(lpDataFrame); nlin = FrameYSize(lpDataFrame); } } } if (fEditedAlpha) { if (lpObject != GetBase()) fChanged = YES; if (!(Control.NoUndo || fDisableUndos) && (!fBase || Control.UndoMasks) && !lpObject->fUndoFailed) lpObject->AlphaDirty = iDirty; if (lpAlpha && lpAlphaFrame) PixmapNewFrame(&lpAlpha->Pixmap, lpAlphaFrame, lpEditRect, Control.UseApply); } if (Control.NoUndo || fDisableUndos) PurgeObjects(); if (!(Control.NoUndo || fDisableUndos) && !lpObject->fUndoFailed && !lpObject->fBothDirty) lpObject->fBothDirty = fEditedData && fEditedAlpha; if (lpEditRect) OffsetRect(lpEditRect, lpObject->rObject.left, lpObject->rObject.top); }
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 ); }
void ImgEditedObjectFrame(LPIMAGE lpImage, LPOBJECT lpObject, int iDirty, LPRECT lpEditRect, LPFRAME lpDataFrame, LPFRAME lpAlphaFrame) /***********************************************************************/ { LPALPHA lpAlpha; BOOL fEditedData, fEditedAlpha, fBase; fBase = (lpObject == ImgGetBase(lpImage)); fEditedData = (lpObject->InitUndoType & UT_DATAUNDO) != 0; fEditedAlpha = (lpObject->InitUndoType & UT_ALPHAUNDO) != 0; if (lpEditRect) OffsetRect(lpEditRect, -lpObject->rObject.left, -lpObject->rObject.top); lpAlpha = lpObject->lpAlpha; if (fEditedData) { lpObject->fChanged = YES; if (!Control.NoUndo && !lpObject->fUndoFailed) lpObject->DataDirty = iDirty; if (lpDataFrame) { PixmapNewFrame(&lpObject->Pixmap, lpDataFrame, lpEditRect, Control.UseApply); if (lpObject == ImgGetBase(lpImage)) { lpImage->npix = FrameXSize(lpDataFrame); lpImage->nlin = FrameYSize(lpDataFrame); } } } if (fEditedAlpha) { if (lpObject != ImgGetBase(lpImage)) lpObject->fChanged = YES; if (!Control.NoUndo && (!fBase || Control.UndoMasks) && !lpObject->fUndoFailed) lpObject->AlphaDirty = iDirty; if (lpAlpha && lpAlphaFrame) PixmapNewFrame(&lpAlpha->Pixmap, lpAlphaFrame, lpEditRect, Control.UseApply); } if (!Control.NoUndo && !lpObject->fUndoFailed && !lpObject->fBothDirty) lpObject->fBothDirty = fEditedData && fEditedAlpha; if (lpEditRect) OffsetRect(lpEditRect, lpObject->rObject.left, lpObject->rObject.top); }
LOCAL void PaletteMapPixmap(LPPIXMAP lpPixmap, CFrameTypeConvert *pTypeConvert) /***********************************************************************/ { int y, w, h; LPTR lp; ProgressBegin(1, 0); w = FrameXSize(lpPixmap->EditFrame); h = FrameYSize(lpPixmap->EditFrame); for (y = 0; y < h; ++y) { AstralClockCursor(y, h, NO); lp = PixmapPtr(lpPixmap, PMT_EDIT, 0, y, YES); if (!lp) break; pTypeConvert->ConvertData(lp, lp, y, w); } ProgressEnd(); }
LPTR FrameToDIB( LPFRAME lpFrame, LPRECT lpRect ) { RECT Rect; // Make sure that this is a valid pointer if (!lpFrame) { return(NULL); } // Validate the image rectangle if (lpRect == NULL) { lpRect = &Rect; Rect.top = 0; Rect.left = 0; Rect.bottom = FrameYSize( lpFrame ) - 1; Rect.right = FrameXSize( lpFrame ) - 1; } // Call the appropriate conversion function switch (FrameType( lpFrame )) { case FDT_LINEART : return(FrameToLineArtDIB( lpFrame, lpRect )); break; case FDT_GRAYSCALE : case FDT_PALETTECOLOR : return(FrameToPaletteDIB( lpFrame, lpRect )); break; case FDT_RGBCOLOR : case FDT_CMYKCOLOR : return(FrameToColorDIB( lpFrame, lpRect )); break; } return(NULL); }
// 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); }
LPOBJECT ObjCreateFromFrame(STORAGE_TYPE StorageType, LPFRAME lpFrame, LPALPHA lpAlpha, LPRECT lpRect, BOOL NoUndo) /************************************************************************/ { LPOBJECT lpObject; RECT rObject; if (!(lpObject = (LPOBJECT)Alloc(sizeof(OBJECT)))) return(NULL); if (lpRect) rObject = *lpRect; else { if ( !lpFrame ) return( NULL ); rObject.left = rObject.top = 0; rObject.right = FrameXSize(lpFrame) - 1; rObject.bottom = FrameYSize(lpFrame) - 1; } ObjInitPrimObject(lpObject, OT_FRAME, RT_FRAME, StorageType, &rObject); ObjInitObject(lpObject, lpFrame, lpAlpha, NoUndo); return(lpObject); }
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); }
LPOBJECT ObjCreateFromPixmap(STORAGE_TYPE StorageType, LPPIXMAP lpPixmap, LPMASK lpAlpha, LPRECT lpRect, BOOL NoUndo) /************************************************************************/ { LPOBJECT lpObject; RECT rObject; if (!(lpObject = (LPOBJECT)Alloc(sizeof(OBJECT)))) return(NULL); if (lpRect) rObject = *lpRect; else { if ( !lpPixmap->EditFrame ) return( NULL ); rObject.left = rObject.top = 0; rObject.right = FrameXSize(lpPixmap->EditFrame) - 1; rObject.bottom = FrameYSize(lpPixmap->EditFrame) - 1; } ObjInitPrimObject(lpObject, OT_FRAME, RT_FRAME, StorageType, &rObject); ObjInitObject(lpObject, NULL, lpAlpha, NoUndo); lpObject->Pixmap = *lpPixmap; return(lpObject); }
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; } } } }
void CImage::EditUndo( BOOL fEditUndo, BOOL fMaskUndo, LPUPDATE_TYPE lpUpdateType, LPRECT lpUpdateRect) { RECT rUndo, rUndoMask, rTemp; LPOBJECT lpBase, lpObject, lpNext; BOOL fNewSize, fSetupMiniViews, fRemoveMarquee, fUndoDelete, fColorMapChanged; BOOL fUndoAlpha, fUndoData; int nDeleted; LPMASK lpMask; EDIT_TARGET Target; AstralSetRectEmpty(lpUpdateRect); // Initialize things for updating the display fNewSize = fSetupMiniViews = fUndoDelete = fColorMapChanged = NO; AstralSetRectEmpty(&rUndo); AstralSetRectEmpty(&rUndoMask); // loop through objects doing undo lpBase = GetBase(); lpObject = NULL; // get the target of the last edit Target = EditTarget; while (lpObject = GetNextObject(lpObject, NO, NO, fEditUndo)) { // See if this is an object we are undoing if (fEditUndo) { // check for special undo processing of a deleted object if (lpObject->fDeleted) continue; // do no undo processing for a deleted object // { // if (Control.UndoObjects && !IsSelectedObject(lpBase)) // continue; // } else // if target is not the entire image and we are in undo // object mode and the object is not selected then // skip this object if (Target != ET_ALLOBJECTS && Control.UndoObjects && !IsSelectedObject(lpObject)) continue; } // Only handle mask undo for the base object if (fMaskUndo) { if (lpObject != lpBase || lpObject->fBothDirty || !lpObject->AlphaDirty) continue; } fUndoData = fUndoAlpha = NO; // Do preprocess for doing a data undo if (fEditUndo) { if (lpObject->DataDirty) fUndoData = YES; // See if we need to undo the alpha for this object if ((lpObject != lpBase) && lpObject->lpAlpha && lpObject->AlphaDirty) fUndoAlpha = YES; if (!fUndoData && !fUndoAlpha) continue; // check to see and undoing/redoing deleted objects will change // the select state, if so undraw the object marquee if (lpObject == lpBase && lpObject->DataUndoType & UT_DELETEOBJECTS) { fUndoDelete = YES; fRemoveMarquee = NO; nDeleted = 0; lpNext = lpObject; while (lpNext = GetNextObject(lpNext, YES, NO, YES)) { if (lpNext->fUndoDeleted) ++nDeleted; else if (lpNext->fDeleted && lpNext->fSelected) { fRemoveMarquee = YES; break; } } if (GetSelObject(NULL) == lpBase && !fRemoveMarquee) { if (CountObjects() - nDeleted <= 1) fRemoveMarquee = YES; } if (fRemoveMarquee) { GetObjectMarqueeRect(this, &rTemp); AstralUnionRect(lpUpdateRect, lpUpdateRect, &rTemp); } } } else // fMaskUndo if (!lpObject->AlphaDirty) continue; else fUndoAlpha = YES; // do a preprocess for undoing the mask caused either by // a mask undo or by an edit function that also edits the mask if (((lpObject == lpBase) && fEditUndo && lpObject->fBothDirty) || fMaskUndo) { if ( lpObject->AlphaUndoType & (UT_CREATEMASK|UT_DELETEMASK) ) { // if the undo is going to delete the mask, // we need to undraw the mask if (GetMask()) { GetMaskMarqueeRect(this, &rTemp); AstralUnionRect(lpUpdateRect, lpUpdateRect, &rTemp); if (GetMaskUpdateRect(YES, NO, &rTemp)) AstralUnionRect(&rUndoMask, &rUndoMask, &rTemp); } // if the undo is going to create the mask, // we need to undraw the object marquees if // not in mask and object marquee mode else { if (!Control.UseMaskAndObjects) { GetObjectMarqueeRect(this, &rTemp); AstralUnionRect(lpUpdateRect, lpUpdateRect, &rTemp); } } } } // Actually do the undo ObjEditUndo(lpObject, fUndoData, fUndoAlpha); // do a postprocess for undoing the mask if ((lpMask = GetMask()) && (((lpObject == lpBase) && fEditUndo && lpObject->fBothDirty) || fMaskUndo)) { // if the undo is going to add the mask, we need to redraw the mask if (lpObject->AlphaUndoType & (UT_CREATEMASK|UT_DELETEMASK) ) { if (GetMaskUpdateRect(YES, NO, &rTemp)) AstralUnionRect(&rUndoMask, &rUndoMask, &rTemp); } else // just redraw the undo area for the mask AstralUnionRect(&rUndoMask, &rUndoMask, &lpMask->Pixmap.UndoRect); } // Setup rectangle for undoing deletion of objects // Handled specially so that moved objects will still undo // and redo properly if (fEditUndo) { if (lpObject == lpBase && lpObject->DataUndoType & UT_DELETEOBJECTS) { lpNext = lpObject; while (lpNext = GetNextObject(lpNext, YES, NO, YES)) { if (lpNext->fDeleted || lpNext->fUndoDeleted) AstralUnionRect(&rUndo, &rUndo, &lpNext->rObject); } fSetupMiniViews = YES; } if (lpObject->DataUndoType & UT_COLORMAP) fColorMapChanged = YES; if (lpObject->Pixmap.fNewFrame) { /* if new frame, cause window to be redisplayed */ if (lpObject == lpBase) fNewSize = YES; else { if (!fNewSize) { AstralUnionRect(&rUndo, &rUndo, &lpObject->rObject); AstralUnionRect(&rUndo, &rUndo, &lpObject->rUndoObject); } } } else { AstralSetRectEmpty(&rTemp); if (fUndoData) AstralUnionRect(&rTemp, &rTemp, &lpObject->Pixmap.UndoRect); if (fUndoAlpha) AstralUnionRect(&rTemp, &rTemp, &lpObject->lpAlpha->Pixmap.UndoRect); if (rTemp.right >= rTemp.left) { if (!fNewSize) { OffsetRect(&rTemp, lpObject->rObject.left, lpObject->rObject.top); AstralUnionRect(&rUndo, &rUndo, &rTemp); } } if( lpObject->DataUndoType & UT_OBJECTRECT ) { AstralUnionRect( &rUndo, &rUndo, &lpObject->rObject ); AstralUnionRect( &rUndo, &rUndo, &lpObject->rUndoObject ); } } } } // now redisplay whatever changes are necessary for the undo if (fColorMapChanged) { ImgColorMapChanged(this); *lpUpdateType |= UT_DATATYPE; } if (fNewSize) { *lpUpdateType |= UT_DATATYPE; if (lpBase->Pixmap.UndoFrame) { if ((FrameXSize(lpBase->Pixmap.UndoFrame) == FrameXSize(lpBase->Pixmap.EditFrame)) && (FrameYSize(lpBase->Pixmap.UndoFrame) == FrameYSize(lpBase->Pixmap.EditFrame))) fNewSize = NO; } if (fNewSize) *lpUpdateType |= UT_SIZE; else { int dx, dy; GetInfo(&dx, &dy, NULL, NULL); SetRect(lpUpdateRect, 0, 0, dx-1, dy-1); } } else { if (!AstralIsRectEmpty(lpUpdateRect)) *lpUpdateType |= UT_ACTIVEAREA; if (rUndoMask.right >= rUndoMask.left) { *lpUpdateType |= UT_ACTIVEAREA; AstralUnionRect(lpUpdateRect, lpUpdateRect, &rUndoMask); } if (rUndo.right >= rUndo.left) { *lpUpdateType |= UT_AREA; AstralUnionRect(lpUpdateRect, lpUpdateRect, &rUndo); } } }
BOOL CWriteBitmap::CTWrite() { RECT rSave; FRMTYPEINFO inType, outType; LPFRAME lpFrame; CFrameTypeConvert TypeConvert; LPOBJECT lpObject; CFile theFile; CFile* pTheFile = NULL; BOOL fRet = FALSE; LPTR lpTH, lp, lp2,lpBuffer, lpImgScanline; int i,x,j,y, LineSize, npix, nlin; double dbl; int NumOfChannels = 4; if (m_lpObjList) { lpObject = m_lpObjList->lpHead; if (lpObject) lpFrame = ObjGetEditFrame(lpObject); } else { lpFrame = m_lpFrame; lpObject = NULL; } ASSERT(lpFrame); if (m_fSrcArea) rSave = m_rSrcArea; else { rSave.top = rSave.left = 0; rSave.bottom = FrameYSize(lpFrame)-1; rSave.right = FrameXSize(lpFrame)-1; } npix = RectWidth(&rSave); nlin = RectHeight(&rSave); inType = FrameTypeInfo(lpFrame); // cause FramePointer never returns line art if (inType.DataType == FDT_LINEART) inType.DataType = FDT_GRAYSCALE; if (inType.DataType == FDT_GRAYSCALE) { NumOfChannels = 1; FrameSetTypeInfo(&outType, FDT_GRAYSCALE); } else FrameSetTypeInfo(&outType, FDT_CMYKCOLOR); // initialize stuff to do the type conversion ProgressBegin(1); if ((pTheFile = OpenFile()) == NULL) { ProgressEnd(); return(FALSE); } if (npix & 1) // odd pixels LineSize = npix + 1; else LineSize = npix; AllocLines(&lpBuffer, 1, max(LineSize*NumOfChannels, FrameByteWidth(lpFrame)), 1); AllocLines(&lpImgScanline, 1, max(LineSize*NumOfChannels, FrameByteWidth(lpFrame)), 1); if (!lpBuffer || !lpImgScanline) { SetError(BEC_errMemory); goto Exit; } if (!(lpTH = Alloc(1024))) { SetError(BEC_errMemory); return(NULL); } clr( (LPTR)lpTH, 1024); set(lpTH, 80, ' '); lstrcpy((LPSTR)lpTH, m_lpFileName); lpTH[lstrlen(m_lpFileName)] = ' '; lpTH[80] = 'C'; lpTH[81] = 'T'; pTheFile->Write(lpTH, 1024); // write first cluster clr( (LPTR)lpTH, 84); lpTH[0] = 1; // inches lpTH[1] = NumOfChannels; // if (NumOfChannels == 1) *((LPWORD)&lpTH[2]) = 0x0800; else *((LPWORD)&lpTH[2]) = 0x0F00; dbl = nlin / (double)lpFrame->Resolution; sprintf((LPSTR)&lpTH[4], "%+.7E",dbl); lpTH[6] = lpTH[5]; lpTH[5] = '.'; if (lpTH[15] == '+') lpTH[17] = lpTH[18] + 1; else { lpTH[17] = lpTH[18] - 1; lpTH[15] = '+'; } dbl = npix / (double)lpFrame->Resolution; sprintf((LPSTR)&lpTH[18], "%+.7E",dbl); lpTH[20] = lpTH[19]; lpTH[19] = '.'; if (lpTH[29] == '+') lpTH[31] = lpTH[32] + 1; else { lpTH[31] = lpTH[32] - 1; lpTH[29] = '+'; } sprintf((LPSTR)&lpTH[32], "%+12d",nlin); lpTH[32] = '+'; for (i=33; i < 44;i++) if (lpTH[i] == ' ' || lpTH[i] == '+') lpTH[i] = '0'; sprintf((LPSTR)&lpTH[44], "%+12d",npix); lpTH[44] = '+'; for (i=45; i < 56;i++) if (lpTH[i] == ' ' || lpTH[i] == '+') lpTH[i] = '0'; lpTH[56] = 0; // scan direction pTheFile->Write(lpTH, 1024); // write second cluster, Parameter Block TRY { if (!TypeConvert.Init(inType, outType, npix, DT_DEFAULT)) { SetError(BEC_errMemory); goto Exit; } for( y=rSave.top; y <= rSave.bottom; y++) { if (Progress( y-rSave.top, nlin, m_bEscapable )) goto Cancelled; if (lpObject) { if (!ObjGetLine( lpObject, rSave.left, y, (rSave.right - rSave.left) + 1, lpImgScanline)) goto BadRead; lp = lpImgScanline; } else { if ( !(lp = FramePointer( lpFrame, rSave.left, y, NO )) ) goto BadRead; } // convert the data to the new type TypeConvert.ConvertData(lp, lpBuffer, y, npix); lp2 = lpBuffer; for (x=0; x < npix; x++) for (j=0; j < NumOfChannels; j++) *(lpImgScanline + j * LineSize + x) = 255 - *lp2++; pTheFile->Write( lpImgScanline, LineSize*NumOfChannels); } fRet = TRUE; goto Exit; } CATCH_ALL(e) { goto BadWrite; } END_CATCH_ALL BadWrite: SetError(BEC_errWriteFile); goto Exit; BadRead: SetError(BEC_errFrameRead); Cancelled: Exit: CloseFile(pTheFile, fRet); if (lpTH) FreeUp (lpTH); if (lpBuffer) FreeUp(lpBuffer); if (lpImgScanline) FreeUp(lpImgScanline); ProgressEnd(); return( fRet ); }
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 */ } } }
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); }
BOOL CWriteBitmap::GIFWrite() { GIFHDR hdr; GIFDESC imDesc; GIFMAP ColorMap; int y, i, j, npix, nlin; LPTR lp, lpBuffer, lpImgScanline; BYTE cTerm; int codeSize; RECT rSave; BOOL bEscapable; BOOL compressInit; LPLZW_STUFF lpLZW; LPRGB lpRGBmap; LPFRAME lpFrame; LPOBJECT lpObject; FRMTYPEINFO inType, outType, inTypeLA, outTypeLA; CFrameTypeConvert TypeConvert, LineArtConvert; BOOL fRet = FALSE; CFile theFile; CFile* pTheFile = NULL; if (m_lpObjList) { lpObject = m_lpObjList->lpHead; if (lpObject) lpFrame = ObjGetEditFrame(lpObject); } else { lpFrame = m_lpFrame; lpObject = NULL; } ASSERT(lpFrame); ProgressBegin(1); if ((pTheFile = OpenFile()) == NULL) { ProgressEnd(); return(FALSE); } TRY { lpBuffer = NULL; lpImgScanline = NULL; compressInit = NO; /* full color not supported, force mini color */ if (m_DataType != FDT_GRAYSCALE && m_DataType != FDT_LINEART) m_DataType = FDT_PALETTECOLOR; if (m_fSrcArea) rSave = m_rSrcArea; else { rSave.top = rSave.left = 0; rSave.bottom = FrameYSize(lpFrame)-1; rSave.right = FrameXSize(lpFrame)-1; } inType = FrameTypeInfo(lpFrame); // cause FramePointer never returns line art if (inType.DataType == FDT_LINEART) inType.DataType = FDT_GRAYSCALE; // make sure colormap is inited for outType so we don't free bogus ptr FrameSetTypeInfo(&outType, FDT_NONE); npix = RectWidth(&rSave); nlin = RectHeight(&rSave); /* initialize file header */ hdr.ScnWidth = npix; hdr.ScnHeight = nlin; hdr.Background = 0; hdr.GlobalMap = TRUE; hdr.ColorRes = 8; /* initialize image descriptor */ imDesc.ImLeft = 0; imDesc.ImTop = 0; imDesc.ImWidth = npix; imDesc.ImHeight = nlin; imDesc.Zero = 0; /* determine type of image to create */ if ( m_DataType == FDT_GRAYSCALE ) { /* gray */ hdr.ColorRes = 8; hdr.bpp = 8; codeSize = 8; FrameSetTypeInfo(&outType, FDT_GRAYSCALE); } else if ( m_DataType == FDT_LINEART ) { /* line art or scatter */ hdr.ColorRes = 1; hdr.bpp = 1; codeSize = 2; FrameSetTypeInfo(&outType, FDT_LINEART); } else //if ( m_DataType == FDT_PALETTECOLOR ) { /* mini color */ hdr.ColorRes = 8; hdr.bpp = 8; codeSize = 8; if (inType.DataType == FDT_PALETTECOLOR) outType = inType; else FrameSetTypeInfo(&outType, FDT_PALETTECOLOR); } AllocLines( &lpBuffer, 1, npix, 4 ); // max size is cool AllocLines( &lpImgScanline, 1, npix, 4 ); if ( !lpBuffer || !lpImgScanline ) { SetError(BEC_errMemory); goto Exit; } /* set raw info byte */ hdr.RawImInfo = 0x80 | ((hdr.ColorRes-1) << 4) | (hdr.bpp-1); /* write file header */ pTheFile->Write((LPTR)"GIF87a", 6); pTheFile->Write((LPTR)&hdr.ScnWidth, 2); pTheFile->Write((LPTR)&hdr.ScnHeight, 2); pTheFile->Write((LPTR)&hdr.RawImInfo, 1); pTheFile->Write((LPTR)&hdr.Background, 1); pTheFile->Write((LPTR)"", 1); switch (m_DataType) { case FDT_LINEART: /* initialize the color map */ ColorMap.Length = 2; ColorMap.Map[0].red = ColorMap.Map[0].green = ColorMap.Map[0].blue = 0xFF; ColorMap.Map[1].red = ColorMap.Map[1].green = ColorMap.Map[1].blue = 0x00; /* write image descriptor, color map and code size */ if (gifWriteImDesc (pTheFile, &imDesc, &ColorMap, codeSize)) goto BadWrite; break; case FDT_GRAYSCALE: /* initialize the color map */ ColorMap.Length = 256; for (i = 0; i < 256; i++) { ColorMap.Map[i].red = ColorMap.Map[i].green = ColorMap.Map[i].blue = i; } /* write image descriptor, color map and code size */ if (gifWriteImDesc (pTheFile, &imDesc, &ColorMap, codeSize)) goto BadWrite; break; case FDT_PALETTECOLOR: // see if we need to create a palette if (!outType.ColorMap) { outType.ColorMap = FrameCreateColorMap(); if (!outType.ColorMap) { SetError(BEC_errMemory); goto Exit; } outType.ColorMap->NumEntries = 256; if (!CreateOptimizedPalette(lpObject, lpFrame, outType.ColorMap->RGBData, &outType.ColorMap->NumEntries, TRUE, NULL)) { SetError(BEC_errMemory); goto Exit; } } lpRGBmap = outType.ColorMap->RGBData; /* initialize the color map */ ColorMap.Length = 256; for (i = 0; i < 256; i++) { ColorMap.Map[i].red = lpRGBmap[i].red; ColorMap.Map[i].green = lpRGBmap[i].green; ColorMap.Map[i].blue = lpRGBmap[i].blue; } /* write image descriptor, color map and code size */ if (gifWriteImDesc (pTheFile, &imDesc, &ColorMap, codeSize)) goto BadWrite; break; } // initialize stuff to do the type conversion if (!TypeConvert.Init(inType, outType, npix, m_DitherType)) { SetError(BEC_errMemory); goto Exit; } if (outType.DataType == FDT_LINEART) { FrameSetTypeInfo(&inTypeLA, FDT_LINEART); FrameSetTypeInfo(&outTypeLA, FDT_GRAYSCALE); if (!LineArtConvert.Init(inTypeLA, outTypeLA, npix)) { SetError(BEC_errMemory); goto Exit; } } /* write the image */ if ( !( lpLZW = CompressLZW_GIF (pTheFile, NULL, 0, codeSize, NULL ) ) ) goto BadWrite; compressInit = YES; for (y = rSave.top; y <= rSave.bottom; y++) { if (Progress (y-rSave.top, nlin, bEscapable )) goto Exit; if (lpObject) { if (!ObjGetLine( lpObject, rSave.left, y, npix, lpImgScanline)) goto BadRead; lp = lpImgScanline; } else { if ( !(lp = FramePointer(lpFrame, rSave.left, y, NO)) ) goto BadRead; } // convert the data to the new type TypeConvert.ConvertData(lp, lpBuffer, y, npix); if (outType.DataType == FDT_LINEART) { /* convert back to depth one, but with pixel values of 0 and 1 */ LineArtConvert.ConvertData(lpBuffer, lpImgScanline, y, npix); for (lp = lpImgScanline, j = 0; j < npix; j++, lp++) *lp = (*lp) ? 0 : 1; lp = lpImgScanline; } else lp = lpBuffer; /* compress the data */ if (!(CompressLZW_GIF (pTheFile, lp, npix, codeSize, lpLZW))) goto BadWrite; } if ( compressInit ) CompressLZW_GIF (pTheFile, NULL, 0, codeSize, lpLZW); cTerm = 0; pTheFile->Write((LPTR)&cTerm, 1); cTerm = GIFTerm; pTheFile->Write((LPTR)&cTerm, 1); fRet = TRUE; goto Exit; } CATCH_ALL(e) { goto BadWrite; } END_CATCH_ALL BadWrite: SetError(BEC_errWriteFile); goto Exit; BadRead: SetError(BEC_errFrameRead); Exit: /* clean up */ CloseFile(pTheFile, fRet); compressInit = NO; if (lpBuffer) FreeUp (lpBuffer); if (lpImgScanline) FreeUp ( lpImgScanline ); if (outType.ColorMap && (outType.ColorMap != inType.ColorMap)) FrameDestroyColorMap(outType.ColorMap); ProgressEnd(); return (fRet); }
void InitPoints() { int i; LPFRAME lpFrame; int Width; int Height; int x,y; LPTR lpSrcLine; BYTE r, g, b; iActiveDot = 0; iNumDots = 0; // Clear out the array for (i=0; i<MAX_DOTS; i++) { DotPoints[i].x = 0; DotPoints[i].y = 0; } if (!lpImage) return; lpFrame = ImgGetBaseEditFrame(lpImage); if (!lpFrame) return; Width = FrameXSize (lpFrame); Height = FrameYSize (lpFrame); // Find all the points in the image. // Search for coded dots that indicate a dot-to-dot point. // These dot points will be drawn as circles for the user to click in. // An array of points - DotPoints[] is maintained to remember these dots. for (y=0;y<Height;y++) { AstralClockCursor( y, Height, NO ); lpSrcLine = FramePointer (lpFrame,0,y,FALSE); for (x=0;x<Width;x++) { RGBS Pixel; FrameGetRGB (lpFrame,lpSrcLine,&Pixel,1); r = Pixel.red; g = Pixel.green; b = Pixel.blue; if (r >= 100 && g == 0 && b == 0) { // This is a coded pixel that contains: // 1) green - No coding. MUST be 0. // 2) red - Sequence that the dot is found. // 3) blue - No coding. MUST be 0. r -= 100; if (r >= 0 && r <= MAX_DOTS) { // Save the Dot position. // Do not allow the dot to go off the screen. DotPoints[r].x = min(x, Width - ((DOT_DIAMETER / 2) + 2)); DotPoints[r].y = min(y, Height - ((DOT_DIAMETER / 2) + 2)); iNumDots = max(iNumDots, r); } } lpSrcLine += 3; } // Width } // Height }
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 ); }
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; } } } }
void ImgEditUndo( LPIMAGE lpImage, BOOL fEditUndo, BOOL fMaskUndo ) /***********************************************************************/ { RECT rUndo, rUndoMask, rTemp; LPOBJECT lpBase, lpObject, lpNext; BOOL fNewSize, fSetupMiniViews, fRemoveMarquee, fUndoDelete; BOOL fUndoAlpha, fUndoData; int nDeleted; LPMASK lpMask; if (!lpImage) return; // Initialize things for updating the display fNewSize = fSetupMiniViews = fUndoDelete = NO; AstralSetRectEmpty(&rUndo); AstralSetRectEmpty(&rUndoMask); // loop through objects doing undo lpBase = ImgGetBase(lpImage); lpObject = NULL; while (lpObject = ImgGetNextObjectEx(lpImage, lpObject, NO, NO, fEditUndo)) { // See if this is an object we are undoing if (fEditUndo) { // check for special undo processing of a deleted object if (lpObject->fDeleted) { if (Control.UndoObjects && !ImgIsSelectedObject(lpImage, lpBase)) continue; } else if (Control.UndoObjects && !ImgIsSelectedObject(lpImage, lpObject)) continue; } // Only handle mask undo for the base object if (fMaskUndo) { if (lpObject != lpBase || lpObject->fBothDirty || !lpObject->AlphaDirty) continue; } fUndoData = fUndoAlpha = NO; // Do preprocess for doing a data undo if (fEditUndo) { if (lpObject->DataDirty) fUndoData = YES; // See if we need to undo the alpha for this object if ((lpObject != lpBase) && lpObject->lpAlpha && lpObject->AlphaDirty) fUndoAlpha = YES; if (!fUndoData && !fUndoAlpha) continue; // check to see and undoing/redoing deleted objects will change // the select state, if so undraw the object marquee if (lpObject == lpBase && lpObject->DataUndoType & UT_DELETEOBJECTS) { fUndoDelete = YES; fRemoveMarquee = NO; nDeleted = 0; lpNext = lpObject; while (lpNext = ImgGetNextObjectEx(lpImage, lpNext, YES, NO, YES)) { if (lpNext->fUndoDeleted) ++nDeleted; else if (lpNext->fDeleted && lpNext->fSelected) { fRemoveMarquee = YES; break; } } if (ImgGetSelObject(lpImage, NULL) == lpBase && !fRemoveMarquee) { if (ImgCountObjects(lpImage) - nDeleted <= 1) fRemoveMarquee = YES; } if (fRemoveMarquee) RemoveObjectMarqueeEx(lpImage, NO); } } else // fMaskUndo if (!lpObject->AlphaDirty) continue; else fUndoAlpha = YES; // do a preprocess for undoing the mask caused either by // a mask undo or by an edit function that also edits the mask if (((lpObject == lpBase) && fEditUndo && lpObject->fBothDirty) || fMaskUndo) { if ( lpObject->AlphaUndoType & (UT_CREATEMASK|UT_DELETEMASK) ) { // if the undo is going to delete the mask, // we need to undraw the mask if (ImgGetMask(lpImage)) { RemoveMaskMarquee(lpImage); if (ImgGetMaskUpdateRect(lpImage, YES, NO, &rTemp)) AstralUnionRect(&rUndoMask, &rUndoMask, &rTemp); } // if the undo is going to create the mask, // we need to undraw the object marquees if // not in mask and object marquee mode else { if (!Control.UseMaskAndObjects) RemoveObjectMarqueeEx(lpImage, NO); } } } // Actually do the undo ObjEditUndo(lpImage, lpObject, fUndoData, fUndoAlpha); // do a postprocess for undoing the mask if ((lpMask = ImgGetMask(lpImage)) && (((lpObject == lpBase) && fEditUndo && lpObject->fBothDirty) || fMaskUndo)) { // if the undo is going to add the mask, we need to redraw the mask if (lpObject->AlphaUndoType & (UT_CREATEMASK|UT_DELETEMASK) ) { if (ImgGetMaskUpdateRect(lpImage, YES, NO, &rTemp)) AstralUnionRect(&rUndoMask, &rUndoMask, &rTemp); } else // just redraw the undo area for the mask AstralUnionRect(&rUndoMask, &rUndoMask, &lpMask->Pixmap.UndoRect); } // Setup rectangle for undoing deletion of objects // Handled specially so that moved objects will still undo // and redo properly if (fEditUndo) { if (lpObject == lpBase && lpObject->DataUndoType & UT_DELETEOBJECTS) { lpNext = lpObject; while (lpNext = ImgGetNextObjectEx(lpImage, lpNext, YES, NO, YES)) { if (lpNext->fDeleted || lpNext->fUndoDeleted) AstralUnionRect(&rUndo, &rUndo, &lpNext->rObject); } fSetupMiniViews = YES; } if (lpObject->Pixmap.fNewFrame) { /* if new frame, cause window to be redisplayed */ if (lpObject == lpBase) fNewSize = YES; else { if (!fNewSize) { AstralUnionRect(&rUndo, &rUndo, &lpObject->rObject); AstralUnionRect(&rUndo, &rUndo, &lpObject->rUndoObject); } } } else { AstralSetRectEmpty(&rTemp); if (fUndoData) AstralUnionRect(&rTemp, &rTemp, &lpObject->Pixmap.UndoRect); if (fUndoAlpha) AstralUnionRect(&rTemp, &rTemp, &lpObject->lpAlpha->Pixmap.UndoRect); if (rTemp.right >= rTemp.left) { if (!fNewSize) { OffsetRect(&rTemp, lpObject->rObject.left, lpObject->rObject.top); AstralUnionRect(&rUndo, &rUndo, &rTemp); } } } } } // now redisplay whatever changes are necessary for the undo if (fNewSize) { SetupImagePalette(lpImage, NO, YES); if (lpBase->Pixmap.UndoFrame) { if ((FrameXSize(lpBase->Pixmap.UndoFrame) == FrameXSize(lpBase->Pixmap.EditFrame)) && (FrameYSize(lpBase->Pixmap.UndoFrame) == FrameYSize(lpBase->Pixmap.EditFrame))) fNewSize = NO; } if (fNewSize) UpdateImageSize(); else UpdateImageEx(lpImage, NULL, YES, YES, YES); if ( Tool.hRibbon ) SendMessage( Tool.hRibbon, WM_CONTROLENABLE, 0, 0L ); } else { if (rUndoMask.right >= rUndoMask.left) { File2DispRect(&rUndoMask, &rUndoMask); AstralToWindowsRect(&rUndoMask); InvalidateRect(lpImage->hWnd, NULL, NO); } if (rUndo.right >= rUndo.left) AnimateUndo( &rUndo ); } if (fUndoDelete) if ( Tool.hRibbon ) SendMessage( Tool.hRibbon, WM_CONTROLENABLE, 0, 0L ); if (fSetupMiniViews) SetupMiniViews(NULL, NO); }
LOCAL BOOL FullScreenView_OnInitDialog(HWND hDlg, HWND hWndFocus, LPARAM lParam) { CPPMDIChildWnd *pMDIChild; HWND hMDIWnd; RECT ClientRect; int npix, nlin, cx, cy, dx, dy; HWND hControl, hMDIChild, hView; LPOBJECT lpBase; LPFRAME lpFrame; // Make the window as big as the screen dx = GetSystemMetrics( SM_CXSCREEN ); dy = GetSystemMetrics( SM_CYSCREEN ); MoveWindow( hDlg, 0, 0, dx, dy, NO ); // Compute the center of the window GetClientRect( hDlg, &ClientRect ); cx = ( ClientRect.right + ClientRect.left ) / 2; cy = ( ClientRect.bottom + ClientRect.top ) / 2; // Link all of the images to image controls hControl = GetDlgItem( hDlg, IDC_VIEWFULL ); CServerView *pView = PictPubApp.GetActiveView(); BOOL bInplaceActive = (pView && pView->GetDocument()->IsInPlaceActive()); if (bInplaceActive) { hMDIChild = pView->GetParentFrame()->GetSafeHwnd(); hView = pView->GetSafeHwnd(); } else { pMDIChild = (CPPMDIChildWnd*)((CMDIFrame*)PictPubApp.m_pMainWnd)->MDIGetActive(); hMDIWnd = pMDIChild->GetSafeHwnd(); if (hMDIWnd) hView = pMDIChild->GetActiveView()->GetSafeHwnd(); else hView = NULL; } while ( hView ) { lpBase = ImgGetBase((LPIMAGE)GetImagePtr(hView)); if ( !lpBase || !hControl ) break; lpFrame = ObjGetEditFrame(lpBase); // Link the frame to the image control SetWindowLong( hControl, GWL_IMAGE, (long)lpBase ); // The destination size can be no bigger the the screen npix = FrameXSize(lpFrame); nlin = FrameYSize(lpFrame); if ( npix > dx || nlin > dy ) { npix = dx; nlin = dy; ScaleToFit( &npix, &nlin, FrameXSize(lpFrame), FrameYSize(lpFrame)); } // Position the control in the center of the window ClientRect.left = cx - npix/2; ClientRect.right = ClientRect.left + npix; ClientRect.top = cy - nlin/2; ClientRect.bottom = ClientRect.top + nlin; MoveWindow( hControl, ClientRect.left, ClientRect.top, // New position RectWidth( &ClientRect ), RectHeight( &ClientRect ), // New size NO /* No repaint*/ ); if (bInplaceActive) break; // Check to see if these get destroyed when the window does do { hView = NULL; if (hMDIWnd = GetWindow( hMDIWnd, GW_HWNDNEXT )) { if ((CWnd::FromHandle(hMDIWnd))-> IsKindOf(RUNTIME_CLASS(CPPMDIChildWnd))) hView = ((CPPMDIChildWnd*)CWnd::FromHandle(hMDIWnd))-> GetActiveView()->GetSafeHwnd(); } } while (hMDIWnd && !hView); if (!hView) break; // Get another image control hControl = CopyWindow( hControl ); } return TRUE; }
BOOL CWriteBitmap::TGAWrite() { TGAHDR PicHdr; int i, bpl, npix, nlin; LPTR lp, lpBuffer, lpImgScanline; RECT rSave; BOOL bEscapable; LPRGB lpRGBmap; RGBS rgb; BOOL fCompressed; LPFRAME lpFrame = NULL; LPOBJECT lpObject; FRMTYPEINFO inType, outType; CFrameTypeConvert TypeConvert; BOOL fRet = FALSE; CFile* pTheFile = NULL; LPMASK lpMask = NULL; LPTGAOPTIONS lpOptions = (LPTGAOPTIONS)m_lpOptions; ASSERT(lpOptions); if (!lpOptions) return(FALSE); if (m_lpObjList) { lpObject = m_lpObjList->lpHead; if (lpObject) { lpFrame = ObjGetEditFrame(lpObject); if (lpObject->lpAlpha && lpOptions->bSaveMask) lpMask = lpObject->lpAlpha; // if only one object don't do combines if (!lpObject->lpNext) lpObject = NULL; } } else { lpFrame = m_lpFrame; lpObject = NULL; } ASSERT(lpFrame); ProgressBegin(1); if ((pTheFile = OpenFile()) == NULL) { ProgressEnd(); return(FALSE); } TRY { if (m_fSrcArea) rSave = m_rSrcArea; else { rSave.top = rSave.left = 0; rSave.bottom = FrameYSize(lpFrame)-1; rSave.right = FrameXSize(lpFrame)-1; } inType = FrameTypeInfo(lpFrame); // cause FramePointer never returns line art if (inType.DataType == FDT_LINEART) inType.DataType = FDT_GRAYSCALE; // make sure colormap is inited for outType so we don't free bogus ptr FrameSetTypeInfo(&outType, FDT_NONE); npix = RectWidth(&rSave); nlin = RectHeight(&rSave); /* image compression does not currently work */ fCompressed = NO; /* initialize file header */ PicHdr.textSize = 0; /* no id field */ PicHdr.XOffset = 0; PicHdr.YOffset = 0; PicHdr.x = npix; PicHdr.y = nlin; PicHdr.imType = 0; /*************************************/ /* determine type of image to create */ /*************************************/ /* save line art and scatter as gray */ switch (m_DataType) { case FDT_LINEART: case FDT_GRAYSCALE: /* gray */ PicHdr.mapType = 1; PicHdr.mapOrig = 0; PicHdr.mapLength = 256; PicHdr.CMapBits = 24; PicHdr.dataType = (fCompressed) ? 9 : 1; PicHdr.dataBits = 8; bpl = npix; FrameSetTypeInfo(&outType, FDT_GRAYSCALE); lpMask = NULL; break; case FDT_PALETTECOLOR: /* mini color */ PicHdr.mapType = 1; PicHdr.mapOrig = 0; PicHdr.mapLength = 256; PicHdr.CMapBits = 24; PicHdr.dataType = (fCompressed) ? 9 : 1; PicHdr.dataBits = 8; bpl = npix; if (inType.DataType == FDT_PALETTECOLOR) outType = inType; else FrameSetTypeInfo(&outType, FDT_PALETTECOLOR); lpMask = NULL; break; case FDT_RGBCOLOR: case FDT_CMYKCOLOR: /* full color */ PicHdr.mapType = 0; /* no color map data */ PicHdr.mapOrig = 0; PicHdr.mapLength = 0; PicHdr.CMapBits = 0; PicHdr.dataType = 2; PicHdr.dataType = (fCompressed) ? 10 : 2; if (m_DataType == FDT_CMYKCOLOR) lpMask = NULL; if (lpMask || (m_DataType == FDT_CMYKCOLOR)) { PicHdr.dataBits = 32; bpl = npix * 4; } else { PicHdr.dataBits = 24; bpl = npix * 3; } FrameSetTypeInfo(&outType, m_DataType); break; default: //Print ("Unknown flag value"); goto BadRead; break; } AllocLines (&lpBuffer, 1, npix, 4); AllocLines (&lpImgScanline, 1, npix, 4 ); if ( !lpBuffer || !lpImgScanline ) { SetError (BEC_errMemory); goto Exit; } /* write file header */ pTheFile->Write(&PicHdr.textSize, 1); pTheFile->Write(&PicHdr.mapType, 1); pTheFile->Write(&PicHdr.dataType, 1); pTheFile->Write(&PicHdr.mapOrig, 2); pTheFile->Write(&PicHdr.mapLength, 2); pTheFile->Write(&PicHdr.CMapBits, 1); pTheFile->Write(&PicHdr.XOffset, 2); pTheFile->Write(&PicHdr.YOffset, 2); pTheFile->Write(&PicHdr.x, 2); pTheFile->Write(&PicHdr.y, 2); pTheFile->Write(&PicHdr.dataBits, 1); pTheFile->Write(&PicHdr.imType, 1); switch (outType.DataType) { case FDT_LINEART: case FDT_GRAYSCALE: /* gray */ /* write the color map */ for (i = 0; i < 256; i++) { rgb.red = rgb.green = rgb.blue = i; pTheFile->Write((LPTR) &rgb, 3); } break; case FDT_PALETTECOLOR: /* mini color */ // see if we need to create a palette if (!outType.ColorMap) { outType.ColorMap = FrameCreateColorMap(); if (!outType.ColorMap) { SetError(BEC_errMemory); goto Exit; } outType.ColorMap->NumEntries = 256; if (!CreateOptimizedPalette(lpObject, lpFrame, outType.ColorMap->RGBData, &outType.ColorMap->NumEntries, TRUE, NULL)) { SetError(BEC_errMemory); goto Exit; } } lpRGBmap = outType.ColorMap->RGBData; /* write the color map */ for (i = 0; i < 256; i++) { pTheFile->Write((LPTR) &lpRGBmap[i].blue, 1); pTheFile->Write((LPTR) &lpRGBmap[i].green, 1); pTheFile->Write((LPTR) &lpRGBmap[i].red, 1); } break; case FDT_RGBCOLOR: case FDT_CMYKCOLOR: /* full color */ break; } // initialize stuff to do the type conversion if (!TypeConvert.Init(inType, outType, npix, m_DitherType)) { SetError(BEC_errMemory); goto Exit; } /* write the image */ for (i = rSave.bottom; i >= rSave.top; i--) { if (Progress(rSave.bottom-i, nlin, bEscapable)) goto Exit; if (lpObject) { if (!ObjGetLine( lpObject, rSave.left, i, (rSave.right - rSave.left) + 1, lpImgScanline)) goto BadRead; lp = lpImgScanline; } else { if ( !(lp = FramePointer(lpFrame, rSave.left, i, NO)) ) goto BadRead; } // convert the data to the new type TypeConvert.ConvertData(lp, lpBuffer, i, npix); if (outType.DataType == FDT_RGBCOLOR) { swapBGR( lpBuffer, lpBuffer, npix ); if (lpMask) { MergeMaskData(lpMask, rSave.left, i, npix, 3, lpBuffer, lpImgScanline); lp = lpImgScanline; } else lp = lpBuffer; } else lp = lpBuffer; #ifdef UNUSED if ( fCompressed ) { if (tgaComp8Bit (ofh, lp, npix)) goto BadWrite; } else #endif // UNUSED { pTheFile->Write(lp, bpl); } } fRet = TRUE; goto Exit; } CATCH_ALL(e) { goto BadWrite; } END_CATCH_ALL BadWrite: SetError(BEC_errWriteFile); goto Exit; BadRead: SetError(BEC_errFrameRead); Exit: /* clean up */ CloseFile(pTheFile, fRet); if (lpBuffer) FreeUp (lpBuffer); if (lpImgScanline) FreeUp( lpImgScanline ); if (outType.ColorMap && (outType.ColorMap != inType.ColorMap)) FrameDestroyColorMap(outType.ColorMap); ProgressEnd(); return (fRet); }