LOCAL void PalPicker_Draw( HWND hWindow, HDC hDC ) /***********************************************************************/ { RECT ClientRect, rPatch; LPCOLORMAP lpColorMap; LPTR lpData; FRMTYPEINFO TypeInfo; int iWidth, iHeight, c, r, n; BYTE value; lpColorMap = PalPicker_GetColorMap(hWindow); if (lpColorMap) n = lpColorMap->NumEntries; else n = 256; // fill background with white GetClientRect(hWindow, &ClientRect); FillRect( hDC, &ClientRect, (HBRUSH)GetStockObject(WHITE_BRUSH) ); // frame the picker FrameRect(hDC, &ClientRect, (HBRUSH)GetStockObject(BLACK_BRUSH) ); InflateRect(&ClientRect, -3, -3); WindowsToAstralRect(&ClientRect); iWidth = RectWidth(&ClientRect); iHeight = RectHeight(&ClientRect); lpData = Alloc((long)iWidth); if (!lpData) return; if (lpColorMap) FrameSetTypeInfo(&TypeInfo, FDT_PALETTECOLOR, lpColorMap); else FrameSetTypeInfo(&TypeInfo, FDT_GRAYSCALE, NULL); value = 0; for (r = 0; r < 16; ++r) { for (c = 0; c < 16; ++c) { PalPicker_GetRect(hWindow, r, c, &rPatch); PalPicker_DrawPatch(hDC, &rPatch, value, TypeInfo, lpData); ++value; if (value >= n) break; } if (value >= n) break; } FreeUp(lpData); }
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); }
void FramePutRGB( LPFRAME lpFrame, LPRGB lpSrcRGB, LPTR lpDst, int iPixelCount) { CFrameTypeConvert TypeConvert; FRMTYPEINFO SrcTypeInfo, DstTypeInfo; if (!lpFrame) return; FrameSetTypeInfo(&SrcTypeInfo, FDT_RGBCOLOR); FrameGetTypeInfo(lpFrame, &DstTypeInfo); if (!TypeConvert.Init(SrcTypeInfo, DstTypeInfo, iPixelCount, DT_NONE)) return; TypeConvert.ConvertData((LPTR)lpSrcRGB, lpDst, 0, iPixelCount); }
BOOL CExpandImageDlg::OnCommand(WPARAM wParam, LPARAM lParam) { int id = LOWORD(wParam); //ID of control WORD codeNotify = HIWORD(wParam); //Control notification code HWND hControl = (HWND) lParam; //Handle of control LPIMAGE lpImage; FRMTYPEINFO TypeInfo; long Color; switch (id) { case IDC_EXPANDLEFT: case IDC_EXPANDRIGHT: case IDC_EXPANDTOP: case IDC_EXPANDBOTTOM: case IDC_HEIGHT: case IDC_WIDTH: case IDC_PREF_UNITS: DoExpandControls(id, codeNotify); break; case IDC_FILLINCOLOR: if (codeNotify != 1) break; lpImage = GetImage(); if (lpImage) ImgGetTypeInfo(lpImage, &TypeInfo); else FrameSetTypeInfo(&TypeInfo, FDT_RGBCOLOR, NULL); if (TypeInfo.DataType == FDT_LINEART) { if(m_FillColor.gray == 255) m_FillColor.gray = 0; else m_FillColor.gray = 255; SetColorInfo(&m_FillColor, &m_FillColor, CS_GRAY); } else if (TypeInfo.DataType == FDT_GRAYSCALE || TypeInfo.DataType == FDT_PALETTECOLOR) { if (!PalettePicker(&m_FillColor, NULL, TypeInfo.ColorMap)) break; } else if (!ColorPicker(&m_FillColor, NULL)) break; CopyRGB( &m_FillColor.rgb, &Color ); SetWindowLong(::GetDlgItem(GetSafeHwnd(),IDC_FILLINCOLOR), GWL_ACTIVE, Color ); AstralControlRepaint(GetSafeHwnd(), IDC_FILLINCOLOR); break; case IDOK: if ( (FMUL( m_Resolution, m_Width ) > MAX_IMAGE_WIDTH) || (FMUL( m_Resolution, m_Height) > MAX_IMAGE_HEIGHT)) { Message( IDS_ETOOWIDE ); break; } SetUnitResolution( 0 ); Control.Units = m_SaveUnits; SetUnitInfo((UNIT_TYPE)(Control.Units-IDC_PREF_UNITINCHES), Control.UnitRes, Control.Points); AstralDlgEnd( GetSafeHwnd(), TRUE ); break; default: break; } return CPPViewModalDlg::OnCommand(wParam, lParam); }
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); }
BOOL ConvertTo(LPIMAGE lpImage, int iFunction) /***********************************************************************/ { CONVERT_PARMS parms; DITHER_TYPE DitherType = DT_NONE; if (ImgInMaskEditMode(lpImage)) return(FALSE); ImgGetTypeInfo(lpImage, &parms.cmsInfo.src); switch (iFunction) { case IDM_CONVLA: FrameSetTypeInfo(&parms.cmsInfo.dst, FDT_LINEART); break; case IDM_CONVSP: FrameSetTypeInfo(&parms.cmsInfo.dst, FDT_LINEART); DitherType = DT_SCATTER; break; case IDM_CONVCT: FrameSetTypeInfo(&parms.cmsInfo.dst, FDT_GRAYSCALE); break; case IDM_CONVPALETTE: FrameSetTypeInfo(&parms.cmsInfo.dst, FDT_PALETTECOLOR); if ( !AstralDlg( NO, PictPubApp.GetResourceHandle(), PictPubApp.Get_hWndAstral(), IDD_CONVERTTO, DlgConvertProc )) return( NO ); DitherType = Convert.ConvertDitherType; break; case IDM_CONVRGBCOLOR: if (Control.CMSEnabled && IsSrcPTSelected(&parms.cmsInfo.src.ptInfo)) { CMSINFO CmsInfo; CmsInfo.src.DataType = FDT_CMYKCOLOR; if (!CmsGetDstPT(&CmsInfo)) return(FALSE); else parms.cmsInfo.dst = CmsInfo.dst; } else { FrameSetTypeInfo(&parms.cmsInfo.dst, FDT_RGBCOLOR); } break; case IDM_CONVCMYKCOLOR: if (Control.CMSEnabled && IsSrcPTSelected(&parms.cmsInfo.src.ptInfo)) { CMSINFO CmsInfo; CmsInfo.src.DataType = FDT_RGBCOLOR; if (!CmsGetDstPT(&CmsInfo)) return(FALSE); else parms.cmsInfo.dst = CmsInfo.dst; } else { FrameSetTypeInfo(&parms.cmsInfo.dst, FDT_CMYKCOLOR); } break; case IDM_COLORMANAGED: if (!CmsGetSrcDstPT(&parms.cmsInfo)) return(TRUE); break; } parms.DitherType = DitherType; parms.ConvertType = Convert.ConvertType; parms.iLevels = Convert.ConvertColors; lstrcpy(parms.szPalette, Convert.ConvertPalette); ProcessCommand(lpImage->lpCmdList, IDS_CMD_CONVERT, &parms); return(TRUE); }
static LPTR FrameToColorDIB( LPFRAME lpFrame, LPRECT lpRect ) { int y, bpl; LPTR lpSrc, lpDIBMem, lpConvertLine; HPTR hpDstLine; DWORD lCount, lImageSize, lInfoSize; int dx, dy; LPBITMAPINFO lpInfo; FRMTYPEINFO SrcTypeInfo, DstTypeInfo; CFrameTypeConvert TypeConvert; if ( !lpFrame ) return( NULL ); FrameGetTypeInfo(lpFrame, &SrcTypeInfo); FrameSetTypeInfo(&DstTypeInfo, FDT_RGBCOLOR); dx = (lpRect->right - lpRect->left) + 1; dy = (lpRect->bottom - lpRect->top) + 1; lInfoSize = sizeof(BITMAPINFOHEADER); bpl = dx * 3; // Always 24-bit color out bpl = 4 * ((bpl + 3) / 4); // DIB packing lImageSize = (long)bpl * dy; lCount = lInfoSize + lImageSize; // Allocate the memory to hold the DIB if ( !(lpDIBMem = Alloc( lCount )) ) { FrameSetError( ERR_MALLOC ); return( NULL ); } if ( !(lpConvertLine = Alloc( bpl )) ) { FreeUp(lpDIBMem); FrameSetError( ERR_MALLOC ); return( NULL ); } lpInfo = (LPBITMAPINFO)lpDIBMem; lpInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); lpInfo->bmiHeader.biWidth = dx; lpInfo->bmiHeader.biHeight = dy; lpInfo->bmiHeader.biPlanes = 1; lpInfo->bmiHeader.biCompression = BI_RGB; lpInfo->bmiHeader.biBitCount = 24; lpInfo->bmiHeader.biSizeImage = lImageSize; lpInfo->bmiHeader.biXPelsPerMeter = (10000L * (long) FrameResolution(lpFrame)) / 254L; lpInfo->bmiHeader.biYPelsPerMeter = (10000L * (long) FrameResolution(lpFrame)) / 254L; lpInfo->bmiHeader.biClrUsed = 0; lpInfo->bmiHeader.biClrImportant = 0; hpDstLine = (HPTR)lpDIBMem; hpDstLine += lInfoSize; if (!TypeConvert.Init(SrcTypeInfo, DstTypeInfo, dx)) { FreeUp(lpDIBMem); FreeUp(lpConvertLine); FrameSetError( ERR_MALLOC ); return( NULL ); } // This goes backwards... for (y = lpRect->bottom; y >= lpRect->top; y--) { lpSrc = FramePointer(lpFrame, lpRect->left, y, NO); if (lpSrc) { TypeConvert.ConvertData(lpSrc, lpConvertLine, y, dx); swapBGR( lpConvertLine, lpConvertLine, dx); CopyToHuge(lpConvertLine, hpDstLine, bpl); } hpDstLine += bpl; } FreeUp(lpConvertLine); return( lpDIBMem ); }
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 void Palette_Paint( HDC hDC, HWND hWindow ) /***********************************************************************/ { RECT ClientRect; LPPALETTE lpPalette; int iRowIncr, iColIncr, iWidth, iHeight, iRows, iCols; int iStart, iEntry, r, c, xCount, yCount; LPRGB lpRGB, lpLine; LFIXED xrate, yrate; BLTSESSION BltSession; FRMTYPEINFO TypeInfo; // get pointer to palette information lpPalette = (LPPALETTE)GetWindowLong(hWindow, GWL_PALETTE); if (!lpPalette) return; GetClientRect(hWindow, &ClientRect); FrameRect(hDC, &ClientRect, (HBRUSH)GetStockObject(BLACK_BRUSH) ); if (!lpPalette->iColors) return; // get ClientRect and allocate buffer for SuperBlt GetChipLayout(hWindow, &ClientRect, &iRows, &iCols, &iRowIncr, &iColIncr, &iStart); iWidth = RectWidth(&ClientRect); iHeight = RectHeight(&ClientRect); lpRGB = (LPRGB)Alloc((long)iWidth*3L); if (!lpRGB) return; yrate = FGET(iHeight, iRows); xrate = FGET(iWidth, iCols); FrameSetTypeInfo(&TypeInfo, FDT_RGBCOLOR, NULL); StartSuperBlt( &BltSession, hDC, NULL, lpBltScreen, &ClientRect, TypeInfo, 10, 0, 0, YES, NULL, NULL ); for (r = 0; r < iRows; ++r) { yCount = FMUL(r+1, yrate) - FMUL(r, yrate); set24(lpRGB, iWidth, RGB(255,255,255)); SuperBlt(&BltSession, (LPTR)lpRGB); yCount -= 2; while (--yCount >= 0) { iEntry = iStart + (r * iRowIncr); lpLine = lpRGB; set24(lpLine, iWidth, RGB(255,255,255)); for (c = 0; c < iCols; ++c) { xCount = FMUL(c+1, xrate) - FMUL(c, xrate); if (iEntry < lpPalette->iColors) set24(lpLine+1, xCount-2, RGB2long(lpPalette->lpColorInfo[iEntry].rgb)); lpLine += xCount; iEntry += iColIncr; } SuperBlt(&BltSession, (LPTR)lpRGB); } set24(lpRGB, iWidth, RGB(255,255,255)); SuperBlt(&BltSession, (LPTR)lpRGB); } SuperBlt(&BltSession, NULL); FreeUp((LPTR)lpRGB); }
BOOL CReadBitmap::CTRead() { LPCTHEADER lpTH; LPFRAME lpFrame; BOOL fConvert = FALSE, fRet = FALSE; CFile theFile; CFile* pTheFile; FRMTYPEINFO inType, outType; LPTR lpIn, lpIn2,lpOut, lpFrmLine; int x,y,j; UINT bytes_read; BOOL GrayScale; BITMAP_ERROR_CODE err; CFrameTypeConvert Convert; ProgressBegin(1); if ((pTheFile = OpenFile()) == NULL) { ProgressEnd(); return(FALSE); } lpFrame = NULL; if ( !(lpTH = ReadCTHeader(pTheFile, m_lpFileName, &err))) { SetError(err); goto Exit; } GrayScale = lpTH->ColSepMask == 8 && lpTH->NumColSep == 1; if (GrayScale) FrameSetTypeInfo(&inType, FDT_GRAYSCALE, NULL); else FrameSetTypeInfo(&inType, FDT_CMYKCOLOR, NULL); if (!SetupTypes(&inType, &outType)) goto Exit; fConvert = !FrameTypeInfoEqual( inType, outType ); if( fConvert ) { if( !Convert.Init( inType, outType, lpTH->Pixels ) ) { SetError(BEC_errMemory); goto Exit; } } /* Create the image frame store */ if ( !(lpFrame = FrameOpen(outType, lpTH->Pixels, lpTH->Lines, lpTH->Resolution))) { SetError(BEC_errFrameOpen); goto Exit; } pTheFile->Seek (2048, CFile::begin); for (y=0; y < lpTH->Lines; y++) { if ( Progress(y, lpTH->Lines, YES)) goto Exit; TRY { bytes_read = pTheFile->Read(lpTH->lpCTLine, lpTH->LineSize); } CATCH_ALL(e) { goto BadRead; } END_CATCH_ALL if (bytes_read != lpTH->LineSize) goto BadRead; if ( !(lpFrmLine = FramePointerRaw( lpFrame, 0, y, YES))) goto BadWrite; lpIn = lpTH->lpCTLine; lpOut = lpFrmLine; lpIn2 = lpIn; for (x=0; x < lpTH->Pixels; x++) { j = 0; if (!GrayScale) { if (lpTH->ColSepMask & 0x1) // cyan { j += lpTH->ChannelSize; *lpOut++ = 255 - *lpIn2; } else *lpOut++ = 0; if (lpTH->ColSepMask & 0x2) // magenta { *lpOut++ = 255 - *(lpIn2 + j); j += lpTH->ChannelSize; } else *lpOut++ = 0; if (lpTH->ColSepMask & 0x4) // yellow { *lpOut++ = 255 - *(lpIn2 + j); j += lpTH->ChannelSize; } else *lpOut++ = 0; } if (lpTH->ColSepMask & 0x8) // black *lpOut++ = 255 - *(lpIn2 + j); else *lpOut++ = 0; lpIn2++; } if( fConvert ) Convert.ConvertData( lpFrmLine, lpFrmLine, y, lpTH->Pixels ); } m_iWidth = lpTH->Pixels; m_iHeight = lpTH->Lines; m_iRes = (int)lpTH->Resolution; m_lpFrame = lpFrame; fRet = TRUE; goto Exit; BadRead: SetError(BEC_errFileRead); goto Exit; BadWrite: SetError(BEC_errFrameRead); Exit: FreeCTHeader(lpTH); CloseFile(pTheFile); if (!fRet && lpFrame) FrameClose(lpFrame); ProgressEnd(); return( fRet ); }
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); }