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; }
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); }