bool CAudioGenerateDoc::GenerateBegin() { // // Waveform storage // m_waveformBuffer.Start(NumChannels(), SampleRate()); if(m_fileoutput) { if(!OpenGenerateFile(m_wave)) return false; } ProgressBegin(this); if(m_audiooutput) { m_soundstream.SetChannels(NumChannels()); m_soundstream.SetSampleRate(int(SampleRate())); m_soundstream.Open(((CAudioProcessApp *)AfxGetApp())->DirSound()); } return true; }
BOOL PosterizeImage(LPIMAGE lpImage, LPPOSTERIZE_PARMS lpParms) /************************************************************************/ { LPMAPS lpMaps; RECT rUpdate; UPDATE_TYPE UpdateType; FRMDATATYPE type; ImgGetInfo(lpImage, NULL, NULL, NULL, &type); if (type == FDT_LINEART) return(FALSE); else if (type == FDT_PALETTECOLOR && ImgGetMask(lpImage)) return(FALSE); if (!(lpMaps = (LPMAPS)Alloc((long)sizeof(MAPS)))) { lpParms->Common.StatusCode = SC_MEMERROR; Message(IDS_EMEMALLOC); return(FALSE); } ProgressBegin(1, lpParms->Common.idDirty-IDS_UNDOFIRST+IDS_PROGFIRST); ResetMap( &lpMaps->MasterMap, MAXPOINTS, NO ); ResetMap( &lpMaps->RedMap, MAXPOINTS, NO ); ResetMap( &lpMaps->GreenMap, MAXPOINTS, NO ); ResetMap( &lpMaps->BlueMap, MAXPOINTS, NO ); ResetMap( &lpMaps->BlackMap, MAXPOINTS, NO ); ResetMap( &lpMaps->HueMap, MAXPOINTS, NO ); ResetMap( &lpMaps->SatMap, MAXPOINTS, NO ); lpMaps->MasterMap.Levels = lpParms->MasterInfo.Levels; lpMaps->MasterMap.Threshold = lpParms->MasterInfo.Threshold; lpMaps->RedMap.Levels = lpParms->RedInfo.Levels; lpMaps->RedMap.Threshold = lpParms->RedInfo.Threshold; lpMaps->GreenMap.Levels = lpParms->GreenInfo.Levels; lpMaps->GreenMap.Threshold = lpParms->GreenInfo.Threshold; lpMaps->BlueMap.Levels = lpParms->BlueInfo.Levels; lpMaps->BlueMap.Threshold = lpParms->BlueInfo.Threshold; lpMaps->BlackMap.Levels = lpParms->BlackInfo.Levels; lpMaps->BlackMap.Threshold = lpParms->BlackInfo.Threshold; MakeMap(&lpMaps->MasterMap); MakeMap(&lpMaps->RedMap); MakeMap(&lpMaps->GreenMap); MakeMap(&lpMaps->BlueMap); MakeMap(&lpMaps->BlackMap); lpParms->Common.StatusCode = ApplyMaps(lpImage, lpMaps, lpParms->Common.idDirty, &rUpdate, &UpdateType); if (UpdateType) { lpParms->Common.UpdateType = UpdateType; lpParms->Common.rUpdateArea = rUpdate; } FreeUp(lpMaps); ProgressEnd(); return(lpParms->Common.StatusCode == SC_SUCCESS); }
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); }
LOCAL LPFRAME ConvertFrame(LPFRAME lpSrcFrame, FRMTYPEINFO OutTypeInfo, CFrameTypeConvert *pTypeConvert) /***********************************************************************/ { int y, Xsize, Ysize; LPFRAME lpDstFrame; FRMTYPEINFO InTypeInfo; LPTR lpSrc, lpDst; CFrameTypeConvert TypeConvert; Xsize = FrameXSize(lpSrcFrame); Ysize = FrameYSize(lpSrcFrame); FrameGetTypeInfo(lpSrcFrame, &InTypeInfo); if (!pTypeConvert) { if (!TypeConvert.Init(InTypeInfo, OutTypeInfo, Xsize)) { Message(IDS_EMEMALLOC); return(NULL); } pTypeConvert = &TypeConvert; } lpDstFrame = FrameOpen(OutTypeInfo, Xsize, Ysize, FrameResolution(lpSrcFrame)); if (!lpDstFrame) { FrameError(IDS_EPROCESSOPEN); return(NULL); } ProgressBegin(1, 0); for (y = 0; y < Ysize; ++y) { if (AstralClockCursor(y, Ysize, YES)) { FrameClose(lpDstFrame); goto ExitError; } if (!(lpSrc = FramePointerRaw(lpSrcFrame, 0, y, NO))) continue; if (!(lpDst = FramePointerRaw(lpDstFrame, 0, y, YES))) continue; pTypeConvert->ConvertData(lpSrc, lpDst, y, Xsize); } ProgressEnd(); return(lpDstFrame); ExitError: ProgressEnd(); return(NULL); }
BOOL HueImage(LPIMAGE lpImage, LPHUE_PARMS lpParms) /************************************************************************/ { LPMAPS lpMaps; RECT rUpdate; UPDATE_TYPE UpdateType; FRMDATATYPE type; ImgGetInfo(lpImage, NULL, NULL, NULL, &type); if (type == FDT_LINEART || type == FDT_GRAYSCALE) return(FALSE); else if (type == FDT_PALETTECOLOR && ImgGetMask(lpImage)) return(FALSE); if (!(lpMaps = (LPMAPS)Alloc((long)sizeof(MAPS)))) { lpParms->Common.StatusCode = SC_MEMERROR; Message(IDS_EMEMALLOC); return(FALSE); } ProgressBegin(1, lpParms->Common.idDirty-IDS_UNDOFIRST+IDS_PROGFIRST); ResetMap( &lpMaps->MasterMap, MAXPOINTS, NO ); ResetMap( &lpMaps->RedMap, MAXPOINTS, NO ); ResetMap( &lpMaps->GreenMap, MAXPOINTS, NO ); ResetMap( &lpMaps->BlueMap, MAXPOINTS, NO ); ResetMap( &lpMaps->BlackMap, MAXPOINTS, NO ); ResetMap( &lpMaps->HueMap, MAXPOINTS, NO ); ResetMap( &lpMaps->SatMap, MAXPOINTS, NO ); lpMaps->HueMap.Points = lpParms->HueInfo.Points; copy((LPTR)&lpParms->HueInfo.Pnt, (LPTR)&lpMaps->HueMap.Pnt, sizeof(lpMaps->HueMap.Pnt)); lpMaps->SatMap.Brightness[0] = lpParms->Saturation; lpMaps->MasterMap.Brightness[0] = lpParms->Brightness; MakeMap(&lpMaps->HueMap); MakeMap(&lpMaps->SatMap); MakeMap(&lpMaps->MasterMap); lpParms->Common.StatusCode = ApplyMaps(lpImage, lpMaps, lpParms->Common.idDirty, &rUpdate, &UpdateType); if (UpdateType) { lpParms->Common.UpdateType = UpdateType; lpParms->Common.rUpdateArea = rUpdate; } FreeUp(lpMaps); ProgressEnd(); return(lpParms->Common.StatusCode == SC_SUCCESS); }
BOOL ContBritImage(LPIMAGE lpImage, LPCONTBRIT_PARMS lpParms) /************************************************************************/ { LPMAPS lpMaps; int i; RECT rUpdate; UPDATE_TYPE UpdateType; FRMDATATYPE type; ImgGetInfo(lpImage, NULL, NULL, NULL, &type); if (type == FDT_LINEART) return(FALSE); else if (type == FDT_PALETTECOLOR && ImgGetMask(lpImage)) return(FALSE); if (!(lpMaps = (LPMAPS)Alloc((long)sizeof(MAPS)))) { lpParms->Common.StatusCode = SC_MEMERROR; Message(IDS_EMEMALLOC); return(FALSE); } ProgressBegin(1, lpParms->Common.idDirty-IDS_UNDOFIRST+IDS_PROGFIRST); ResetMapEx( &lpMaps->MasterMap, MAPPOINTS, NO, YES); ResetMap( &lpMaps->RedMap, MAPPOINTS, NO ); // sometimes Cyan ResetMap( &lpMaps->GreenMap, MAPPOINTS, NO ); // sometimes Magenta ResetMap( &lpMaps->BlueMap, MAPPOINTS, NO ); // sometimes Yellow ResetMap( &lpMaps->BlackMap, MAPPOINTS, NO ); ResetMap( &lpMaps->HueMap, MAXPOINTS, NO ); ResetMap( &lpMaps->SatMap, MAPPOINTS, NO ); lpMaps->MasterMap.Contrast = lpParms->Contrast; for (i = 0; i < NUM_BANDS; ++i) lpMaps->MasterMap.Brightness[i] = lpParms->Brightness[i]; MakeMap(&lpMaps->MasterMap); lpParms->Common.StatusCode = ApplyMaps(lpImage, lpMaps, lpParms->Common.idDirty, &rUpdate, &UpdateType); if (UpdateType) { lpParms->Common.UpdateType = UpdateType; lpParms->Common.rUpdateArea = rUpdate; } FreeUp(lpMaps); ProgressEnd(); return(lpParms->Common.StatusCode == SC_SUCCESS); }
LOCAL BOOL size_image(LPIMAGE lpImage, LFIXED Width , LFIXED Height, int Resolution, BOOL bSmartSize) { int pix, lin, res; LPFRAME lpDataFrame; LPFRAME lpAlphaFrame; LPOBJECT lpBase; LPALPHA lpAlpha; RECT rAlpha; if (!lpImage) return(FALSE); lpBase = ImgGetBase(lpImage); lpAlpha = lpBase->lpAlpha; res = Resolution; ProgressBegin(1, 0); pix = FMUL( res, Width ); lin = FMUL( res, Height ); lpAlphaFrame = NULL; if (lpDataFrame = SizeFrame(lpBase->Pixmap.EditFrame, pix, lin, res, bSmartSize)) { if (lpAlpha) lpAlphaFrame = SizeFrame(lpAlpha->Pixmap.EditFrame, pix, lin, res, bSmartSize); } if ( !lpDataFrame || (lpAlpha && !lpAlphaFrame)) { if (lpDataFrame) FrameClose(lpDataFrame); if (lpAlphaFrame) FrameClose(lpAlphaFrame); ProgressEnd(); return( FALSE ); } lpBase->rObject.right = FrameXSize(lpDataFrame)-1; lpBase->rObject.bottom = FrameYSize(lpDataFrame)-1; if (lpAlpha) MaskRectUpdate(lpAlpha, &rAlpha); ProgressEnd(); return( TRUE ); }
void 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(); }
LOCAL void PaletteMapPixmap(LPPIXMAP lpPixmap, CFrameTypeConvert *pTypeConvert) /***********************************************************************/ { int y, w, h; LPTR lp; ProgressBegin(1, 0); w = FrameXSize(lpPixmap->EditFrame); h = FrameYSize(lpPixmap->EditFrame); for (y = 0; y < h; ++y) { AstralClockCursor(y, h, NO); lp = PixmapPtr(lpPixmap, PMT_EDIT, 0, y, YES); if (!lp) break; pTypeConvert->ConvertData(lp, lp, y, w); } ProgressEnd(); }
BOOL TextureFillImage( LPIMAGE lpImage, LPTEXTUREFILL_PARMS lpParms) { ENGINE Engine; FNAME szFileName; LPFRAME lpTexture; FRMTYPEINFO TypeInfo; ImgGetTypeInfo(lpImage, &TypeInfo); if (!LookupExtFile(lpParms->TextureName, szFileName, IDN_TEXTURE)) { lpParms->Common.StatusCode = SC_FILENOTFOUND; return(FALSE); } ProgressBegin(2, lpParms->Common.idDirty-IDS_UNDOFIRST+IDS_PROGFIRST); CReadImage read(szFileName); if ( !(lpTexture = read.ReadFrame(TypeInfo) )) { ProgressEnd(); lpParms->Common.StatusCode = SC_READERROR; return(FALSE); } SetEngineOld(&Engine, NO, NULL, NULL, lpTexture, lpParms->fHorzFlip, lpParms->fVertFlip, NULL, NULL, lpParms->TextureOpacity, lpParms->TextureMergeMode); lpParms->Common.StatusCode = LineEngineSelObj(lpImage,&Engine,lpParms->Common.idDirty); if (!AstralIsRectEmpty(&Engine.rUpdate)) { lpParms->Common.UpdateType = UT_AREA; lpParms->Common.rUpdateArea = Engine.rUpdate; } ProgressEnd(); return(lpParms->Common.StatusCode == SC_SUCCESS); }
BOOL ApplyCalImage(LPIMAGE lpImage, LPAPPLYCAL_PARMS lpParms) /************************************************************************/ { RECT rUpdate; UPDATE_TYPE UpdateType; FRMDATATYPE type; ImgGetInfo(lpImage, NULL, NULL, NULL, &type); if (type == FDT_LINEART) return(FALSE); else if (type == FDT_PALETTECOLOR && ImgGetMask(lpImage)) return(FALSE); ProgressBegin(1, lpParms->Common.idDirty-IDS_UNDOFIRST+IDS_PROGFIRST); lpParms->Common.StatusCode = ApplyCalibration(lpImage, lpParms->Common.idDirty, lpParms->szScanMap, lpParms->szPrintMap, &rUpdate, &UpdateType); if (UpdateType) { lpParms->Common.UpdateType = UpdateType; lpParms->Common.rUpdateArea = rUpdate; } ProgressEnd(); return(lpParms->Common.StatusCode == SC_SUCCESS); }
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); }
int AstralImageImport( LPSTR lpInFile, LPSTR lpProfile, int nFileType ) ////////////////////////////////////////////////////////////////////////// { OFSTRUCT ofstruct; HINSTANCE hDLL = NULL; HINSTANCE hSrcLibrary = NULL; HINSTANCE hDstLibrary = NULL; HINSTANCE hImportSetupData = NULL; HINSTANCE hExportSetupData = NULL; CREATESETUP lpfnCreateSetup = NULL; DESTROYSETUP lpfnDestroySetup = NULL; IMPORTPROC lpfnImportProc = NULL; IMPORT_OPTIONS Options; EXPORT_OPTIONS Export; int error = IMPORT_NOERROR; FNAME szFilterPath; FNAME szOutFile; FNAME szTempFile; FNAME szINIPath; char szFilter[13]; char szINI[13]; ProgressBegin( 1, PROGRESS_ID( IDS_UNDOIMPORTIMAGE )); szFilterPath[0] = szOutFile[0] = szTempFile[0] = szINIPath[0] = 0; szFilter[0] = szINI[0] = 0; if( !nFileType || nFileType < IDN_FIRSTIMPORTFILETYPE || nFileType > IDN_LASTIMPORTFILETYPE ) { error = IMPORT_INVALIDFILE_ERROR; goto ImportAbort; } // load ISGDI9.DLL explicitly GetModuleFileName( PictPubApp.Get_hInstAstral(), szFilterPath, sizeof( szFilterPath )); *strrchr( szFilterPath, '\\' ) = '\0'; lstrcat( szFilterPath, "\\" ); lstrcat( szFilterPath, FILTER_DRIVER ); hDLL = LoadLibrary( szFilterPath ); #ifdef WIN32 if( hDLL == NULL ) #else if( hDLL < HINSTANCE_ERROR ) #endif { error = IMPORT_DLLLOAD_ERROR; goto ImportAbort; } // get filter and profile names GetImportFilter( nFileType, szFilter, szINI ); // get location of filters GetExtNamePath( szFilterPath, IDN_IMPORTFILTERS ); // set import filter path lstrcat( szFilterPath, szFilter ); if( OpenFile( szFilterPath, &ofstruct, OF_EXIST ) == HFILE_ERROR ) { error = IMPORT_SRCLIBLOAD_ERROR; goto ImportAbort; } // set import filter profile path if( Control.bNetworkInstall ) // use pouch path { GetIniPath( szINIPath ); } else // use filters directory { GetExtNamePath( szINIPath, IDN_IMPORTFILTERS ); } lstrcat( szINIPath, szINI ); #ifdef WIN32 if(( hSrcLibrary = LoadLibrary( szFilterPath )) != NULL ) #else if(( hSrcLibrary = LoadLibrary( szFilterPath )) >= HINSTANCE_ERROR ) #endif { lpfnCreateSetup = ( CREATESETUP )GetProcAddress( hSrcLibrary, "CreateSetup" ); hImportSetupData = ( HINSTANCE )( *lpfnCreateSetup )( hSrcLibrary, szINIPath, NULL, NULL ); } else { error = IMPORT_SRCLIBLOAD_ERROR; goto ImportAbort; } // set export filter path *strrchr( szFilterPath, '\\' ) = '\0'; lstrcat( szFilterPath, "\\" ); lstrcat( szFilterPath, EXPORT_FILTER ); if( OpenFile( szFilterPath, &ofstruct, OF_EXIST ) == HFILE_ERROR ) { error = IMPORT_DSTLIBLOAD_ERROR; goto ImportAbort; } #ifdef WIN32 if(( hDstLibrary = LoadLibrary( szFilterPath )) != NULL ) #else if(( hDstLibrary = LoadLibrary( szFilterPath )) >= HINSTANCE_ERROR ) #endif { lpfnCreateSetup = ( CREATESETUP )GetProcAddress( hDstLibrary, "CreateSetup" ); hExportSetupData = ( HINSTANCE )( *lpfnCreateSetup )( hDstLibrary, lpProfile, NULL, NULL ); } else { error = IMPORT_DSTLIBLOAD_ERROR; goto ImportAbort; } memset( &Export, 0, sizeof( EXPORT_OPTIONS )); Export.GetSet_Status = ( GETSET_STATUS )MakeProcInstance(( FARPROC )GetSet_DialogStatus, PictPubApp.Get_hInstAstral()); if( Export.GetSet_Status == NULL ) { error = IMPORT_IMPORTFILE_ERROR; goto ImportAbort; } *strrchr( szFilterPath, '\\' ) = '\0'; *strrchr( szINIPath, '\\' ) = '\0'; memset( &Options, 0, sizeof( IMPORT_OPTIONS )); Options.hInputData = hImportSetupData; // Handle to import data Options.hOutputData = hExportSetupData; // Handle to export data Options.lpszDriverPath = szFilterPath; // Driver DLL directory Options.lpszFontPath = szFilterPath; // Font file directory Options.lpExport = &Export; // set temp file directory if( Control.bNetworkInstall ) Options.lpszWorkPath = szINIPath; else Options.lpszWorkPath = szFilterPath; lstrcpy( szOutFile, Options.lpszWorkPath ); lstrcat( szOutFile, "\\" ); // create temp file name lstrcpy( szTempFile, "PP" ); GetTempFilename( szTempFile, ".TIF" ); lstrcat( szOutFile, szTempFile ); lpfnImportProc = ( IMPORTPROC )GetProcAddress( hSrcLibrary, "ImportFile" ); if( !( error = (( *lpfnImportProc )( NULL, EXPORT_FILTER, szOutFile, lpInFile, ( LPSTR )&Options )))) lstrcpy( lpInFile, szOutFile ); else FileDelete( szOutFile ); // get rid of temp file in case of error if( Export.GetSet_Status != NULL ) FreeProcInstance(( FARPROC )Export.GetSet_Status ); ImportAbort: #ifdef WIN32 if( hDstLibrary != NULL ) #else if( hDstLibrary >= HINSTANCE_ERROR ) #endif { lpfnDestroySetup = ( DESTROYSETUP )GetProcAddress( hDstLibrary, "DestroySetup" ); ( *lpfnDestroySetup )( hExportSetupData ); FreeLibrary( hDstLibrary ); } #ifdef WIN32 if( hSrcLibrary != NULL ) #else if( hSrcLibrary >= HINSTANCE_ERROR ) #endif { lpfnDestroySetup = ( DESTROYSETUP )GetProcAddress( hSrcLibrary, "DestroySetup" ); ( *lpfnDestroySetup )( hImportSetupData ); FreeLibrary( hSrcLibrary ); } #ifdef WIN32 if( hDLL != NULL ) #else if( hDLL >= HINSTANCE_ERROR ) #endif { FreeLibrary( hDLL ); } ProgressEnd(); switch( error ) { case IMPORT_NOERROR: break; case IMPORT_INVALIDFILE_ERROR: // type not supported Message( IDS_INVALIDIMPORTFILE_ERROR ); break; case IMPORT_SRCLIBLOAD_ERROR: // error loading import filter Message( IDS_IMPORTLIBLOAD_ERROR ); break; case IMPORT_DSTLIBLOAD_ERROR: // error loading export filter Message( IDS_EXPORTLIBLOAD_ERROR ); break; case IME_INVALID_FILE_TYPE: // incorrect file format Message( IDS_INVALIDIMPORTFILE_TYPE ); break; case IME_INVALID_FILE_VERSION: // unsupported file version Message( IDS_INVALIDIMPORTFILE_VERSION ); break; case IME_MEMORY: // insufficient memory Message( IDS_EMEMALLOC ); break; case IMPORT_DLLLOAD_ERROR: case IMPORT_IMPORTFILE_ERROR: // non-specific error from app default: // non-specific error from filter Message( IDS_IMPORTFILE_ERROR ); break; } return error; }
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 ); }
BOOL CImage::CombineObjects(BOOL fNoUndo, BOOL fCreateMask, BOOL fForceIt, ITEMID idDirty, LPRECT lpUpdateRect) { LPOBJECT lpBase, lpObject; int iWidth, iHeight, depth, y, iImageWidth, iImageHeight; LPTR lpDataBuf, lpMaskPtr; RECT rFloaters, rMask, rTemp; BOOL fNewMask; LPMASK lpMask; UNDO_TYPE UndoType; AstralSetRectEmpty(lpUpdateRect); // get rectangle for all floating objects if (!GetFloatingObjectsRect(&rFloaters)) return(FALSE); // Get base object lpBase = GetBase(); // get pixmap information PixmapGetInfo(&lpBase->Pixmap, PMT_EDIT, &iImageWidth, &iImageHeight, &depth, NULL); BoundRect(&rFloaters, 0, 0, iImageWidth-1, iImageHeight-1); iWidth = RectWidth(&rFloaters); iHeight = RectHeight(&rFloaters); // allocate buffer for alpha channel combining if (!(lpDataBuf = Alloc((long)iWidth*depth))) { Message(IDS_EMEMALLOC); return(FALSE); } lpMask = NULL; if (fCreateMask) { lpMask = GetMaskEx(OFF, Control.NoUndo, &fNewMask, &rTemp); AstralUnionRect(lpUpdateRect, lpUpdateRect, &rTemp); } // do it to it ProgressBegin(lpMask != NULL ? 2 : 1, idDirty-IDS_UNDOFIRST+IDS_PROGFIRST); if (!fNoUndo) { UndoType = UT_DATA|UT_DELETEOBJECTS; if (lpMask) { if (fNewMask) UndoType |= UT_CREATEMASK; else UndoType |= UT_ALPHA; } if (!ImgEditInit(this, ET_OBJECT, UndoType, lpBase)) { if (!fForceIt) { ProgressEnd(); FreeUp(lpDataBuf); return(FALSE); } } } // do it to it ProgressBegin(1, 0); for (y = rFloaters.top; y <= rFloaters.bottom; ++y) { AstralClockCursor(y-rFloaters.top, iHeight, NO); ImgGetLine(this, NULL, rFloaters.left, y, iWidth, lpDataBuf); PixmapWrite(&lpBase->Pixmap, PMT_EDIT, rFloaters.left, y, iWidth, lpDataBuf, iWidth); } ProgressEnd(); if (lpMask && (lpObject = GetNextObject(lpBase, YES, NO))) { ProgressBegin(1, 0); for (y = rFloaters.top; y <= rFloaters.bottom; ++y) { AstralClockCursor(y-rFloaters.top, iHeight, NO); lpMaskPtr = PixmapPtr(&lpMask->Pixmap, PMT_EDIT, rFloaters.left, y, YES); if (!lpMaskPtr) continue; ImgMaskLoad(this, lpObject, NULL, rFloaters.left, y, iWidth, lpDataBuf, NO, CR_OR, 0, 0); CombineData(lpDataBuf, lpMaskPtr, iWidth, NO, CR_OR); } MaskRectUpdate(lpMask, &rMask); ProgressEnd(); } FreeUp(lpDataBuf); GetObjectMarqueeRect(this, &rTemp); AstralUnionRect(lpUpdateRect, lpUpdateRect, &rTemp); lpObject = lpBase; while (lpObject = GetNextObject(lpObject, YES, NO)) { // always let undo stuff initialize this // lpObject->fUndoDeleted = NO; lpObject->fDeleted = YES; } //DeleteObjects((LPOBJECT)lpBase->lpNext, NO); if (!fNoUndo) ImgEditedObject(this, lpBase, idDirty, &rFloaters); else fChanged = YES; //if ( Tool.hRibbon ) // SendMessage( Tool.hRibbon, WM_CONTROLENABLE, 0, 0L ); ProgressEnd(); //SetupMiniViews(NULL, NO); return(TRUE); }
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 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); }
BOOL ReadObjData( LPSTR lpFileName, LPOBJECTLIST lpObjList, int outDepth, LPINT lpDataType, LPRECT lpScaleRect, LPINT lpFullFileX, LPINT lpFullFileY, LPINT lpFullResolution) /************************************************************************/ { LPFRAME lpFrame; LPOBJECT lpObject; int ifh; LPLONG lngptr; LPWORD shtptr; int nObjects, i, idFileType, nPasses; WORD wBytes, wByteOrder, wVersion; long lObjSize, lObjStart; LPOBJOFFSETS lpOffsets; OBJECT Obj; LFIXED xrate, yrate; int opix, olin, baseW, baseH; LPRECT lpLoadRect; xrate = yrate = UNITY; lpOffsets = NULL; if ( !lpObjList ) return( FALSE ); lpObjList->lpHead = lpObjList->lpTail = NULL; if ( (ifh = _lopen(lpFileName, OF_READ)) < 0) { Message( IDS_EOPEN, lpFileName ); return( FALSE ); } // Read in header info wBytes = OBJ_HDR_SIZE; if ( _lread(ifh, LineBuffer[0], wBytes) != wBytes ) goto BadRead; shtptr = (LPWORD)LineBuffer[0]; wByteOrder = GetNextWord(&shtptr); /* byte order is LSB,MSB */ if (wByteOrder != TIF_II && wByteOrder != TIF_MM) goto BadRead; wVersion = GetNextWord(&shtptr); /* Version Number */ nObjects = GetNextWord(&shtptr); /* Number of Objects */ lngptr = (LPLONG)shtptr; lObjSize = GetNextLong(&lngptr); /* size of object data */ lObjStart = GetNextLong(&lngptr); /* start of object data */ if (!(lpOffsets = (LPOBJOFFSETS)Alloc(sizeof(OBJOFFSETS)*nObjects))) { Message(IDS_EMEMALLOC); return(FALSE); } _llseek (ifh, lObjStart, 0); wBytes = (WORD)lObjSize; nPasses = 0; for (i = 0; i < nObjects; ++i) { if ( _lread(ifh, LineBuffer[0], wBytes) != wBytes ) goto BadRead; shtptr = (LPWORD)LineBuffer[0]; Obj.ObjectType = (OBJECT_TYPE)GetNextWord(&shtptr); Obj.rObject.left = GetNextWord(&shtptr); Obj.rObject.top = GetNextWord(&shtptr); Obj.rObject.right = GetNextWord(&shtptr); Obj.rObject.bottom = GetNextWord(&shtptr); Obj.Opacity = GetNextWord(&shtptr); Obj.MergeMode = (MERGE_MODE)GetNextWord(&shtptr); Obj.wGroupID = GetNextWord(&shtptr); if (i==0 && lpScaleRect) { opix = RectWidth(lpScaleRect); olin = RectHeight(lpScaleRect); baseW = RectWidth(&Obj.rObject); baseH = RectHeight(&Obj.rObject); xrate = ScaleToFit(&opix, &olin, baseW, baseH); if (opix > baseW || olin > baseH) { // No upsizing allowed opix = baseW; olin = baseH; } xrate = FGET( opix, baseW ); yrate = FGET( olin, baseH ); } // scale the object rect Obj.rObject.left = FMUL(Obj.rObject.left, xrate); Obj.rObject.top = FMUL(Obj.rObject.top, yrate); Obj.rObject.right = FMUL(Obj.rObject.right, xrate); Obj.rObject.bottom = FMUL(Obj.rObject.bottom, yrate); if (!(lpObject = ObjCreateFromFrame(ST_PERMANENT, NULL, NULL, &Obj.rObject, Control.NoUndo))) { Message(IDS_EMEMALLOC); goto BadRead; } idFileType = GetNextWord(&shtptr); lpOffsets[i].bInvert = GetNextWord(&shtptr); lpOffsets[i].rMask.left = GetNextWord(&shtptr); lpOffsets[i].rMask.top = GetNextWord(&shtptr); lpOffsets[i].rMask.right = GetNextWord(&shtptr); lpOffsets[i].rMask.bottom = GetNextWord(&shtptr); // scale the mask rect lpOffsets[i].rMask.left = FMUL(lpOffsets[i].rMask.left, xrate); lpOffsets[i].rMask.top = FMUL(lpOffsets[i].rMask.top, yrate); lpOffsets[i].rMask.right = FMUL(lpOffsets[i].rMask.right, xrate); lpOffsets[i].rMask.bottom = FMUL(lpOffsets[i].rMask.bottom, yrate); lngptr = (LPLONG)shtptr; lpOffsets[i].lDataOffset = GetNextLong(&lngptr); lpOffsets[i].lAlphaOffset = GetNextLong(&lngptr); shtptr = (LPWORD)lngptr; // versions after 1.1 saved selected state if (wVersion == 0x0101) Obj.fSelected = NO; else Obj.fSelected = GetNextWord(&shtptr); if (wVersion < 0x0103 || lObjSize == 41) { Obj.ObjectDataID = OBJECT_DATA_NONE; Obj.dwObjectData = 0; } else { Obj.ObjectDataID = GetNextWord(&shtptr); Obj.dwObjectData = *(LPDWORD)shtptr; shtptr += 2; } lpObject->ObjectType = Obj.ObjectType; lpObject->Opacity = Obj.Opacity; lpObject->MergeMode = Obj.MergeMode; lpObject->wGroupID = Obj.wGroupID; lpObject->fSelected = Obj.fSelected; lpObject->ObjectDataID = Obj.ObjectDataID; lpObject->dwObjectData = Obj.dwObjectData; ObjAddTail(lpObjList, (LPPRIMOBJECT)lpObject); ++nPasses; if (lpOffsets[i].lAlphaOffset) ++nPasses; } ProgressBegin(nPasses, 0); lpObject = NULL; i = 0; while (lpObject = (LPOBJECT)ObjGetNextObject(lpObjList, (LPPRIMOBJECT)lpObject, YES)) { if (lpScaleRect && i!=0) { lpLoadRect = &lpObject->rObject; } else lpLoadRect = lpScaleRect; _llseek (ifh, lpOffsets[i].lDataOffset, 0); lpFrame = ReadTiffData(ifh, lpFileName, outDepth, lpDataType, NO/*bReadOnly*/, lpLoadRect, NO, lpFullFileX, lpFullFileY, lpFullResolution); if (i == 0) { lpDataType = NULL; lpFullFileX = NULL; lpFullFileY = NULL; lpFullResolution = NULL; } if (!lpFrame) goto BadRead; PixmapSetup(&lpObject->Pixmap, lpFrame, Control.NoUndo); if (!lpOffsets[i].lAlphaOffset) { ++i; continue; } _llseek (ifh, lpOffsets[i].lAlphaOffset, 0); lpFrame = ReadTiffData(ifh, lpFileName, outDepth, lpDataType, NO/*bReadOnly*/, lpLoadRect, NO, NULL, NULL, NULL); if (!lpFrame) goto BadRead; lpObject->lpAlpha = MaskCreate(lpFrame, 0, 0, OFF, Control.NoUndo); if (!lpObject->lpAlpha) { Message(IDS_EMEMALLOC); goto BadRead; } lpObject->lpAlpha->bInvert = lpOffsets[i].bInvert; lpObject->lpAlpha->rMask = lpOffsets[i].rMask; ++i; } if ( lpOffsets ) FreeUp( (LPTR)lpOffsets ); _lclose(ifh); ProgressEnd(); return( TRUE ); BadRead: while (lpObject = (LPOBJECT)ObjGetNextObject(lpObjList, NULL, YES)) { ObjUnlinkObject(lpObjList, (LPPRIMOBJECT)lpObject); ObjFreeUp(lpObject); } _lclose(ifh); if ( lpOffsets ) FreeUp( (LPTR)lpOffsets ); if (nPasses) ProgressEnd(); Message( IDS_EREAD, lpFileName ); return( FALSE ); }
int objwrt(LPIMAGE lpImage, LPSTR lpFileName, int idFileType, LPRECT lpRect, int flag, BOOL fCompressed) /************************************************************************/ { LPOBJECT lpObject; int ofp; LPLONG lngptr; LPWORD shtptr; FNAME temp; BOOL bEscapable; int nObjects, i, nPasses; long lObjStart; WORD wBytes; LPOBJOFFSETS lpOffsets; if (!lpImage) return( -1 ); lpObject = NULL; nObjects = nPasses = 0; while (lpObject = ImgGetNextObject(lpImage, lpObject, YES, NO)) { if (lpObject->lpAlpha && (nObjects || Save.bSaveMask)) ++nPasses; ++nObjects; ++nPasses; } if (!(lpOffsets = (LPOBJOFFSETS)Alloc(sizeof(OBJOFFSETS)*nObjects))) { Message(IDS_EMEMALLOC); return(-1); } bEscapable = !FileExists(lpFileName); #ifdef _MAC // The Mac file system can't handle the following pathname: // Bad ---> "DIR:FILE.EXT" // Needs to be -> ":DIR:FILE.EXT" // Add the additional ':' here to specify starting at our directory. if (lpFileName[0] != ':') { STRING szName; lstrcpy(szName, lpFileName); lstrcpy(lpFileName+1, szName); lpFileName[0] = ':'; } #endif if ((ofp = _lcreat(lpFileName,0)) < 0) { FreeUp((LPTR)lpOffsets); Message( IDS_EOPEN, lpFileName ); return(-1); } ProgressBegin(nPasses, 0); // Fill in header info shtptr = (LPWORD)LineBuffer[0]; SetNextWord(&shtptr, 0x4949); /* byte order is LSB,MSB */ SetNextWord(&shtptr, OBJ_VERSION); /* Version Number */ SetNextWord(&shtptr, ImgCountObjects(lpImage)); /* Number of Objects */ lngptr = (LPLONG)shtptr; SetNextLong(&lngptr, OBJ_DATA_SIZE); /* size of object data */ SetNextLong(&lngptr, OBJ_HDR_SIZE); /* start of object data */ // Write out header info wBytes = (LPTR)lngptr - (LPTR)LineBuffer[0]; if ( _lwrite(ofp, LineBuffer[0], wBytes) != wBytes ) goto BadWrite; lObjStart = _llseek (ofp, 0L, 1); wBytes = OBJ_DATA_SIZE * ImgCountObjects(lpImage); if ( _lwrite(ofp, LineBuffer[0], wBytes) != wBytes ) goto BadWrite; lpObject = NULL; i = 0; while (lpObject = ImgGetNextObject(lpImage, lpObject, YES, NO)) { lpOffsets[i].lDataOffset = _llseek (ofp, 0L, 1); lpOffsets[i].lAlphaOffset = 0L; if (TiffWriteFrame(ofp, lpFileName, NULL, lpObject->Pixmap.EditFrame, NULL, flag, fCompressed, bEscapable) < 0) goto BadWrite; if (!lpObject->lpAlpha || (!i && !Save.bSaveMask)) { ++i; continue; } lpOffsets[i].lAlphaOffset = _llseek (ofp, 0L, 1); if (TiffWriteFrame(ofp, lpFileName, NULL, lpObject->lpAlpha->Pixmap.EditFrame, NULL, IDC_SAVECT, fCompressed, bEscapable) < 0) goto BadWrite; ++i; } // fill in object data information and write it _llseek (ofp, lObjStart, 0); lpObject = NULL; i = 0; while (lpObject = ImgGetNextObject(lpImage, lpObject, YES, NO)) { shtptr = (LPWORD)LineBuffer[0]; SetNextWord(&shtptr, lpObject->ObjectType); SetNextWord(&shtptr, lpObject->rObject.left); SetNextWord(&shtptr, lpObject->rObject.top); SetNextWord(&shtptr, lpObject->rObject.right); SetNextWord(&shtptr, lpObject->rObject.bottom); SetNextWord(&shtptr, lpObject->Opacity); SetNextWord(&shtptr, lpObject->MergeMode); SetNextWord(&shtptr, lpObject->wGroupID); SetNextWord(&shtptr, idFileType); if (lpObject->lpAlpha) { SetNextWord(&shtptr, lpObject->lpAlpha->bInvert); SetNextWord(&shtptr, lpObject->lpAlpha->rMask.left); SetNextWord(&shtptr, lpObject->lpAlpha->rMask.top); SetNextWord(&shtptr, lpObject->lpAlpha->rMask.right); SetNextWord(&shtptr, lpObject->lpAlpha->rMask.bottom); } else { SetNextWord(&shtptr, 0); SetNextWord(&shtptr, 0); SetNextWord(&shtptr, 0); SetNextWord(&shtptr, 0); SetNextWord(&shtptr, 0); } lngptr = (LPLONG)shtptr; SetNextLong(&lngptr, lpOffsets[i].lDataOffset); SetNextLong(&lngptr, lpOffsets[i].lAlphaOffset); shtptr = (LPWORD)lngptr; SetNextWord(&shtptr, lpObject->fSelected); SetNextWord(&shtptr, lpObject->ObjectDataID); lngptr = (LPLONG)shtptr; SetNextLong(&lngptr, lpObject->dwObjectData); shtptr = (LPWORD)lngptr; ++i; // Write out Object data wBytes = OBJ_DATA_SIZE;; if ( _lwrite(ofp, LineBuffer[0], wBytes) != wBytes ) goto BadWrite; } FreeUp( (LPTR)lpOffsets ); _lclose(ofp); ProgressEnd(); return( 0 ); BadWrite: _lclose(ofp); FreeUp( (LPTR)lpOffsets ); lstrcpy(temp,lpFileName); FileDelete(temp); if (nPasses) ProgressEnd(); return( -1 ); }
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 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 ); }
int TiffWriteFrame( int oFile, LPSTR lpFileName, LPOBJECT lpObject, LPFRAME lpFrame, LPRECT lpRect, int flag, BOOL fCompressed, BOOL bEscapable) { TAG tag; int y, bpl, npix, nlin, ofp; LPLONG lngptr,boffptr; LPWORD shtptr; DWORD byteoffset; WORD i, numtags, photomet, samples; BYTE bpp; LPWORD lpRed, lpGreen, lpBlue; RGBS RGBmap[256]; LPTR lp, lpBuffer, lpOutputPointer, lpImgScanline; FNAME temp; RECT rSave; BOOL compressInit; #ifdef STATIC16 // only in new framelib CFrameTypeConvert FrameTypeConvert; FRMTYPEINFO SrcTypeInfo; FRMTYPEINFO DstTypeInfo; #endif lpBuffer = NULL; lpImgScanline = NULL; if (!lpFrame) return( -1 ); ProgressBegin(1,0); if ((ofp = oFile) < 0) bEscapable = !FileExists(lpFileName); if ((ofp = oFile) < 0 && (ofp = _lcreat(lpFileName,0)) < 0) { Message( IDS_EWRITE, lpFileName ); goto Exit; } if (lpRect) rSave = *lpRect; else { rSave.top = rSave.left = 0; rSave.bottom = FrameYSize(lpFrame)-1; rSave.right = FrameXSize(lpFrame)-1; } npix = RectWidth(&rSave); nlin = RectHeight(&rSave); switch(flag) { case IDC_SAVELA : case IDC_SAVESP : bpp = 1; bpl = ((npix + 7) / 8); numtags = 11; photomet = 1; samples = 1; break; case IDC_SAVECT : bpp = 8; bpl = npix; numtags = 11; photomet = 1; samples = 1; break; case IDC_SAVE4BITCOLOR : case IDC_SAVE8BITCOLOR : bpp = 8; bpl = npix; numtags = 12; photomet = 3; samples = 1; break; case IDC_SAVE24BITCOLOR : bpp = 24; bpl = npix * 3; numtags = 11; photomet = 2; samples = 3; break; case IDC_SAVE32BITCOLOR : bpp = 32; bpl = npix * 4; numtags = 11; photomet = 5; samples = 4; break; default : goto Exit; break; } compressInit = NO; if ( bpp == 1 ) { AllocLines( &lpBuffer, 1, npix, 2 ); AllocLines( &lpImgScanline, 1, npix, 1 ); } else { AllocLines( &lpBuffer, 1, max(bpl, FrameByteWidth(lpFrame)), 1 ); AllocLines( &lpImgScanline, 1, max(bpl, FrameByteWidth(lpFrame)), 1 ); } if ( !lpBuffer || !lpImgScanline ) { Message( IDS_EMEMALLOC ); _lclose( ofp ); goto Exit; } /* first location where any extra data can be stored */ /* 10 byte header + all tag data (12 bytes each) + 4 bytes (null ifd) */ byteoffset = 10 + (numtags * sizeof(TAG)) + 4; shtptr = (LPWORD)LineBuffer[0]; SetNextWord(&shtptr, 0x4949); /* byte order is LSB,MSB */ SetNextWord(&shtptr, 0x2a); /* tiff version number */ SetNextWord(&shtptr, 8); /* byte offset to first image file directory LSW */ SetNextWord(&shtptr, 0); /* byte offset to first image file directory MSW */ SetNextWord(&shtptr, numtags); /* number of entries in IFD */ tag.tagno = 0xff; /* tag 0xff, subfile type */ tag.type = 3; /* field type is short */ tag.length = 1; /* number of values */ tag.value = 1; /* value */ #ifdef _MAC SwapTag(&tag); #endif lmemcpy((LPTR)shtptr,(LPTR)&tag.tagno,12); shtptr += 6; tag.tagno = 0x100; /* tag 0x100, number of pixels */ tag.type = 3; /* field type is short */ tag.length = 1; /* number of values */ tag.value = npix; /* value */ #ifdef _MAC SwapTag(&tag); #endif lmemcpy((LPTR)shtptr,(LPTR)&tag.tagno,12); shtptr += 6; tag.tagno = 0x101; /* tag 0x101, number of lines */ tag.type = 3; /* field type is short */ tag.length = 1; /* number of values */ tag.value = nlin; /* value */ #ifdef _MAC SwapTag(&tag); #endif lmemcpy((LPTR)shtptr,(LPTR)&tag.tagno,12); shtptr += 6; tag.tagno = 0x102; /* tag 0x102, bits per sample */ tag.type = 3; /* field type is short */ tag.length = samples; /* number of values */ if ( samples == 3 || samples == 4) { tag.value = byteoffset; /* deferred value */ byteoffset += (samples*sizeof(short)); } else tag.value = bpp; /* value */ #ifdef _MAC SwapTag(&tag); #endif lmemcpy((LPTR)shtptr,(LPTR)&tag.tagno,12); shtptr += 6; tag.tagno = 0x103; /* tag 0x103, compression */ tag.type = 3; /* field type is short */ tag.length = 1; /* number of values */ tag.value = (fCompressed ? 5:1); /* value */ #ifdef _MAC SwapTag(&tag); #endif lmemcpy((LPTR)shtptr,(LPTR)&tag.tagno,12); shtptr += 6; tag.tagno = 0x106; /* tag 0x106,photometric inter.(0 = black) */ tag.type = 3; /* field type is short */ tag.length = 1; /* number of values */ tag.value = photomet; /* value */ #ifdef _MAC SwapTag(&tag); #endif lmemcpy((LPTR)shtptr,(LPTR)&tag.tagno,12); shtptr += 6; tag.tagno = 0x111; /* tag 0x111, strip byte offsets */ tag.type = 4; /* field type is long */ tag.length = 1; /* number of values */ tag.value = 0; /* dummy location of the start of image data */ #ifdef _MAC SwapTag(&tag); #endif lmemcpy((LPTR)shtptr,(LPTR)&tag.tagno,12); boffptr = (LPLONG)(shtptr+4); // make boffptr point at tag.value shtptr += 6; tag.tagno = 0x115; /* tag 0x115, samples per pixel*/ tag.type = 3; /* field type is short */ tag.length = 1; /* number of values */ tag.value = samples; /* value */ #ifdef _MAC SwapTag(&tag); #endif lmemcpy((LPTR)shtptr,(LPTR)&tag.tagno,12); shtptr += 6; tag.tagno = 0x11a; /* tag 0x11a, xresolution */ tag.type = 5; /* field type is rational */ tag.length = 1; /* number of values */ tag.value = byteoffset; /* deferered value */ byteoffset += 8; #ifdef _MAC SwapTag(&tag); #endif lmemcpy((LPTR)shtptr,(LPTR)&tag.tagno,12); shtptr += 6; tag.tagno = 0x11b; /* tag 0x11b, yresolution */ tag.type = 5; /* field type is rational */ tag.length = 1; /* number of values */ tag.value = byteoffset; /* deferred value */ byteoffset += 8; #ifdef _MAC SwapTag(&tag); #endif lmemcpy((LPTR)shtptr,(LPTR)&tag.tagno,12); shtptr += 6; tag.tagno = 0x11c; /* tag 0x11c, planar configuration */ tag.type = 3; /* field type is short */ tag.length = 1; /* number of values */ tag.value = 1; /* value */ #ifdef _MAC SwapTag(&tag); #endif lmemcpy((LPTR)shtptr,(LPTR)&tag.tagno,12); shtptr += 6; if ( photomet == 3 ) // Palette color map { tag.tagno = 0x140; /* tag 0x140, colormap */ tag.type = 3; /* field type is short */ tag.length = 3*256; /* number of values */ tag.value = byteoffset; /* value */ byteoffset += (2*3*256); #ifdef _MAC SwapTag(&tag); #endif lmemcpy((LPTR)shtptr,(LPTR)&tag.tagno,12); shtptr += 6; } // Copy the NULL Image File Directory pointer SetNextWord(&shtptr, 0); /* pointer to next IFD */ SetNextWord(&shtptr, 0); // Copy out the Bits Per Sample, if multiple samples if ( samples == 3 ) // The bits per pixel per sample { SetNextWord(&shtptr, 8); SetNextWord(&shtptr, 8); SetNextWord(&shtptr, 8); } // Copy out the Bits Per Sample, if multiple samples if ( samples == 4 ) // The bits per pixel per sample { SetNextWord(&shtptr, 8); SetNextWord(&shtptr, 8); SetNextWord(&shtptr, 8); SetNextWord(&shtptr, 8); } // Copy out the X and Y resolution fields lngptr = (LPLONG)shtptr; #ifdef PPVIDEO SetNextLong(&lngptr, FrameResolution(lpFrame) * 2); /* xreso numerator */ SetNextLong(&lngptr, 2); /* xreso denominator */ SetNextLong(&lngptr, FrameResolution(lpFrame) * 2); /* yreso numerator */ SetNextLong(&lngptr, 2); /* yreso denominator */ #else SetNextLong(&lngptr, FrameResolution(lpFrame)); /* xreso numerator */ SetNextLong(&lngptr, 1); /* xreso denominator */ SetNextLong(&lngptr, FrameResolution(lpFrame)); /* yreso numerator */ SetNextLong(&lngptr, 1); /* yreso denominator */ #endif *boffptr = byteoffset; #ifdef _MAC swapl((LPDWORD)boffptr); #endif // Write out the tags, the bpp, and the resolutions i = (LPTR)lngptr - (LPTR)LineBuffer[0]; if ( _lwrite(ofp, LineBuffer[0], i) != i ) goto BadWrite; // Write the color palette, if necessary if ( photomet == 3 ) // Palette color map { if (!OptimizeBegin(lpObject, lpFrame, RGBmap, 256, NULL /*(LPROC)AstralClockCursor*/, // No Progress report NO, Convert.fOptimize, Convert.fScatter, Convert.fDither, npix)) goto BadWrite; lpRed = (LPWORD)LineBuffer[0]; lpGreen = lpRed + 256; lpBlue = lpGreen + 256; for ( i=0; i<256; i++ ) { *lpRed++ = (WORD)RGBmap[i].red << 8; *lpGreen++ = (WORD)RGBmap[i].green << 8; *lpBlue++ = (WORD)RGBmap[i].blue << 8; } if ( _lwrite(ofp, LineBuffer[0], 2*3*256) != 2*3*256 ) goto BadWrite; } if ( fCompressed ) { if ( CompressLZW( ofp, NULL, 0 ) < 0 ) /* Initialize */ goto BadWrite; compressInit = YES; } switch(bpp) { case 1 : for( y=rSave.top; y<=rSave.bottom; y++ ) { if (AstralClockCursor( y-rSave.top, nlin, bEscapable )) goto Cancelled; if ( lpObject ) { if (!ImgGetLine( NULL, lpObject, rSave.left, y, (rSave.right - rSave.left) + 1, lpImgScanline)) goto BadRead; lp = lpImgScanline; } else { if ( !(lp = FramePointer( lpFrame, rSave.left, y, NO )) ) goto BadRead; } if (FrameDepth(lpFrame) == 0) { if (flag == IDC_SAVESP) diffuse( 0, i, 0, NULL, lp, npix, lpBuffer ); else con2la( lp, npix, lpBuffer ); } else { ConvertData( lp, FrameDepth(lpFrame), npix, lpBuffer+npix, 1 ); if ( flag == IDC_SAVESP ) diffuse( 0, i, 0, NULL, lpBuffer+npix, npix, lpBuffer ); else con2la( lpBuffer+npix, npix, lpBuffer ); } if ( fCompressed ) { if ( CompressLZW( ofp, lpBuffer, bpl ) < 0 ) goto BadWrite; } else { if ( _lwrite( ofp, (LPSTR)lpBuffer, bpl ) != bpl ) goto BadWrite; } } break; case 8 : for( y=rSave.top; y<=rSave.bottom; y++ ) { if (AstralClockCursor( y-rSave.top, nlin, bEscapable )) goto Cancelled; if ( lpObject ) { if (!ImgGetLine( NULL, lpObject, rSave.left, y, (rSave.right - rSave.left) + 1, lpImgScanline)) goto BadRead; lp = lpImgScanline; } else { if ( !(lp = FramePointer( lpFrame, rSave.left, y, NO )) ) goto BadRead; } if (FrameDepth(lpFrame) == 0) { if ( photomet == 3 ) // If we are storing palette color OptimizeData(0, y, npix, lp, lpBuffer, 1 ); else ConvertData( lp, 1, npix, lpBuffer, 1 ); } else { if ( photomet == 3 ) // If we are storing palette color OptimizeData(0, y, npix, lp, lpBuffer, FrameDepth(lpFrame)); else ConvertData( lp, FrameDepth(lpFrame), npix, lpBuffer, 1 ); } if ( fCompressed ) { if ( CompressLZW( ofp, lpBuffer, bpl ) < 0 ) goto BadWrite; } else { if ( _lwrite( ofp, (LPSTR)lpBuffer, bpl ) != bpl ) goto BadWrite; } } break; case 24 : for( y=rSave.top; y<=rSave.bottom; y++ ) { if (AstralClockCursor( y-rSave.top, nlin, bEscapable )) goto Cancelled; if ( lpObject ) { if (!ImgGetLine( NULL, lpObject, rSave.left, y, (rSave.right - rSave.left) + 1, lpImgScanline)) goto BadRead; lp = lpImgScanline; } else { if ( !(lp = FramePointer( lpFrame, rSave.left, y, NO )) ) goto BadRead; } if (FrameType(lpFrame) != FDT_RGBCOLOR) { if (FrameType(lpFrame) != FDT_LINEART) { #ifdef STATIC16 SrcTypeInfo.DataType = FrameType(lpFrame); SrcTypeInfo.ColorMap = NULL; SrcTypeInfo.DataType = FDT_RGBCOLOR; SrcTypeInfo.ColorMap = NULL; FrameTypeConvert.Init(SrcTypeInfo, DstTypeInfo, npix); FrameTypeConvert.ConvertData((LPTR)lp, (LPTR)lpBuffer, y, npix); #else FrameTypeConvert( (LPTR)lp, FrameType(lpFrame), NULL, y, (LPTR)lpBuffer, FDT_RGBCOLOR, NULL, npix); #endif } else { #ifdef STATIC16 SrcTypeInfo.DataType = FDT_GRAYSCALE; SrcTypeInfo.ColorMap = NULL; SrcTypeInfo.DataType = FDT_RGBCOLOR; SrcTypeInfo.ColorMap = NULL; FrameTypeConvert.Init(SrcTypeInfo, DstTypeInfo, npix); FrameTypeConvert.ConvertData((LPTR)lp, (LPTR)lpBuffer, y, npix); #else FrameTypeConvert( (LPTR)lp, FDT_GRAYSCALE, NULL, y, (LPTR)lpBuffer, FDT_RGBCOLOR, NULL, npix); #endif } lpOutputPointer = lpBuffer; } else { lpOutputPointer = lp; } if ( fCompressed ) { if ( CompressLZW( ofp, lpOutputPointer, bpl ) < 0 ) goto BadWrite; } else { if ( _lwrite( ofp, (LPSTR)lpOutputPointer, bpl ) != bpl ) goto BadWrite; } } break; case 32 : for( y=rSave.top; y<=rSave.bottom; y++ ) { if (AstralClockCursor( y-rSave.top, nlin, bEscapable )) goto Cancelled; if ( lpObject ) { if (!ImgGetLine( NULL, lpObject, rSave.left, y, (rSave.right - rSave.left) + 1, lpImgScanline)) goto BadRead; lp = lpImgScanline; } else { if ( !(lp = FramePointer( lpFrame, rSave.left, y, NO )) ) goto BadRead; } if (FrameType(lpFrame) != FDT_CMYKCOLOR) { if (FrameType(lpFrame) != FDT_LINEART) { #ifdef STATIC16 SrcTypeInfo.DataType = FrameType(lpFrame); SrcTypeInfo.ColorMap = NULL; SrcTypeInfo.DataType = FDT_CMYKCOLOR; SrcTypeInfo.ColorMap = NULL; FrameTypeConvert.Init(SrcTypeInfo, DstTypeInfo, npix); FrameTypeConvert.ConvertData((LPTR)lp, (LPTR)lpBuffer, y, npix); #else FrameTypeConvert( (LPTR)lp, FrameType(lpFrame), NULL, y, (LPTR)lpBuffer, FDT_CMYKCOLOR, NULL, npix); #endif } else { #ifdef STATIC16 SrcTypeInfo.DataType = FDT_GRAYSCALE; SrcTypeInfo.ColorMap = NULL; SrcTypeInfo.DataType = FDT_CMYKCOLOR; SrcTypeInfo.ColorMap = NULL; FrameTypeConvert.Init(SrcTypeInfo, DstTypeInfo, npix); FrameTypeConvert.ConvertData((LPTR)lp, (LPTR)lpBuffer, y, npix); #else FrameTypeConvert( (LPTR)lp, FDT_GRAYSCALE, NULL, y, (LPTR)lpBuffer, FDT_CMYKCOLOR, NULL, npix); #endif } lpOutputPointer = lpBuffer; } else { lpOutputPointer = lp; } if ( fCompressed ) { if ( CompressLZW( ofp, lpOutputPointer, bpl ) < 0 ) goto BadWrite; } else { if ( _lwrite( ofp, (LPSTR)lpOutputPointer, bpl ) != bpl ) goto BadWrite; } } break; } if ( compressInit ) if ( CompressLZW( ofp, NULL, 0 ) < 0 ) /* Terminate */ goto BadWrite; compressInit = NO; OptimizeEnd(); if (ofp != oFile) _lclose(ofp); if (lpBuffer) FreeUp( lpBuffer ); if (lpImgScanline) FreeUp( lpImgScanline ); ProgressEnd(); return( 0 ); BadWrite: Message( IDS_EWRITE, lpFileName ); goto BadTiff; BadRead: Message( IDS_EREAD, (LPTR)Control.RamDisk ); Cancelled: BadTiff: if ( compressInit ) if ( CompressLZW( ofp, NULL, 0 ) < 0 ) /* Terminate */ goto BadWrite; compressInit = NO; OptimizeEnd(); if (ofp != oFile) _lclose(ofp); lstrcpy(temp,lpFileName); FileDelete(temp); Exit: if (lpBuffer) FreeUp( lpBuffer ); if (lpImgScanline) FreeUp( lpImgScanline ); ProgressEnd(); return( -1 ); }
long DoCommand( HWND hWindow, WPARAM wParam, LPARAM lParam ) /***********************************************************************/ { FNAME szFileName; LPFRAME lpFrame; LPOBJECT lpObject, lpBase; RECT rect, rMask, rTemp, rAll; HWND hWnd; STRING szString; int i, idFileType, x, y, dx, dy; BOOL fDoZoom, bPrint, fHasZoom; LPSTR lpszCmdLine; HGLOBAL hMem; ITEMID idDataType; DWORD dwReturn; int NewShape; UINT wID; SoundStartID( wParam, NO/*bLoop*/, NULL/*hInstance*/ ); /* WIN16: ID = wParam ctrl handle = LOWORD(lParam) notify code = HIWORD(lParam) WIN32: ID = LOWORD(wParam) ctrl handle = lParam notify code = HIWORD(wParam) */ #ifdef WIN32 wID = LOWORD(wParam); #else wID = wParam; #endif switch (wID) { case IDM_EXIT: DeactivateTool(); PostMessage( hWndAstral, WM_CLOSE, 0, 0L); Delay (750); break; case IDM_CLOSE: DeactivateTool(); /* Check to see if the image needs to be saved */ if ( !ConfirmClose(NO,NO) ) break; CloseImage( NO, lpImage ); // Close the active image break; case IDM_ABOUT: /* Bring up the modal 'About' dialog box */ AstralDlg( NO|2, hInstAstral, hWindow, IDD_ABOUT, DlgAboutProc); break; case IDM_NEXTPAGE: if ( !lpImage ) break; DeactivateTool(); SendMessage( lpImage->hWnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0L ); break; case IDM_NEW: DeactivateTool(); SoundStartResource( "magic01", NO, NULL ); AstralCursor( IDC_WAIT ); New( Control.NewWidth, Control.NewHeight, Control.NewResolution, Control.NewDepth ); AstralCursor( NULL ); break; case IDM_OPEN: DeactivateTool(); /* Bring up the modal 'File Open' box */ if ( !(dwReturn = DoOpenDlg( hWindow, IDD_OPEN, Save.FileType, szFileName, NO )) ) break; idFileType = LOWORD( dwReturn ); Save.FileType = idFileType; PutDefaultInt( "FileType", idFileType - IDN_TIFF ); AstralImageLoad( idFileType, szFileName, MAYBE, YES ); break; case IDM_ALTOPEN: DeactivateTool(); // Command line sent from a second instance prior to it closing /* If the caller passed in a file name, try to load it or print it */ if ( !(lpszCmdLine = (LPSTR)lParam) ) break; HandleCommandLine( hWindow, lpszCmdLine, &bPrint ); break; case IDM_SAVE: DeactivateTool(); HandleSaveCommand(hWindow, wID, YES); break; case IDM_SAVEAS: DeactivateTool(); HandleSaveCommand(hWindow, wID, YES); break; case IDM_SAVESPECIAL: DeactivateTool(); HandleSaveCommand(hWindow, wID, YES); break; case IDM_SAVEWALLPAPER: DeactivateTool(); SaveWallpaper( "CRAYOLA", NO/*fTiled*/ ); break; case IDM_REVERT: if ( !lpImage ) break; DeactivateTool(); if ( lpImage->fUntitled ) // If the picture doesn't have a name, get out break; if ( ImgChanged(lpImage) ) { /* Check to see if its OK to trash changes */ if ( AstralOKCancel(IDS_OKTOREVERT, (LPSTR)lpImage->CurFile) == IDCANCEL ) break; } lstrcpy( szFileName, lpImage->CurFile ); idFileType = lpImage->FileType; fDoZoom = IsZoomed(lpImage->hWnd); fHasZoom = Window.fHasZoom; CloseImage( NO, lpImage ); // Close the active image if ( !AstralImageLoad( idFileType, szFileName, fDoZoom, YES ) ) break; break; case IDM_RECALLIMAGE0: case IDM_RECALLIMAGE1: case IDM_RECALLIMAGE2: case IDM_RECALLIMAGE3: case IDM_RECALLIMAGE4: case IDM_RECALLIMAGE5: case IDM_RECALLIMAGE6: case IDM_RECALLIMAGE7: case IDM_RECALLIMAGE8: case IDM_RECALLIMAGE9: DeactivateTool(); GetMenuString( GetMenu(hWindow), wID, szFileName, sizeof(szFileName), MF_BYCOMMAND ); i = 0; while ( szFileName[i] && szFileName[i] != ' ' ) i++; // Skip over the numeric id in the string (3. junk.tif) lstrcpy(szString, &szFileName[i+1]); GetRecallFileName(szString); AstralImageLoad( NULL, szString, MAYBE, YES ); break; case IDM_PRINT: if ( !lpImage ) break; DeactivateTool(); AstralCursor( IDC_WAIT ); DoPrintSizeInits(); SoundStartResource( "print", YES, NULL ); PrintFile( hWindow, filename(lpImage->CurFile), YES, lpImage, NULL ); SoundStop(); AstralCursor( NULL ); break; case IDM_PRINTSETUP: /* Bring up the setup dialog box for the active printer */ AstralDlg( NO|2, hInstAstral, hWindow, IDD_PRINTSETUP, DlgPrintSetupProc); break; case IDC_SOUND: SoundToggle(); break; case IDM_UNDO: if ( !lpImage ) break; DeactivateTool(); ImgEditUndo(lpImage, YES, NO); break; case IDM_CUT: case IDM_COPY: if ( !lpImage ) break; DeactivateTool(); // Create the clipboard files from the image ProgressBegin(1, IDS_PROGCOPY); if ( !ImgWriteClipOut( lpImage, NULL, NULL, &rMask, lpImage->DataType ) ) { ProgressEnd(); Message(IDS_EMEMALLOC); break; } ProgressEnd(); OpenClipboard(hWindow); EmptyClipboard(); // Passing a NULL data handle in SetClipboardData() means that // the data will be requested in a WM_RENDERFORMAT message hMem = ConstructObject( lpImage, IsRectEmpty(&rMask)? (LPRECT)NULL : (LPRECT)&rMask ); if ( pOLE ) { // Any data put on before Native will become staticly copied SetClipboardData( pOLE->cfNative, NULL ); SetClipboardData( pOLE->cfOwnerLink, hMem ); } SetClipboardData( CF_DIB, NULL ); if ( Control.DoPicture ) SetClipboardData( CF_METAFILEPICT, NULL ); if ( Control.DoBitmap ) SetClipboardData( CF_BITMAP, NULL ); SetClipboardData( CF_PALETTE, NULL ); SetClipboardData( Control.cfImage, NULL ); if ( pOLE && wID == IDM_COPY && !lpImage->fUntitled ) { // ObjectLink is retrieved during a Paste Link... SetClipboardData( pOLE->cfObjectLink, hMem ); } CloseClipboard(); if ( wID == IDM_COPY ) break; // else fall through to IDM_DELETE case IDM_DELETE: if ( !lpImage ) break; { COLORINFO ColorInfo; DeactivateTool(); ColorInfo.gray = 255; SetColorInfo( &ColorInfo, &ColorInfo, CS_GRAY ); TintFill( lpImage, &ColorInfo, 255, MM_NORMAL, wID == IDM_CUT ? IDS_UNDOCUT : IDS_UNDODELETE ); } break; case IDM_PASTE: if ( !lpImage ) break; case IDM_PASTEASNEW: if ( !OpenClipboard(hWndAstral) ) { Message( IDS_ECLIPOPEN ); break; } if ( !IsClipboardFormatAvailable(CF_DIB) && !IsClipboardFormatAvailable(CF_BITMAP) && !IsClipboardFormatAvailable(Control.cfImage) ) { Message( IDS_ECLIPOPEN ); CloseClipboard(); break; } CloseClipboard(); DeactivateTool(); // First put clipboard contents into a file(s) AstralCursor(IDC_WAIT); if ( !PasteFromClipboard( hWindow, (wID == IDM_PASTE) /*fNeedMask*/ ) ) { AstralCursor(NULL); Message(IDS_EMEMALLOC); break; } if ( wID == IDM_PASTE ) { ProgressBegin(1, IDS_PROGPASTECLIP); TransformObjectsStart( YES/*fNewObject*/ ); if ( ImgCreateClipInObject( lpImage, NO ) ) ; ProgressEnd(); } else if ( wID == IDM_PASTEASNEW ) { if ( lpFrame = AstralFrameLoad( Names.PasteImageFile, -1, &idDataType, &idFileType) ) { if ( NewImageWindow( NULL, // lpOldFrame NULL, // Name lpFrame, // lpNewFrame idFileType, // lpImage->FileType idDataType, // lpImage->DataType FALSE, // New view? IMG_DOCUMENT, // lpImage->DocumentType NULL, // lpImage->ImageName MAYBE ) ) lpImage->fChanged = YES; } } break; case IDM_ESCAPE: if (!lpImage) break; if (lpImage->hWnd == hZoomWindow) break; if ( Tool.bActive && Tool.lpToolProc ) DestroyProc( lpImage->hWnd, 1L ); break; case IDM_SIZEUP: case IDM_SIZEDOWN: if (!Retouch.hBrush) break; SetFocus( hWindow ); // Take focus away from any controls if ( Retouch.BrushShape == IDC_BRUSHCUSTOM ) break; if ( wID == IDM_SIZEUP ) { if( bHexBrush && ( Retouch.BrushSize % 2 == 0 ) && ( Retouch.BrushSize > 6 )) Retouch.BrushSize += 2; else Retouch.BrushSize++; } else { if( bHexBrush && ( Retouch.BrushSize % 2 == 0 ) && ( Retouch.BrushSize > 6 )) Retouch.BrushSize -= 2; else Retouch.BrushSize--; } if ( Retouch.BrushSize < 1 || Retouch.BrushSize > MAX_BRUSH_SIZE ) { Retouch.BrushSize = bound( Retouch.BrushSize, 1,MAX_BRUSH_SIZE); MessageBeep(0); break; } if (lpImage) DisplayBrush(0, 0, 0, OFF); SetMgxBrushSize(Retouch.hBrush, Retouch.BrushSize); if (lpImage && Window.hCursor == Window.hNullCursor) DisplayBrush(lpImage->hWnd, 32767, 32767, ON); if ( Tool.hRibbon ) SetSlide( Tool.hRibbon, IDC_BRUSHSIZE, Retouch.BrushSize ); break; case IDM_SHAPEUP: case IDM_SHAPEDOWN: if (!Retouch.hBrush) break; SetFocus( hWindow ); // Take focus away from any controls NewShape = Retouch.BrushShape; if ( wID == IDM_SHAPEUP ) NewShape++; else NewShape--; if ( NewShape > IDC_BRUSHCUSTOM ) NewShape = IDC_BRUSHCIRCLE; if ( NewShape < IDC_BRUSHCIRCLE ) NewShape = IDC_BRUSHCUSTOM; if (lpImage) DisplayBrush(0, 0, 0, OFF); if (!SetMgxBrushShape(Retouch.hBrush, NewShape, Names.CustomBrush)) { NewShape = IDC_BRUSHCIRCLE; SetMgxBrushShape(Retouch.hBrush, NewShape, Names.CustomBrush); } Retouch.BrushShape = NewShape; if (lpImage && Window.hCursor == Window.hNullCursor) DisplayBrush(lpImage->hWnd, 32767, 32767, ON); if ( Tool.hRibbon ) { CheckComboItem( Tool.hRibbon, IDC_BRUSHSHAPE, IDC_BRUSHCIRCLE, IDC_BRUSHCUSTOMNEW, Retouch.BrushShape ); SendMessage( Tool.hRibbon, WM_CONTROLENABLE, 0, 0L ); } break; case IDM_MOVEUP: case IDM_MOVEDOWN: case IDM_MOVELEFT: case IDM_MOVERIGHT: if (!lpImage) break; lpBase = ImgGetBase(lpImage); if (ImgGetSelObject(lpImage, NULL) == lpBase) break; dx = dy = 0; if (wID == IDM_MOVEUP) --dy; if (wID == IDM_MOVEDOWN) ++dy; if (wID == IDM_MOVELEFT) --dx; if (wID == IDM_MOVERIGHT) ++dx; lpObject = NULL; while (lpObject = ImgGetSelObject(lpImage, lpObject)) { rect = lpObject->rObject; OffsetRect(&rect, dx, dy); if (!AstralIntersectRect(&rTemp, &lpBase->rObject, &rect)) break; } if (lpObject) break; AstralSetRectEmpty(&rAll); lpObject = NULL; while (lpObject = ImgGetSelObject(lpImage, lpObject)) { rect = lpObject->rObject; OffsetRect(&lpObject->rObject, dx, dy); AstralUnionRect(&rAll, &rAll, &lpObject->rObject); if (!lpObject->Pixmap.fNewFrame && EqualRect(&rect, &lpObject->rUndoObject)) lpObject->rUndoObject = lpObject->rObject; UpdateImage(&rect, TRUE); UpdateImage(&lpObject->rObject, TRUE); } if (wID == IDM_MOVEUP) { x = (rAll.left + rAll.right)/2; y = rAll.top; } else if (wID == IDM_MOVEDOWN) { x = (rAll.left + rAll.right)/2; y = rAll.bottom; } else if (wID == IDM_MOVELEFT) { x = rAll.left; y = (rAll.top + rAll.bottom)/2; } else if (wID == IDM_MOVERIGHT) { x = rAll.right; y = (rAll.top + rAll.bottom)/2; } File2Display(&x, &y); AutoScroll(lpImage->hWnd, x, y); AstralUpdateWindow(lpImage->hWnd); DisplayInfo(-1, &rAll); break; case IDM_LASTTOOL: DeactivateTool(); if ( Tool.idLast && (hWnd = AstralDlgGet(IDD_MAIN)) ) SendMessage( hWnd, WM_COMMAND, Tool.idLast, 2L); break; case IDM_PREF: // prevent problems if running animations and they change // the wave mix dll setting in preferences StopAnimation(); AstralDlg( NO|2, hInstAstral, hWindow, IDD_PREF, DlgPrefProc ); break; case IDC_VIEWLAST: // duplicate of function in the view ribbon if ( !lpImage ) break; RevertLastView(); break; // case IDC_VIEWFULL: // duplicate of function in the view ribbon // if ( !lpImage ) // break; // AstralDlg( NO, hInstAstral, hWindow, IDD_VIEWFULL, DlgFullScreenViewProc ); // break; case IDC_VIEWALL: // duplicate of function in the view ribbon if ( !lpImage ) break; ViewAll(); break; case IDC_ZOOMIN: // duplicate of function in the view ribbon if ( !lpImage ) break; if (!lpImage->lpDisplay) break; if (!lpImage->lpDisplay->ViewPercentage) break; x = ( lpImage->lpDisplay->FileRect.left + lpImage->lpDisplay->FileRect.right ) / 2; y = ( lpImage->lpDisplay->FileRect.top + lpImage->lpDisplay->FileRect.bottom ) / 2; SaveLastView(); Zoom(x,y, +100, YES, ( View.ZoomWindow ^ CONTROL ) ); break; case IDC_ZOOMOUT: // duplicate of function in the view ribbon if ( !lpImage ) break; if (!lpImage->lpDisplay) break; if (!lpImage->lpDisplay->ViewPercentage) break; x = ( lpImage->lpDisplay->FileRect.left + lpImage->lpDisplay->FileRect.right ) / 2; y = ( lpImage->lpDisplay->FileRect.top + lpImage->lpDisplay->FileRect.bottom ) / 2; SaveLastView(); Zoom(x,y, -100, YES,( View.ZoomWindow ^ CONTROL ) ); break; case IDM_HELP: Control.Hints = !Control.Hints; PutDefInt (Control.Hints,Control.Hints); break; default: return( FALSE ); } return( TRUE ); }
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); }
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 PSPrint( LPIMAGE lpImage, LPFRAME lpFrame, BYTE cSep, int xSrc, int ySrc, int dxSrc, int dySrc, int xDest, int yDest, int dxDest, int dyDest, int iPrResX, int iPrResY ) { int y, yline, ystart, ylast, x, depth; LFIXED yrate, yoffset; LPTR lpBuffer[5], p1Buf, p2Buf, p3Buf, p4Buf; LPSTR lpAngle, lpRuling; LPTR lpImageData; BOOL Negative, Asciize; STRING szAngle, szRuling; long lSize; LPFRAME lpBaseFrame; #define C_ANGLE Halftone.ScreenAngle[0] #define M_ANGLE Halftone.ScreenAngle[1] #define Y_ANGLE Halftone.ScreenAngle[2] #define K_ANGLE Halftone.ScreenAngle[3] #define C_RULING Halftone.ScreenRuling[0] #define M_RULING Halftone.ScreenRuling[1] #define Y_RULING Halftone.ScreenRuling[2] #define K_RULING Halftone.ScreenRuling[3] ProgressBegin(1,0); lpAngle = szAngle; lpRuling = szRuling; Negative = Page.Negative; Asciize = !Page.BinaryPS; PS_ID( IDS_PS_DICTDEF ); /* Send the definition of the read data function */ if ( Asciize ) { PS_ID( IDS_PS_HEXDATA ); } else { PS_ID( IDS_PS_BINDATA ); } if ( !Halftone.DoHalftoning ) goto HalftoningDone; /* Send the definition of the spot function */ if ( Halftone.DotShape == IDC_ELLIPSEDOT ) { PS_ID( IDS_PS_ELLDOT1 ); PS_ID( IDS_PS_ELLDOT2 ); } else if ( Halftone.DotShape == IDC_SQUAREDOT ) { PS_ID( IDS_PS_SQUDOT ); } else if ( Halftone.DotShape == IDC_CIRCLEDOT ) { PS_ID( IDS_PS_CIRDOT ); } else if ( Halftone.DotShape == IDC_TRIANGLEDOT ) { PS_ID( IDS_PS_TRIDOT ); } else if ( Halftone.DotShape == IDC_PROPELLERDOT ) { PS_ID( IDS_PS_PROPDOT ); } if ( Page.OutputType == IDC_PRINT_BLACKSEPS || Page.OutputType == IDC_PRINT_GRAY ) { // Setup the "image" screen angles and freqs based on the sep if ( cSep == 'C' ) { FixedAscii( C_ANGLE, lpAngle, -2 ); FixedAscii( C_RULING, lpRuling, -2 ); } else if ( cSep == 'M' ) { FixedAscii( M_ANGLE, lpAngle, -2 ); FixedAscii( M_RULING, lpRuling, -2 ); } else if ( cSep == 'Y' ) { FixedAscii( Y_ANGLE, lpAngle, -2 ); FixedAscii( Y_RULING, lpRuling, -2 ); } else //if ( cSep == 'K' || cSep == 'X' || !cSep ) { FixedAscii( K_ANGLE, lpAngle, -2 ); FixedAscii( K_RULING, lpRuling, -2 ); } PS_ID2( IDS_PS_SETSCREEN, lpRuling, lpAngle ); } else { // Setup the "colorimage" screen angles and frequencies PS_ID( IDS_PS_COLOREXT ); PS_ID( IDS_PS_STARTBLOCK ); FixedAscii( C_RULING, lpRuling, -2 ); FixedAscii( C_ANGLE, lpAngle, -2 ); PS_ID2( IDS_PS_SETSPOT, lpRuling, lpAngle ); FixedAscii( M_RULING, lpRuling, -2 ); FixedAscii( M_ANGLE, lpAngle, -2 ); PS_ID2( IDS_PS_SETSPOT, lpRuling, lpAngle ); FixedAscii( Y_RULING, lpRuling, -2 ); FixedAscii( Y_ANGLE, lpAngle, -2 ); PS_ID2( IDS_PS_SETSPOT, lpRuling, lpAngle ); FixedAscii( K_RULING, lpRuling, -2 ); FixedAscii( K_ANGLE, lpAngle, -2 ); PS_ID2( IDS_PS_SETSPOT, lpRuling, lpAngle ); PS_ID( IDS_PS_SETCOLORSCREEN ); PS_ID( IDS_PS_ENDBLOCK ); PS_ID( IDS_PS_STARTBLOCK ); FixedAscii( K_RULING, lpRuling, -2 ); FixedAscii( K_ANGLE, lpAngle, -2 ); PS_ID2( IDS_PS_SETSCREEN, lpRuling, lpAngle ); PS_ID( IDS_PS_ENDBLOCK ); PS_ID( IDS_PS_IFELSE ); } HalftoningDone: // Setup a null transfer curve unless doing seps w/black ink (image operator) if ( Page.OutputType == IDC_PRINT_BLACKSEPS ) { PS_ID( IDS_PS_BLACKSEPS ); } else if ( Page.OutputType == IDC_PRINT_COLORSEPS ) { PS_ID( IDS_PS_COLORSEPS ); } else { PS_ID( IDS_PS_NOINVERT ); } PS_ID( IDS_PS_CHECKINVERT ); /* Send the destination point (x,y) in spots */ PS_ID2( IDS_PS_TRANSLATE, xDest, yDest ); /* Send the destination size (w,h) in spots */ PS_ID2( IDS_PS_SCALE, dxDest, dyDest ); if (lpImage) lpBaseFrame = ImgGetBaseEditFrame(lpImage); else lpBaseFrame = lpFrame; /* Compute how many pixels we're going to send */ /* Never send more than 16 pixels per halftone grid (or 4/grid in x and y) */ if (depth = FrameDepth( lpBaseFrame )) { if ( iPrResX < 600 ) dxDest /= 4; else dxDest /= 8; if ( iPrResY < 600 ) dyDest /= 4; else dyDest /= 8; } if (depth == 0) depth = 1; /* Let the printer do any upsizing */ if ( dySrc < dyDest ) { yrate = UNITY; dxDest = dxSrc; dyDest = dySrc; } else yrate = FGET( dySrc, dyDest ); /* Send the definition for the line buffers */ PS_ID1( IDS_PS_LINE1, dxDest ); PS_ID1( IDS_PS_LINE2, dxDest ); PS_ID1( IDS_PS_LINE3, dxDest ); PS_ID1( IDS_PS_LINE4, dxDest ); PS_ID1( IDS_PS_LINE5, dxDest ); if ( cSep ) // Plane at a time { // cSep is either 'C', 'M', 'Y', 'K', 'X'(gray) or NULL if ( Page.OutputType == IDC_PRINT_COLORSEPS ) { PS_ID( IDS_PS_DOCOLORSEPDEF ); } else { PS_ID( IDS_PS_NOCOLORSEPDEF ); } PS_ID( IDS_PS_DOIMAGEDEF ); PS_ID( IDS_PS_COLORSEPVAL ); // Start color image proc PS_ID( IDS_PS_STARTBLOCK ); PS_ID( IDS_PS_STARTBLOCK ); if ( cSep == 'C' ) { PS_ID( IDS_PS_SEPCYAN ); } else if ( cSep == 'M' ) { PS_ID( IDS_PS_SEPMAGENTA ); } else if ( cSep == 'Y' ) { PS_ID( IDS_PS_SEPYELLOW ); } else if ( cSep == 'K' || cSep == 'X' ) { PS_ID( IDS_PS_SEPBLACK ); } PS_ID( IDS_PS_COLORIMAGE4 ); PS_ID( IDS_PS_ENDBLOCK ); PS_ID( IDS_PS_ENDBLOCK ); // Start gray image proc PS_ID( IDS_PS_STARTBLOCK ); PS_ID( IDS_PS_STARTBLOCK ); PS_ID( IDS_PS_GETLINE1 ); PS_ID( IDS_PS_IMAGE ); PS_ID( IDS_PS_ENDBLOCK ); PS_ID( IDS_PS_ENDBLOCK ); PS_ID( IDS_PS_IFELSE ); PS_ID( IDS_PS_DEF ); } else if ( Page.Type == IDC_PRINTER_IS_CMYK ) { if (Page.OutputType == IDC_PRINT_COLORGRAY) { PS_ID( IDS_PS_DOIMAGEDEF ); PS_ID( IDS_PS_COLOREXT ); // Start color image proc PS_ID( IDS_PS_STARTBLOCK ); PS_ID( IDS_PS_STARTBLOCK ); PS_ID( IDS_PS_GETLINE1 ); PS_ID( IDS_PS_GETLINE2 ); PS_ID( IDS_PS_GETLINE3 ); PS_ID( IDS_PS_STARTBLOCK ); PS_ID( IDS_PS_GETLINE4 ); PS_ID( IDS_PS_GETLINE5 ); PS_ID( IDS_PS_POP ); PS_ID( IDS_PS_ENDBLOCK ); PS_ID( IDS_PS_COLORIMAGE4 ); PS_ID( IDS_PS_ENDBLOCK ); PS_ID( IDS_PS_ENDBLOCK ); // Start gray image proc PS_ID( IDS_PS_STARTBLOCK ); PS_ID( IDS_PS_STARTBLOCK ); PS_ID( IDS_PS_STARTBLOCK ); PS_ID( IDS_PS_DUMPLINE1 ); PS_ID( IDS_PS_DUMPLINE2 ); PS_ID( IDS_PS_DUMPLINE3 ); PS_ID( IDS_PS_STARTBLOCK ); PS_ID( IDS_PS_GETLINE4 ); PS_ID( IDS_PS_GETLINE5 ); PS_ID( IDS_PS_ENDBLOCK ); PS_ID( IDS_PS_IMAGE ); PS_ID( IDS_PS_ENDBLOCK ); PS_ID( IDS_PS_ENDBLOCK ); PS_ID( IDS_PS_ENDBLOCK ); PS_ID( IDS_PS_IFELSE ); PS_ID( IDS_PS_DEF ); } else { PS_ID( IDS_PS_DOIMAGEDEF ); PS_ID( IDS_PS_COLOREXT ); // Start color image proc PS_ID( IDS_PS_STARTBLOCK ); PS_ID( IDS_PS_STARTBLOCK ); PS_ID( IDS_PS_GETLINE1 ); PS_ID( IDS_PS_GETLINE2 ); PS_ID( IDS_PS_GETLINE3 ); PS_ID( IDS_PS_GETLINE4 ); PS_ID( IDS_PS_COLORIMAGE4 ); PS_ID( IDS_PS_ENDBLOCK ); PS_ID( IDS_PS_ENDBLOCK ); // Start gray image proc PS_ID( IDS_PS_STARTBLOCK ); PS_ID( IDS_PS_STARTBLOCK ); PS_ID( IDS_PS_STARTBLOCK ); PS_ID( IDS_PS_DUMPLINE1 ); PS_ID( IDS_PS_DUMPLINE2 ); PS_ID( IDS_PS_DUMPLINE3 ); PS_ID( IDS_PS_GETLINE4 ); PS_ID( IDS_PS_ENDBLOCK ); PS_ID( IDS_PS_NOIMAGE ); PS_ID( IDS_PS_ENDBLOCK ); PS_ID( IDS_PS_ENDBLOCK ); PS_ID( IDS_PS_IFELSE ); PS_ID( IDS_PS_DEF ); } } else if ( Page.Type == IDC_PRINTER_IS_RGB ) { PS_ID( IDS_PS_DOIMAGEDEF ); PS_ID( IDS_PS_COLOREXT ); // Start color image proc PS_ID( IDS_PS_STARTBLOCK ); PS_ID( IDS_PS_STARTBLOCK ); PS_ID( IDS_PS_GETLINE1 ); PS_ID( IDS_PS_GETLINE2 ); PS_ID( IDS_PS_GETLINE3 ); if ( Page.OutputType == IDC_PRINT_COLORGRAY ) { PS_ID( IDS_PS_DUMPLINE4 ); } PS_ID( IDS_PS_COLORIMAGE3 ); PS_ID( IDS_PS_ENDBLOCK ); PS_ID( IDS_PS_ENDBLOCK ); // Start gray image proc PS_ID( IDS_PS_STARTBLOCK ); PS_ID( IDS_PS_STARTBLOCK ); PS_ID( IDS_PS_STARTBLOCK ); PS_ID( IDS_PS_DUMPLINE1 ); PS_ID( IDS_PS_DUMPLINE2 ); if ( Page.OutputType == IDC_PRINT_COLORGRAY ) { PS_ID( IDS_PS_DUMPLINE3 ); PS_ID( IDS_PS_GETLINE4 ); PS_ID( IDS_PS_ENDBLOCK ); PS_ID( IDS_PS_IMAGE ); } else { PS_ID( IDS_PS_GETLINE3 ); PS_ID( IDS_PS_ENDBLOCK ); PS_ID( IDS_PS_NOIMAGE ); } PS_ID( IDS_PS_ENDBLOCK ); PS_ID( IDS_PS_ENDBLOCK ); PS_ID( IDS_PS_IFELSE ); PS_ID( IDS_PS_DEF ); } /* Send the inline image's size, packing, and transform */ PS_ID5( IDS_PS_TRANSFORM, dxDest, dyDest, 8, dxDest, dyDest ); if ( !Asciize ) { // The size must include the doimage command that follows lSize = (long)dxDest * dyDest * depth; PS_ID1( IDS_PS_BEGINBINARY, lSize + 9 + 2 ); } PS_ID( IDS_PS_DOIMAGE ); // Should be 9 characters for ( x=0; x<5; x++ ) lpBuffer[x] = NULL; if (!AllocLines((LPPTR)&lpImageData, 1, dxSrc, depth)) { ProgressEnd(); return(FALSE); } if (!AllocLines((LPPTR)&lpBuffer[0], 1, dxDest, depth)) { FreeUp( lpImageData ); ProgressEnd(); return( FALSE ); } if (!AllocLines((LPPTR)&lpBuffer[1], 4, dxDest, 1)) { FreeUp(lpBuffer[0]); FreeUp( lpImageData ); ProgressEnd(); return( FALSE ); } p1Buf = lpBuffer[1]; p2Buf = lpBuffer[2]; p3Buf = lpBuffer[3]; p4Buf = lpBuffer[4]; ystart = ySrc; yline = -1; yoffset = (long)yrate>>1; for (y=0; y<dyDest; y++) { if (AstralClockCursor( y, dyDest, YES )) { fAbortPrint = YES; break; } /* Check for user input to abort dialog box */ (*lpAbortTest)(hPrinterDC, 0); if ( fAbortPrint ) break; ylast = yline; #ifdef WIN32 yline = ystart + WHOLE( yoffset ); #else yline = ystart + HIWORD( yoffset ); #endif yoffset += yrate; if ( yline != ylast ) { LFIXED rate; if (lpImage) ImgGetLine( lpImage, NULL, xSrc, yline, dxSrc, lpImageData ); else copy(FramePointer(lpBaseFrame, xSrc, yline, NO), lpImageData, dxSrc*depth); rate = FGET( dxSrc, dxDest ); FrameSample( lpBaseFrame, lpImageData, 0, lpBuffer[0], 0, dxDest, rate); } if ( cSep ) { // cSep is either 'C', 'M', 'Y', 'K', 'X'(gray) or NULL if (cSep != 'X') { LPTR lpOutBuf; int iPlaneOffset; switch(cSep) { case 'C' : lpOutBuf = p1Buf; iPlaneOffset = 0; break; case 'M' : lpOutBuf = p2Buf; iPlaneOffset = 1; break; case 'Y' : lpOutBuf = p3Buf; iPlaneOffset = 2; break; case 'K' : lpOutBuf = p4Buf; iPlaneOffset = 3; break; } switch(depth) { case 0 : case 1 : lpOutBuf = (LPTR)lpBuffer[0]; break; case 3 : ClrRGBtoCMYK( (LPRGB)lpBuffer[0], p1Buf, p2Buf, p3Buf,p4Buf,dxDest,YES); break; case 4 : { LPTR lpSrc = (LPTR)lpBuffer[0]; LPTR lpDst = lpOutBuf; int iCount = dxDest; lpSrc += iPlaneOffset; while(iCount-- > 0) { *lpDst++ = *lpSrc; lpSrc += 4; } } break; } if (Negative) negate(lpOutBuf, (long)dxDest); if ( !SendPSData( Asciize, lpOutBuf, dxDest ) ) goto ErrorExit; } else { ConvertData( lpBuffer[0], depth, dxDest, p1Buf, 1 ); if (Negative) negate(p1Buf, (long)dxDest); CorrectGray( p1Buf, dxDest, YES, YES ); if ( !SendPSData( Asciize, p1Buf, dxDest ) ) goto ErrorExit; } } else if ( Page.Type == IDC_PRINTER_IS_CMYK ) { switch(depth) { case 0 : case 1 : copy( lpBuffer[0], p1Buf, dxDest ); copy( lpBuffer[0], p2Buf, dxDest ); copy( lpBuffer[0], p3Buf, dxDest ); copy( lpBuffer[0], p4Buf, dxDest ); break; case 3 : ClrRGBtoCMYK( (LPRGB)lpBuffer[0], p1Buf, p2Buf, p3Buf,p4Buf,dxDest,YES); break; case 4 : { LPTR lpSrc = (LPTR)lpBuffer[0]; LPTR lpDst1 = p1Buf; LPTR lpDst2 = p2Buf; LPTR lpDst3 = p3Buf; LPTR lpDst4 = p4Buf; int iCount = dxDest; while(iCount-- > 0) { *lpDst1++ = *lpSrc++; *lpDst2++ = *lpSrc++; *lpDst3++ = *lpSrc++; *lpDst4++ = *lpSrc++; } } break; } if (Negative) { negate(p1Buf, (long)dxDest); negate(p2Buf, (long)dxDest); negate(p3Buf, (long)dxDest); negate(p4Buf, (long)dxDest); } if ( !SendPSData( Asciize, p1Buf, dxDest ) ) goto ErrorExit; if ( !SendPSData( Asciize, p2Buf, dxDest ) ) goto ErrorExit; if ( !SendPSData( Asciize, p3Buf, dxDest ) ) goto ErrorExit; if ( !SendPSData( Asciize, p4Buf, dxDest ) ) goto ErrorExit; if ( Page.OutputType == IDC_PRINT_COLORGRAY ) { ConvertData( lpBuffer[0], depth, dxDest, p1Buf, 1 ); if (Negative) negate(p1Buf, (long)dxDest); CorrectGray( p1Buf, dxDest, YES, YES); if ( !SendPSData( Asciize, p1Buf, dxDest ) ) goto ErrorExit; } } else if ( Page.Type == IDC_PRINTER_IS_RGB ) { switch(depth) { case 0 : case 1 : copy( lpBuffer[0], p1Buf, dxDest ); copy( lpBuffer[0], p2Buf, dxDest ); copy( lpBuffer[0], p3Buf, dxDest ); break; case 3 : UnshuffleRGB( (LPRGB)lpBuffer[0], p1Buf, p2Buf, p3Buf, dxDest ); break; case 4 : { LPCMYK lpCMYK = (LPCMYK)lpBuffer[0]; LPTR lpDst1 = p1Buf; LPTR lpDst2 = p2Buf; LPTR lpDst3 = p3Buf; RGBS rgb; int iCount = dxDest; while(iCount-- > 0) { CMYKtoRGB(lpCMYK->c, lpCMYK->m, lpCMYK->y, lpCMYK->k, &rgb); lpCMYK++; *lpDst1++ = rgb.red; *lpDst2++ = rgb.green; *lpDst3++ = rgb.blue; } } break; } if (Negative) { negate( p1Buf, dxDest ); negate( p2Buf, dxDest ); negate( p3Buf, dxDest ); } if ( !SendPSData( Asciize, p1Buf, dxDest ) ) goto ErrorExit; if ( !SendPSData( Asciize, p2Buf, dxDest ) ) goto ErrorExit; if ( !SendPSData( Asciize, p3Buf, dxDest ) ) goto ErrorExit; if ( Page.OutputType == IDC_PRINT_COLORGRAY ) { ConvertData( (LPTR)lpBuffer[0], depth, dxDest, p1Buf, 1 ); if (Negative) negate(p1Buf, (long)dxDest); CorrectGray( p1Buf, dxDest, YES, YES); if ( !SendPSData( Asciize, p1Buf, dxDest ) ) goto ErrorExit; } } } if ( !Asciize ) { PS_ID( IDS_PS_ENDBINARY ); } /* Send the save restore command */ PS_ID( IDS_PS_MYSAVERESTORE ); PS_ID( IDS_PS_END ); ErrorExit: if ( lpBuffer[0] ) FreeUp(lpBuffer[0]); if ( lpBuffer[1] ) FreeUp(lpBuffer[1]); if ( lpImageData ) FreeUp( lpImageData ); ProgressEnd(); return( TRUE ); }