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); } } }
STATUS_CODE ApplyColorMap(LPIMAGE lpImage, LPCOLORMAP lpColorMap, BOOL fReMap, DITHER_TYPE DitherType, ITEMID idDirty) /************************************************************************/ { UNDO_TYPE UndoType; int iMaxWidth; FRMTYPEINFO OldTypeInfo, NewTypeInfo; LPOBJECT lpObject; RECT rEdit; CFrameTypeConvert TypeConvert; UndoType = UT_COLORMAP; if (fReMap) UndoType |= UT_DATA; if (!ImgEditInit(lpImage, ET_ALLOBJECTS, UndoType, NULL)) return(SC_UNDOERROR); ProgressBegin(ImgCountObjects(lpImage), idDirty-IDS_UNDOFIRST+IDS_PROGFIRST); if (fReMap) { ImgGetTypeInfo(lpImage, &OldTypeInfo); FrameSetTypeInfo(&NewTypeInfo, FDT_PALETTECOLOR, lpColorMap); iMaxWidth = 0; lpObject = NULL; while (lpObject = ImgGetNextObject(lpImage, lpObject, YES, NO)) { if (RectWidth(&lpObject->rObject) > iMaxWidth) iMaxWidth = RectWidth(&lpObject->rObject); } if (!TypeConvert.Init(OldTypeInfo, NewTypeInfo, iMaxWidth, DitherType)) { ProgressEnd(); Message(IDS_EMEMALLOC); return(SC_MEMERROR); } } lpObject = NULL; while (lpObject = ImgGetNextObjectEx(lpImage, lpObject, YES, NO, YES)) { if (fReMap) PaletteMapPixmap(&lpObject->Pixmap, &TypeConvert); FrameSetColorMap(ObjGetEditFrame(lpObject), lpColorMap); rEdit = lpObject->rObject; ImgEditedObject(lpImage, lpObject, idDirty, &rEdit); } ImgColorMapChanged(lpImage); ProgressEnd(); return(SC_SUCCESS); }
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); }
void CChromaMask::MaskAddChroma(LPIMAGE lpImage, LPMASK lpMask, LPRECT lpRect, BOOL MaskExist) { int dx, dy, i, depth; LPTR lpAlphaLine; LPTR lpLine; LPOBJECT lpBase = ImgGetBase(lpImage); int top = -1; int bottom = 0; FRMTYPEINFO TypeInfo; ProgressBegin(1,PROGRESS_ID(IDS_CHROMA_APPLY)); PixmapGetInfo(&lpMask->Pixmap, PMT_EDIT, &dx, &dy, NULL, NULL); ImgGetTypeInfo(lpImage, &TypeInfo); if (!(depth = FrameDepth(ObjGetEditFrame(lpBase)))) depth = 1; // never worry about lineart xExtL = 10000; xExtR = 0; lpLine = Alloc((long)dx*depth); for (i = 0; i < dy; ++i) { AstralClockCursor(i, dy, NO); Dirty = FALSE; lpAlphaLine = PixmapPtr( &lpMask->Pixmap, PMT_EDIT, 0, i, YES); if (Delete) clr(lpAlphaLine, dx); ImgGetLine(lpImage, lpBase, 0, i, dx, lpLine, NULL); ChromaProc(dx, TypeInfo, lpLine, lpAlphaLine, MaskExist); if (Dirty) { if (top == -1) top = i; if (i > bottom) bottom = i; } } lpRect->left = xExtL; lpRect->right = xExtR; lpRect->top = top; lpRect->bottom = bottom; FreeUp(lpLine); ProgressEnd(); }
void ImgInitDisplay(LPIMAGE lpImage, BOOL fGeneratePaletteLUT) /***********************************************************************/ { LPTR lpPaletteLUT; RGBS RGBmap[256]; LPRGB lpRGBmap; int nColors; FRMTYPEINFO TypeInfo, DstTypeInfo = ColorManager.Monitor.dst; LPOBJECT lpObject; lpObject = lpImage->GetDisplayObject(); if (!lpObject) return; FrameGetTypeInfo(ObjGetEditFrame(lpObject), &TypeInfo); if ( lpBltScreen->BitMapInfo.bmiHeader.biBitCount == 8 && !lpImage->lpPaletteLUT) { ProgressBegin(1, PROGRESS_ID(IDS_UNDOSETUPDISPLAY)); if (TypeInfo.DataType == FDT_PALETTECOLOR) lpPaletteLUT = Alloc(32768L); else lpPaletteLUT = NULL; if (lpPaletteLUT) { if (TypeInfo.ColorMap->NumEntries > MAX8BITCOLORS) { nColors = MAX8BITCOLORS; lpRGBmap = RGBmap; if (!ReducePalette(TypeInfo.ColorMap->RGBData, TypeInfo.ColorMap->NumEntries, lpRGBmap, nColors)) { FreeUp(lpPaletteLUT); lpPaletteLUT = NULL; } } else { lpRGBmap = TypeInfo.ColorMap->RGBData; nColors = TypeInfo.ColorMap->NumEntries; } } if (lpPaletteLUT) { if (fGeneratePaletteLUT) CreatePaletteLut15(lpRGBmap, nColors, lpPaletteLUT, AstralClockCursor); lpImage->lpPaletteLUT = lpPaletteLUT; lpImage->PaletteType = PT_CUSTOMPALETTE; lpImage->hPal = CreateLogicalPalette(lpRGBmap, nColors); GetObject(lpImage->hPal, sizeof(nColors), (void *)&nColors); lpImage->nPaletteEntries = GetPaletteEntries(lpImage->hPal, 0, nColors, lpImage->Palette); } else { if ( FrameType(ImgGetBaseEditFrame(lpImage)) <= FDT_GRAYSCALE) { lpImage->hPal = lpBltScreen->hGrayPal; lpImage->nPaletteEntries = lpBltScreen->nGrayEntries; lpImage->PaletteType = lpBltScreen->GrayPaletteType; lpImage->lpPaletteLUT = lpBltScreen->lpGrayPaletteLUT; copy((LPTR)lpBltScreen->GrayPalette, (LPTR)lpImage->Palette, sizeof(lpImage->Palette)); } else { lpImage->hPal = lpBltScreen->hColorPal; lpImage->nPaletteEntries = lpBltScreen->nColorEntries; lpImage->PaletteType = lpBltScreen->ColorPaletteType; lpImage->lpPaletteLUT = lpBltScreen->lpColorPaletteLUT; copy((LPTR)lpBltScreen->ColorPalette, (LPTR)lpImage->Palette, sizeof(lpImage->Palette)); } } ProgressEnd(); } if (lpImage->m_cmsXform) { if( Control.CMSEnabled && lpKCMSFreeProc ) { if (lpImage->PtInfo.toRCS != TypeInfo.ptInfo.toRCS && lpImage->PtInfo.frRCS != TypeInfo.ptInfo.frRCS ) { ( lpKCMSFreeProc )( lpImage->m_cmsXform ); lpImage->m_cmsXform = NULL; } } else lpImage->m_cmsXform = NULL; } if( Control.CMSEnabled && IsSrcPTSelected( &TypeInfo.ptInfo ) && IsDstPTSelected( &DstTypeInfo.ptInfo ) && lpKCMSCnctProc ) { lpImage->m_bDoCmsGamma = YES; if (!lpImage->m_cmsXform) { if( ( !FrameTypeInfoEqual( TypeInfo, DstTypeInfo ) ) && ConvertCRCtoUID( &TypeInfo, &DstTypeInfo ) ) { // save for later check to avoid a monitor reconnect. lpImage->PtInfo = TypeInfo.ptInfo; lpImage->m_cmsXform = ( *lpKCMSCnctProc )( &TypeInfo, &DstTypeInfo ); } else lpImage->m_cmsXform = NULL; } } else lpImage->m_cmsXform = NULL; }
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; }
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; } } } }
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); }
BOOL ObjGetLine(LPOBJECT lpObject, int x, int y, int dx, LPTR lpOut) /************************************************************************/ { LPALPHA lpAlpha; LPTR lp; LPPROCESSPROC lpProcessProc; RECT rLine, rSect; int nPixels, ox, oy, depth; FRMTYPEINFO TypeInfo; FRMDATATYPE DataType; long lOffset; LPFRAME lpFrame; // fill buffer with base image object // use depth of base image object lpFrame = ObjGetEditFrame(lpObject); FrameGetTypeInfo(lpFrame, &TypeInfo); DataType = TypeInfo.DataType; depth = FrameDepth(lpFrame); if (TypeInfo.DataType == FDT_LINEART) { depth = 1; TypeInfo.DataType = FDT_GRAYSCALE; } if (!ObjGetLineAlloc(dx, depth)) { //Message(IDS_EMEMALLOC); return(FALSE); } if (!FrameRead(lpFrame, x, y, dx, lpOut, dx)) return(FALSE); // setup rect for this line for intersect check rLine.left = x; rLine.right = x + dx - 1; rLine.top = rLine.bottom = y; // start with first object on top of base image while(lpObject = lpObject->lpNext) { // if object cannot be rendered through raster means if (lpObject->fDeleted || !AstralIntersectRect(&rSect, &lpObject->rObject, &rLine)) continue; // get merge proc for this object lpProcessProc = GetProcessProc(lpObject->MergeMode, DataType); ox = rSect.left-lpObject->rObject.left; oy = y-lpObject->rObject.top; nPixels = (rSect.right - rSect.left + 1); lOffset = (long)(rSect.left - rLine.left) * depth; lp = FramePointer(ObjGetEditFrame(lpObject), ox, oy, NO, nPixels); if (lp) { if (lpAlpha = ObjGetAlpha(lpObject)) { MaskLoad(lpAlpha, ox, oy, nPixels, lpGLMaskBuf); if (lpObject->Opacity != 255) ScaleData8(lpGLMaskBuf, nPixels, lpObject->Opacity); } else set(lpGLMaskBuf, nPixels, lpObject->Opacity); (*lpProcessProc)(lpOut+lOffset, lp, lpGLMaskBuf, nPixels); } } return(TRUE); }
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); }
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 ); }
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; } } } }
BOOL ConvertImage(LPIMAGE lpImage, LPCONVERT_PARMS lpParms) /***********************************************************************/ { BOOL fRet = FALSE; LPFRAME lpDstFrame, lpBaseFrame; LPOBJECT lpBase, lpObject; BOOL fError, fOptimize, fProgressSet; INTERNAL_DATA data; int inDepth, iMaxWidth, nColors, i; LPCOLORMAP lpColorMap; LPRGB lpRGB; FRMTYPEINFO InTypeInfo, OutTypeInfo; CFrameTypeConvert TypeConvert; DITHER_TYPE DitherType = DT_DEFAULT; if (ImgInMaskEditMode(lpImage)) return(TRUE); lpColorMap = NULL; lpBase = ImgGetBase(lpImage); lpBaseFrame = ObjGetEditFrame(lpBase); inDepth = FrameDepth(lpBaseFrame); OutTypeInfo = lpParms->cmsInfo.dst; FrameGetTypeInfo(lpBaseFrame, &InTypeInfo); // are we try to convert to a color managed image? if (Control.CMSEnabled && IsDstPTSelected(&OutTypeInfo.ptInfo)) { // see if our image already has a color managed source if (!IsSrcPTSelected(&InTypeInfo.ptInfo)) { // nope, see if the source passed in is valid for this image if (IsSrcPTSelected(&lpParms->cmsInfo.src.ptInfo) && (lpParms->cmsInfo.src.DataType == InTypeInfo.DataType)) { InTypeInfo = lpParms->cmsInfo.src; } // go get a source from the user else { CMSINFO CmsInfo2; if( CmsGetSrcPTType( &InTypeInfo, &CmsInfo2) ) InTypeInfo = CmsInfo2.src; } } } else FrameSetTypeInfo(&InTypeInfo, InTypeInfo.DataType, InTypeInfo.ColorMap); // no conversion necessary if (FrameTypeInfoEqual(InTypeInfo, OutTypeInfo)) return(TRUE); DitherType = lpParms->DitherType; fOptimize = lpParms->ConvertType == CT_OPTIMIZED; fProgressSet = FALSE; if ( OutTypeInfo.DataType == FDT_PALETTECOLOR/* && inDepth >= 3 */) { if (lpParms->ConvertType == CT_CUSTOM) { FNAME szFileName; if ( !LookupExtFileN( lpParms->szPalette, szFileName, IDN_PALETTE, NO ) ) return(FALSE); if (!(lpColorMap = Palette_ReadColorMap(szFileName))) return(FALSE); } else { // allocate a map to carry around with image lpColorMap = FrameCreateColorMap(); if (!lpColorMap) { Message(IDS_EMEMALLOC); goto MemError; } lpColorMap->NumEntries = lpParms->iLevels; if (InTypeInfo.DataType == FDT_GRAYSCALE && lpColorMap->NumEntries == 256 && fOptimize) { DitherType = DT_NONE; lpRGB = lpColorMap->RGBData; for (i = 0; i < lpColorMap->NumEntries; ++i) { lpRGB->red = lpRGB->green = lpRGB->blue = i; ++lpRGB; } } else { // 1. CreateOptimizedPalette phase - only if fOptimize // 2. Mapping phase ProgressBegin(fOptimize ? 2 : 1, lpParms->Common.idDirty-IDS_UNDOFIRST+IDS_PROGFIRST); fProgressSet = TRUE; if (fOptimize) ProgressBegin(1, 0); if (!CreateOptimizedPalette(lpBase, ObjGetEditFrame(lpBase), lpColorMap->RGBData, &lpColorMap->NumEntries, fOptimize, fOptimize ? AstralClockCursor : NULL)) { if (fOptimize) ProgressEnd(); Message(IDS_EMEMALLOC); goto ExitFalse; } if (fOptimize) ProgressEnd(); } } if (lpColorMap->NumEntries <= 16) lpColorMap->NumEntries = 16; else lpColorMap->NumEntries = 256; FrameSetTypeInfo(&OutTypeInfo, FDT_PALETTECOLOR, lpColorMap); } if (!fProgressSet) ProgressBegin(1, lpParms->Common.idDirty-IDS_UNDOFIRST+IDS_PROGFIRST); fProgressSet = TRUE; iMaxWidth = 0; lpObject = NULL; while (lpObject = ImgGetNextObject(lpImage, lpObject, YES, NO)) { if (RectWidth(&lpObject->rObject) > iMaxWidth) iMaxWidth = RectWidth(&lpObject->rObject); } if (!TypeConvert.Init(InTypeInfo, OutTypeInfo, iMaxWidth, DitherType)) { Message(IDS_EMEMALLOC); goto ExitFalse; } if (ImgMultipleObjects(lpImage)) { ProgressBegin(ImgCountObjects(lpImage), 0); if ( !ImgEditInit(lpImage, ET_ALLOBJECTS, UT_NEWDATA|UT_COLORMAP, lpBase) ) goto ExitFalse; fError = NO; lpObject = NULL; while (lpObject = ImgGetNextObject(lpImage, lpObject, YES, NO)) { lpDstFrame = ConvertFrame(ObjGetEditFrame(lpObject), OutTypeInfo, &TypeConvert); if (!lpDstFrame) { fError = YES; break; } ImgEditedObjectFrame( lpImage, lpObject, lpParms->Common.idDirty, NULL, lpDstFrame, NULL); } if (fError) { lpObject = NULL; while (lpObject = ImgGetNextObject(lpImage, lpObject, YES, NO)) { if (lpObject->Pixmap.UndoFrame) { lpDstFrame = lpObject->Pixmap.EditFrame; lpObject->Pixmap.EditFrame = lpObject->Pixmap.UndoFrame; lpObject->Pixmap.UndoFrame = NULL; FrameClose(lpDstFrame); } } } ProgressEnd(); } else { if ( !ImgEditInit(lpImage, ET_OBJECT, UT_NEWDATA|UT_COLORMAP, lpBase) ) goto ExitFalse; ProgressBegin(1, 0); lpDstFrame = ConvertFrame(lpBaseFrame, OutTypeInfo, &TypeConvert); ProgressEnd(); if (!lpDstFrame) goto ExitFalse; /* Setup the new image and bring up the new image window */ ImgEditedObjectFrame( lpImage, lpBase, lpParms->Common.idDirty, NULL, lpDstFrame, NULL); } switch (lpParms->cmsInfo.dst.DataType) { case FDT_LINEART: lpImage->DataType = IDC_SAVELA; break; case FDT_GRAYSCALE: lpImage->DataType = IDC_SAVECT; break; case FDT_PALETTECOLOR: lpImage->DataType = IDC_SAVE8BITCOLOR; break; case FDT_RGBCOLOR: lpImage->DataType = IDC_SAVE24BITCOLOR; break; case FDT_CMYKCOLOR: lpImage->DataType = IDC_SAVE32BITCOLOR; break; } ImgColorMapChanged(lpImage); lpParms->Common.UpdateType = UT_DATATYPE; fRet = TRUE; ExitFalse: if (fProgressSet) ProgressEnd(); MemError: if (lpColorMap) FrameDestroyColorMap(lpColorMap); return(fRet); }
LPFRAME CImage::GetBaseEditFrame() { return(ObjGetEditFrame(GetBase())); }
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 ); }
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); }