BOOL InvertImage(LPIMAGE lpImage, LPCMD_PARMS lpParms) { ENGINE Engine; FRMTYPEINFO TypeInfo; LPCOLORMAP lpColorMap; ImgGetTypeInfo(lpImage, &TypeInfo); if (TypeInfo.DataType == FDT_PALETTECOLOR) { lpColorMap = FrameCopyColorMap(TypeInfo.ColorMap); if (!lpColorMap) { Message(IDS_EMEMALLOC); lpParms->Common.StatusCode = SC_MEMERROR; return(FALSE); } negate((LPTR)lpColorMap->RGBData, sizeof(RGBS)*lpColorMap->NumEntries); lpParms->Common.StatusCode = ApplyColorMap(lpImage, lpColorMap, FALSE, DT_NONE, lpParms->Common.idDirty); FrameDestroyColorMap(lpColorMap); if (lpParms->Common.StatusCode == SC_SUCCESS) lpParms->Common.UpdateType = UT_DATATYPE; } else { SetEngineDef(&Engine); Engine.lpDataProc = invert_proc; lpParms->Common.StatusCode = LineEngineSelObj(lpImage,&Engine,lpParms->Common.idDirty); if (!AstralIsRectEmpty(&Engine.rUpdate)) { lpParms->Common.UpdateType = UT_AREA; lpParms->Common.rUpdateArea = Engine.rUpdate; } } return(lpParms->Common.StatusCode == SC_SUCCESS); }
void ObjFreeUp(LPOBJECT lpObject) /************************************************************************/ { if (!lpObject) return; if ( lpObject->ObjectType == OT_FRAME ) { PixmapFree(&lpObject->Pixmap); if (lpObject->lpAlpha) MaskClose(lpObject->lpAlpha); if (lpObject->lpUndoAlpha) MaskClose(lpObject->lpUndoAlpha); if (lpObject->UndoColorMap) FrameDestroyColorMap(lpObject->UndoColorMap); } if (lpObject->lpText) delete lpObject->lpText; if (lpObject->lpUndoText) delete lpObject->lpUndoText; FreeUp((LPTR)lpObject); }
LOCAL STATUS_CODE ApplyMaps(LPIMAGE lpImage, LPMAPS lpMaps, ITEMID idDirty, LPRECT lpUpdateRect, LPUPDATE_TYPE lpUpdateType) /************************************************************************/ { ENGINE Engine; FRMTYPEINFO TypeInfo; LPCOLORMAP lpColorMap; STATUS_CODE StatusCode; AstralSetRectEmpty(lpUpdateRect); *lpUpdateType = UT_NONE; ImgGetTypeInfo(lpImage, &TypeInfo); if (TypeInfo.DataType == FDT_PALETTECOLOR) { lpColorMap = FrameCopyColorMap(TypeInfo.ColorMap); if (!lpColorMap) { Message(IDS_EMEMALLOC); return(SC_MEMERROR); } ApplyMaps24((LPTR)lpColorMap->RGBData, lpColorMap->NumEntries, lpMaps); StatusCode = ApplyColorMap(lpImage, lpColorMap, FALSE, DT_NONE, idDirty); FrameDestroyColorMap(lpColorMap); if (StatusCode == SC_SUCCESS) *lpUpdateType = UT_DATATYPE; } else { SetEngineDef(&Engine); Engine.lpDataProc = (LPDATAPROC)ApplyMapsProc; Engine.lpParam = lpMaps; StatusCode = LineEngineSelObj(lpImage, &Engine, idDirty); if (!AstralIsRectEmpty(&Engine.rUpdate)) { *lpUpdateRect = Engine.rUpdate; *lpUpdateType = UT_AREA; } } return(StatusCode); }
void CImage::ObjEditApply(LPOBJECT lpObject, BOOL fApplyData, BOOL fApplyAlpha, BOOL fInitFrame) { LPALPHA lpAlpha; LPOBJECT lpNext; BOOL fInitingData, fInitingAlpha; if (!fApplyData && !fApplyAlpha) return; lpObject->InitUndoType = 0; fInitingAlpha = fInitFrame && fApplyAlpha; fInitingData = fInitFrame && fApplyData; lpAlpha = lpObject->lpAlpha; if (fApplyData) { if (lpObject->fBothDirty) fApplyAlpha = YES; if (lpObject == GetBase()) { PurgeObjects(); lpNext = lpObject; while (lpNext = GetNextObject(lpNext, YES, NO, NO)) lpNext->fUndoDeleted = NO; } if (!fInitingData) PixmapFreeUndo(&lpObject->Pixmap); else PixmapEditApply(&lpObject->Pixmap); if (lpObject->lpUndoText) { delete lpObject->lpUndoText; lpObject->lpUndoText = NULL; } if (lpObject->UndoColorMap) { FrameDestroyColorMap(lpObject->UndoColorMap); lpObject->UndoColorMap = NULL; } lpObject->DataUndoType = 0; lpObject->DataDirty = NO; } if (fApplyAlpha) { if (lpObject->lpUndoAlpha) { MaskClose(lpObject->lpUndoAlpha); lpObject->lpUndoAlpha = NULL; } if (lpAlpha) { if (!fInitingAlpha) PixmapFreeUndo(&lpAlpha->Pixmap); else PixmapEditApply(&lpAlpha->Pixmap); } lpObject->AlphaUndoType = 0; lpObject->AlphaDirty = NO; } lpObject->fBothDirty = NO; }
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 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 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); }
LOCAL void Convert_OnCommand(HWND hDlg, int id, HWND hControl, UINT codeNotify) /************************************************************************/ { BOOL Bool; switch (id) { case IDC_MINITYPES: // case IDC_MINI256: // case IDC_MINI16: // case IDC_MINI8: // case IDC_MINICUSTOM: if ( !(id = HandleCombo( hDlg, id, codeNotify )) ) break; Convert.MiniType = id; if (Convert.MiniType == IDC_MINI256) Convert.ConvertColors = 256; else if (Convert.MiniType == IDC_MINI16) Convert.ConvertColors = 16; else if (Convert.MiniType == IDC_MINI8) Convert.ConvertColors = 8; Convert_Enable(hDlg); break; case IDC_DITHERTYPES: // case IDC_DITHERPATTERN: // case IDC_DITHERSCATTERED: // case IDC_DITHERNONE: if ( !(id = HandleCombo( hDlg, id, codeNotify )) ) break; if ( id == IDC_DITHERPATTERN ) { Convert.fDither = YES; Convert.fScatter = NO; Convert.ConvertDitherType = DT_PATTERN; } else if ( id == IDC_DITHERSCATTERED ) { Convert.fDither = NO; Convert.fScatter = YES; Convert.ConvertDitherType = DT_SCATTER; } else { Convert.fDither = NO; Convert.fScatter = NO; Convert.ConvertDitherType = DT_NONE; } break; case IDC_PALETTETYPES: // case IDC_PALETTEOPTIMIZED: // case IDC_PALETTESTANDARD: // case IDC_PALETTECUSTOM: if ( !(id = HandleCombo( hDlg, id, codeNotify )) ) break; if (id == IDC_PALETTEOPTIMIZED) Convert.ConvertType = CT_OPTIMIZED; else if (id == IDC_PALETTESTANDARD) Convert.ConvertType = CT_STANDARD; else Convert.ConvertType = CT_CUSTOM; Convert.fOptimize = ( id == IDC_PALETTEOPTIMIZED ); Convert_Enable(hDlg); break; case IDC_PALETTECOLORS: if ( GetFocus() != GetDlgItem( hDlg, id ) ) break; if ( codeNotify != EN_CHANGE ) break; Convert.ConvertColors = GetDlgItemSpin( hDlg, id, &Bool, NO ); break; case IDC_EXTNAMES: GetExtName( hDlg, IDC_EXTNAMES, IDC_FILENAME, Convert.ConvertPalette, IDN_PALETTE, codeNotify ); break; case IDC_EXTMANAGE: PopupMenu( hDlg, id, IDC_FILENAME ); break; case IDC_ADDEXT: case IDC_DELETEEXT: case IDC_RENAMEEXT: ExtNameManager( hDlg, IDC_EXTNAMES, IDC_FILENAME, Convert.ConvertPalette, IDN_PALETTE, id, NO ); break; case IDOK: // make sure we can open a colormap if (Convert.ConvertType == CT_CUSTOM) { FNAME szFileName; LPCOLORMAP lpColorMap; if ( !LookupExtFile( Convert.ConvertPalette, szFileName, IDN_PALETTE ) ) break; if (!(lpColorMap = Palette_ReadColorMap(szFileName))) break; FrameDestroyColorMap(lpColorMap); } AstralDlgEnd( hDlg, TRUE ); break; case IDCANCEL: AstralDlgEnd( hDlg, FALSE ); break; default: break; } }
BOOL CReadBitmap::GIFRead() /************************************************************************/ { GIFHDR hdr; GIFDESC ImDesc; GIFMAP GlobalMap; GIFMAP LocalMap; BYTE cTemp; LPTR lpFileLine, lpLineBuffer, lpOut; LPFRAME lpFrame; FILEBUF ifd; /* file descriptor (buffered) */ BOOL graymap; int i; int sy; int xres; /* pixels per inch */ int npix; /* image width (pixels) */ int nlin; /* image height (pixels) */ BYTE codeSize; int iCodeSize; int iRowMapIndex; BOOL compressInit; LPLZW_STUFF lpLZW; FRMTYPEINFO inType, outType; LPCOLORMAP lpColorMap; CFrameTypeConvert TypeConvert; CFile theFile; CFile* pTheFile; BOOL fRet = FALSE; ProgressBegin(1); if ((pTheFile = OpenFile()) == NULL) { ProgressEnd(); return(FALSE); } TRY { lpFileLine = NULL; lpFrame = NULL; lpLineBuffer = NULL; compressInit = NO; lpColorMap = NULL; if (!(lpLineBuffer = Alloc (BUF_SIZE))) goto Exit; FileFDOpenRdr (&ifd, pTheFile, lpLineBuffer, BUF_SIZE); /* initialize the Global and local color maps */ gifInitColorMap (&GlobalMap); gifInitColorMap (&LocalMap); /* read gif file header */ if (gifReadHeader (&ifd, &hdr)) goto BadRead; /* get global color map, if any */ if (hdr.GlobalMap) { if (gifReadColorMap (&ifd, hdr.bpp, &GlobalMap)) goto BadRead; } /* look for start of image */ while (1) { FileFDRead (&ifd, (LPTR) &cTemp, 1); if (ifd.err) goto BadRead; /* test for image separator character */ if (cTemp == GIFImSep) break; /* test for terminator character (no image blocks in file?) */ if (cTemp == GIFImSep) goto BadRead; /* test for extension block character */ if (cTemp == GIFExtBlk) { /* Skip over the extension block */ /* read function code */ FileFDRead (&ifd, (LPTR) &cTemp, 1); do { /* read byte count */ FileFDRead (&ifd, (LPTR) &cTemp, 1); /* skip data bytes */ if (cTemp) FileFDSeek (&ifd, (long) cTemp, 1); } while (cTemp); } } /* now at the start of the first image */ if (gifReadImDesc (&ifd, &ImDesc)) goto BadRead; /* read local color map, if any */ if (ImDesc.LocalMap) { if (gifReadColorMap (&ifd, ImDesc.bpp, &LocalMap)) goto BadRead; } else { LocalMap = GlobalMap; ImDesc.bpp = hdr.bpp; } /* check for gray map */ graymap = TRUE; for (i = 0; (i < LocalMap.Length) && graymap; i++) graymap = (LocalMap.Map[i].red == LocalMap.Map[i].green) && (LocalMap.Map[i].red == LocalMap.Map[i].blue); lpColorMap = FrameCreateColorMap(); if (!lpColorMap) { SetError(BEC_errMemory); goto Exit; } lpColorMap->NumEntries = LocalMap.Length; for (i = 0; i < LocalMap.Length; ++i) lpColorMap->RGBData[i] = LocalMap.Map[i]; /* get width of image in pixels */ npix = ImDesc.ImWidth; nlin = ImDesc.ImHeight; xres = 75; if (hdr.bpp == 1) FrameSetTypeInfo(&inType, FDT_LINEART); else FrameSetTypeInfo(&inType, FDT_PALETTECOLOR, lpColorMap); if (!SetupTypes(&inType, &outType, graymap)) goto Exit; FrameSetTypeInfo(&inType, FDT_PALETTECOLOR, lpColorMap); if (!TypeConvert.Init(inType, outType, npix, m_DitherType)) { SetError(BEC_errMemory); goto Exit; } /* allocate space for one line of the image (file) */ if ( !AllocLines (&lpFileLine, 1, npix, 1)) { SetError(BEC_errMemory); goto BadWrite; } /* Create the image frame store */ lpFrame = FrameOpen(outType, npix, nlin, xres); if ( !lpFrame ) { SetError(BEC_errFrameOpen); goto Exit; } /* convert the image */ if (FileFDRead (&ifd, &codeSize, 1) == -1) goto BadRead; iCodeSize = codeSize; if (FileFDSeek (&ifd, 0L, 1) == -1) goto BadRead; if ( !( lpLZW = DecompressLZW_GIF (ifd.pFile, NULL, 0, iCodeSize, NULL))) goto BadRead; compressInit = YES; if (ImDesc.Interlaced) iRowMapIndex = 1; else iRowMapIndex = 0; sy = gifRowMap [iRowMapIndex].first; for (i = 0; i < nlin; i++) { if (Progress (i, nlin, YES)) goto Exit; if (!(DecompressLZW_GIF (ifd.pFile, lpFileLine, npix, iCodeSize, lpLZW))) goto BadRead; if ( !(lpOut = FramePointerRaw(lpFrame, 0, sy, YES)) ) goto BadWrite; TypeConvert.ConvertData(lpFileLine, lpOut, sy, npix); sy += gifRowMap [iRowMapIndex].step; if (sy >= ImDesc.ImHeight) { iRowMapIndex++; sy = gifRowMap [iRowMapIndex].first; } } m_iWidth = npix; m_iHeight = nlin; m_iRes = xres; m_lpFrame = lpFrame; fRet = TRUE; goto Exit; } CATCH_ALL(e) { goto BadRead; } END_CATCH_ALL ProgressEnd(); return (TRUE); BadRead: SetError(BEC_errFileRead); goto Exit; BadWrite: SetError(BEC_errFrameRead); Exit: if (compressInit) DecompressLZW_GIF (ifd.pFile, NULL, 0, iCodeSize, lpLZW); compressInit = NO; if ( lpFileLine ) FreeUp( lpFileLine ); if ( lpLineBuffer ) FreeUp (lpLineBuffer); if ( lpColorMap ) FrameDestroyColorMap(lpColorMap); CloseFile(pTheFile); if (!fRet && lpFrame) FrameClose(lpFrame); ProgressEnd(); return(fRet); }
//************************************************************************ LOCAL STATUS_CODE ApplyCalibration( LPIMAGE lpImage, ITEMID dirty, LPSTR lpScanMap, LPSTR lpPrintMap, LPRECT lpUpdateRect, LPUPDATE_TYPE lpUpdateType) //************************************************************************ { FNAME szFileName; ENGINE Engine; LPCALMAPS lpMaps; BOOL fScanMap, fPrintMap; FRMTYPEINFO TypeInfo; LPCOLORMAP lpColorMap; STATUS_CODE StatusCode; int i; ASSERT(lpImage); AstralSetRectEmpty(lpUpdateRect); *lpUpdateType = UT_NONE; ImgGetTypeInfo(lpImage, &TypeInfo); lpMaps = (LPCALMAPS)Alloc(sizeof(CALMAPS)); if (!lpMaps) { Message(IDS_EMEMALLOC); return(SC_MEMERROR); } for (i = 0; i < CALSCAN_MAPS; ++i) ResetMap( &lpMaps->ScanMap[i], CALPOINTS, NO ); if (fScanMap = (lstrlen(lpScanMap) != 0)) { if ( LookupExtFileN( lpScanMap, szFileName, IDN_SCANMAP, NO ) ) { // Remember that the maps load in XRGB order if (!LoadMap( &lpMaps->ScanMap[CALSCAN_GRAY], &lpMaps->ScanMap[CALSCAN_RED], &lpMaps->ScanMap[CALSCAN_GREEN], &lpMaps->ScanMap[CALSCAN_BLUE], szFileName )) { FreeUp(lpMaps); return(SC_READERROR); } if (TypeInfo.DataType == FDT_CMYKCOLOR) { // make maps work on cmyk for (i = 0; i < CALSCAN_MAPS; ++i) ReverseMap(&lpMaps->ScanMap[i], FALSE); } } else { fScanMap = NO; } } for (i = 0; i < CAL_MAPS; ++i) ResetMap( &lpMaps->PrintMap[i], CALPOINTS, NO ); if (fPrintMap = (lstrlen(lpPrintMap) != 0)) { if ( LookupExtFileN( lpPrintMap, szFileName, IDN_CALMAP, NO ) ) { // Remember that the maps load in MCMYK order if (!LoadCalMap( &lpMaps->PrintMap[CAL_MASTER], &lpMaps->PrintMap[CAL_CYAN], &lpMaps->PrintMap[CAL_MAGENTA], &lpMaps->PrintMap[CAL_YELLOW], &lpMaps->PrintMap[CAL_BLACK], szFileName )) { FreeUp(lpMaps); return(SC_READERROR); } if (TypeInfo.DataType != FDT_CMYKCOLOR) { // make maps work on rgb for (i = 0; i < CAL_MAPS; ++i) ReverseMap(&lpMaps->PrintMap[i], FALSE); } } else { fPrintMap = NO; lpPrintMap = NULL; } } if (!fScanMap && !fPrintMap) { FreeUp(lpMaps); return(SC_SUCCESS); // user selected no maps??? } switch (TypeInfo.DataType) { case FDT_LINEART: case FDT_GRAYSCALE: MakeFloatMap(&lpMaps->ScanMap[CALSCAN_GRAY], lpMaps->CalPnts); MakeFloatMap(&lpMaps->PrintMap[CAL_BLACK], lpMaps->TmpPnts); MapCombine(lpMaps->CalPnts, lpMaps->TmpPnts); MapCreateLut(lpMaps->CalPnts, lpMaps->Lut[0]); break; case FDT_CMYKCOLOR: for (i = 0; i < 4; ++i) { if (i == 3) // black MakeFloatMap(&lpMaps->ScanMap[CALSCAN_GRAY], lpMaps->CalPnts); else MakeFloatMap(&lpMaps->ScanMap[CALSCAN_RED+i], lpMaps->CalPnts); MakeFloatMap(&lpMaps->PrintMap[CAL_MASTER], lpMaps->TmpPnts); MapCombine(lpMaps->CalPnts, lpMaps->TmpPnts); MakeFloatMap(&lpMaps->PrintMap[CAL_CYAN+i], lpMaps->TmpPnts); MapCombine(lpMaps->CalPnts, lpMaps->TmpPnts); MapCreateLut(lpMaps->CalPnts, lpMaps->Lut[i]); } break; default: case FDT_RGBCOLOR: case FDT_PALETTECOLOR: for (i = 0; i < 3; ++i) { MakeFloatMap(&lpMaps->ScanMap[CALSCAN_RED+i], lpMaps->CalPnts); MakeFloatMap(&lpMaps->PrintMap[CAL_MASTER], lpMaps->TmpPnts); MapCombine(lpMaps->CalPnts, lpMaps->TmpPnts); MakeFloatMap(&lpMaps->PrintMap[CAL_CYAN+i], lpMaps->TmpPnts); MapCombine(lpMaps->CalPnts, lpMaps->TmpPnts); MapCreateLut(lpMaps->CalPnts, lpMaps->Lut[i]); } break; } ImgGetTypeInfo(lpImage, &TypeInfo); if (TypeInfo.DataType == FDT_PALETTECOLOR) { lpColorMap = FrameCopyColorMap(TypeInfo.ColorMap); if (!lpColorMap) { Message(IDS_EMEMALLOC); return(SC_MEMERROR); } LineCalMapProc(0, 0, lpColorMap->NumEntries-1, (LPTR)lpColorMap->RGBData, (LPTR)lpColorMap->RGBData, 3, lpMaps); StatusCode = ApplyColorMap(lpImage, lpColorMap, FALSE, DT_NONE, dirty); FrameDestroyColorMap(lpColorMap); if (StatusCode == SC_SUCCESS) *lpUpdateType = UT_DATATYPE; } else { SetEngineDef(&Engine); Engine.lpDataProc = (LPDATAPROC)LineCalMapProc; Engine.lpParam = lpMaps; StatusCode = LineEngineSelObj(lpImage, &Engine, dirty); if (!AstralIsRectEmpty(&Engine.rUpdate)) { *lpUpdateRect = Engine.rUpdate; *lpUpdateType = UT_AREA; } } FreeUp(lpMaps); return(StatusCode); }
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); }