// This updates the device-dependant EAX reverb state. This is called on // initialization and any time the device parameters (eg. playback frequency, // format) have been changed. static ALboolean ReverbDeviceUpdate(ALeffectState *effect, ALCdevice *Device) { ALverbState *State = (ALverbState*)effect; ALuint frequency = Device->Frequency, index; // Allocate the delay lines. if(!AllocLines(frequency, State)) return AL_FALSE; // Calculate the modulation filter coefficient. Notice that the exponent // is calculated given the current sample rate. This ensures that the // resulting filter response over time is consistent across all sample // rates. State->Mod.Coeff = aluPow(MODULATION_FILTER_COEFF, MODULATION_FILTER_CONST / frequency); // The early reflection and late all-pass filter line lengths are static, // so their offsets only need to be calculated once. for(index = 0;index < 4;index++) { State->Early.Offset[index] = (ALuint)(EARLY_LINE_LENGTH[index] * frequency); State->Late.ApOffset[index] = (ALuint)(ALLPASS_LINE_LENGTH[index] * frequency); } // The echo all-pass filter line length is static, so its offset only // needs to be calculated once. State->Echo.ApOffset = (ALuint)(ECHO_ALLPASS_LENGTH * frequency); return AL_TRUE; }
// This updates the device-dependant reverb state. This is called on // initialization and any time the device parameters (eg. playback frequency, // or format) have been changed. static ALboolean VerbDeviceUpdate( ALeffectState* effect, ALCdevice* Device ) { ALverbState* State = ( ALverbState* )effect; ALuint frequency = Device->Frequency, index; // Allocate the delay lines. if ( !AllocLines( AL_FALSE, frequency, State ) ) { return AL_FALSE; } State->Scale = aluSqrt( Device->NumChan / 8.0f ); // The early reflection and late all-pass filter line lengths are static, // so their offsets only need to be calculated once. for ( index = 0; index < 4; index++ ) { State->Early.Offset[index] = ( ALuint )( EARLY_LINE_LENGTH[index] * frequency ); State->Late.ApOffset[index] = ( ALuint )( ALLPASS_LINE_LENGTH[index] * frequency ); } return AL_TRUE; }
BOOL ExportImageDLL( LPSTR lpExportFile ) { HMODULE hModule; FARPROC lpClockCursor = NULL; FARPROC lpDataPointer = NULL; EXPORTPROC lpStartProc; EXPORTPROC lpProcessProc; EXPORTPROC lpEndProc; LPFRAME lpFrame; EXPPARMS parms; BOOL fSuccess = FALSE; LPIMAGE lpImage; lpImage = GetActiveImage(); if (!lpImage) goto Exit; lpFrame = ImgGetBaseEditFrame(lpImage); if (!lpFrame) goto Exit; if (!(hModule = (HMODULE)AstralLoadLibrary(lpExportFile))) goto Exit; lpStartProc = (EXPORTPROC)GetProcAddress(hModule, "_ExportStart"); lpProcessProc = (EXPORTPROC)GetProcAddress(hModule, "_ExportProcess"); lpEndProc = (EXPORTPROC)GetProcAddress(hModule, "_ExportEnd"); if ( !lpStartProc || !lpProcessProc || !lpEndProc ) goto Exit; iExportXSize = FrameXSize( lpFrame ); iExportYSize = FrameYSize( lpFrame ); iExportDepth = FrameDepth( lpFrame ); iExportResolution = FrameResolution( lpFrame ); lpClockCursor = MakeProcInstance( (FARPROC)ExportClockCursor, PictPubApp.Get_hInstAstral() ); lpDataPointer = MakeProcInstance( (FARPROC)ExportDataPointer, PictPubApp.Get_hInstAstral() ); AllocLines( &lpExportBuffer, 1, iExportXSize, max(1, iExportDepth)); parms.hInstance = PictPubApp.Get_hInstAstral(); parms.hWnd = GetActiveWindow(); parms.lpszFileName = lpImage->CurFile; parms.XSize = iExportXSize; parms.YSize = iExportYSize; parms.Depth = iExportDepth; parms.Resolution = iExportResolution; parms.StatusCallback = (LPROC)lpClockCursor; parms.DataPointer = (LPTRPROC)lpDataPointer; if (!lpClockCursor || !lpDataPointer || !lpExportBuffer) goto Exit; if ((*lpStartProc)((LPEXPPARMS)&parms)) { MessageStatus( IDS_PLEASEWAIT ); if ((*lpProcessProc)((LPEXPPARMS)&parms)) { fSuccess = TRUE; (*lpEndProc)((LPEXPPARMS)&parms); } } Exit: if (lpClockCursor) FreeProcInstance((FARPROC)lpClockCursor); if (lpDataPointer) FreeProcInstance((FARPROC)lpDataPointer); if (lpExportBuffer) FreeUp(lpExportBuffer); lpExportBuffer = NULL; if (hModule) FreeLibrary(hModule); MessageStatus( 0 ); return(fSuccess); }
BOOL CWriteBitmap::GIFWrite() { GIFHDR hdr; GIFDESC imDesc; GIFMAP ColorMap; int y, i, j, npix, nlin; LPTR lp, lpBuffer, lpImgScanline; BYTE cTerm; int codeSize; RECT rSave; BOOL bEscapable; BOOL compressInit; LPLZW_STUFF lpLZW; LPRGB lpRGBmap; LPFRAME lpFrame; LPOBJECT lpObject; FRMTYPEINFO inType, outType, inTypeLA, outTypeLA; CFrameTypeConvert TypeConvert, LineArtConvert; BOOL fRet = FALSE; CFile theFile; CFile* pTheFile = NULL; if (m_lpObjList) { lpObject = m_lpObjList->lpHead; if (lpObject) lpFrame = ObjGetEditFrame(lpObject); } else { lpFrame = m_lpFrame; lpObject = NULL; } ASSERT(lpFrame); ProgressBegin(1); if ((pTheFile = OpenFile()) == NULL) { ProgressEnd(); return(FALSE); } TRY { lpBuffer = NULL; lpImgScanline = NULL; compressInit = NO; /* full color not supported, force mini color */ if (m_DataType != FDT_GRAYSCALE && m_DataType != FDT_LINEART) m_DataType = FDT_PALETTECOLOR; if (m_fSrcArea) rSave = m_rSrcArea; else { rSave.top = rSave.left = 0; rSave.bottom = FrameYSize(lpFrame)-1; rSave.right = FrameXSize(lpFrame)-1; } inType = FrameTypeInfo(lpFrame); // cause FramePointer never returns line art if (inType.DataType == FDT_LINEART) inType.DataType = FDT_GRAYSCALE; // make sure colormap is inited for outType so we don't free bogus ptr FrameSetTypeInfo(&outType, FDT_NONE); npix = RectWidth(&rSave); nlin = RectHeight(&rSave); /* initialize file header */ hdr.ScnWidth = npix; hdr.ScnHeight = nlin; hdr.Background = 0; hdr.GlobalMap = TRUE; hdr.ColorRes = 8; /* initialize image descriptor */ imDesc.ImLeft = 0; imDesc.ImTop = 0; imDesc.ImWidth = npix; imDesc.ImHeight = nlin; imDesc.Zero = 0; /* determine type of image to create */ if ( m_DataType == FDT_GRAYSCALE ) { /* gray */ hdr.ColorRes = 8; hdr.bpp = 8; codeSize = 8; FrameSetTypeInfo(&outType, FDT_GRAYSCALE); } else if ( m_DataType == FDT_LINEART ) { /* line art or scatter */ hdr.ColorRes = 1; hdr.bpp = 1; codeSize = 2; FrameSetTypeInfo(&outType, FDT_LINEART); } else //if ( m_DataType == FDT_PALETTECOLOR ) { /* mini color */ hdr.ColorRes = 8; hdr.bpp = 8; codeSize = 8; if (inType.DataType == FDT_PALETTECOLOR) outType = inType; else FrameSetTypeInfo(&outType, FDT_PALETTECOLOR); } AllocLines( &lpBuffer, 1, npix, 4 ); // max size is cool AllocLines( &lpImgScanline, 1, npix, 4 ); if ( !lpBuffer || !lpImgScanline ) { SetError(BEC_errMemory); goto Exit; } /* set raw info byte */ hdr.RawImInfo = 0x80 | ((hdr.ColorRes-1) << 4) | (hdr.bpp-1); /* write file header */ pTheFile->Write((LPTR)"GIF87a", 6); pTheFile->Write((LPTR)&hdr.ScnWidth, 2); pTheFile->Write((LPTR)&hdr.ScnHeight, 2); pTheFile->Write((LPTR)&hdr.RawImInfo, 1); pTheFile->Write((LPTR)&hdr.Background, 1); pTheFile->Write((LPTR)"", 1); switch (m_DataType) { case FDT_LINEART: /* initialize the color map */ ColorMap.Length = 2; ColorMap.Map[0].red = ColorMap.Map[0].green = ColorMap.Map[0].blue = 0xFF; ColorMap.Map[1].red = ColorMap.Map[1].green = ColorMap.Map[1].blue = 0x00; /* write image descriptor, color map and code size */ if (gifWriteImDesc (pTheFile, &imDesc, &ColorMap, codeSize)) goto BadWrite; break; case FDT_GRAYSCALE: /* initialize the color map */ ColorMap.Length = 256; for (i = 0; i < 256; i++) { ColorMap.Map[i].red = ColorMap.Map[i].green = ColorMap.Map[i].blue = i; } /* write image descriptor, color map and code size */ if (gifWriteImDesc (pTheFile, &imDesc, &ColorMap, codeSize)) goto BadWrite; break; case FDT_PALETTECOLOR: // see if we need to create a palette if (!outType.ColorMap) { outType.ColorMap = FrameCreateColorMap(); if (!outType.ColorMap) { SetError(BEC_errMemory); goto Exit; } outType.ColorMap->NumEntries = 256; if (!CreateOptimizedPalette(lpObject, lpFrame, outType.ColorMap->RGBData, &outType.ColorMap->NumEntries, TRUE, NULL)) { SetError(BEC_errMemory); goto Exit; } } lpRGBmap = outType.ColorMap->RGBData; /* initialize the color map */ ColorMap.Length = 256; for (i = 0; i < 256; i++) { ColorMap.Map[i].red = lpRGBmap[i].red; ColorMap.Map[i].green = lpRGBmap[i].green; ColorMap.Map[i].blue = lpRGBmap[i].blue; } /* write image descriptor, color map and code size */ if (gifWriteImDesc (pTheFile, &imDesc, &ColorMap, codeSize)) goto BadWrite; break; } // initialize stuff to do the type conversion if (!TypeConvert.Init(inType, outType, npix, m_DitherType)) { SetError(BEC_errMemory); goto Exit; } if (outType.DataType == FDT_LINEART) { FrameSetTypeInfo(&inTypeLA, FDT_LINEART); FrameSetTypeInfo(&outTypeLA, FDT_GRAYSCALE); if (!LineArtConvert.Init(inTypeLA, outTypeLA, npix)) { SetError(BEC_errMemory); goto Exit; } } /* write the image */ if ( !( lpLZW = CompressLZW_GIF (pTheFile, NULL, 0, codeSize, NULL ) ) ) goto BadWrite; compressInit = YES; for (y = rSave.top; y <= rSave.bottom; y++) { if (Progress (y-rSave.top, nlin, bEscapable )) goto Exit; if (lpObject) { if (!ObjGetLine( lpObject, rSave.left, y, npix, lpImgScanline)) goto BadRead; lp = lpImgScanline; } else { if ( !(lp = FramePointer(lpFrame, rSave.left, y, NO)) ) goto BadRead; } // convert the data to the new type TypeConvert.ConvertData(lp, lpBuffer, y, npix); if (outType.DataType == FDT_LINEART) { /* convert back to depth one, but with pixel values of 0 and 1 */ LineArtConvert.ConvertData(lpBuffer, lpImgScanline, y, npix); for (lp = lpImgScanline, j = 0; j < npix; j++, lp++) *lp = (*lp) ? 0 : 1; lp = lpImgScanline; } else lp = lpBuffer; /* compress the data */ if (!(CompressLZW_GIF (pTheFile, lp, npix, codeSize, lpLZW))) goto BadWrite; } if ( compressInit ) CompressLZW_GIF (pTheFile, NULL, 0, codeSize, lpLZW); cTerm = 0; pTheFile->Write((LPTR)&cTerm, 1); cTerm = GIFTerm; pTheFile->Write((LPTR)&cTerm, 1); fRet = TRUE; goto Exit; } CATCH_ALL(e) { goto BadWrite; } END_CATCH_ALL BadWrite: SetError(BEC_errWriteFile); goto Exit; BadRead: SetError(BEC_errFrameRead); Exit: /* clean up */ CloseFile(pTheFile, fRet); compressInit = NO; if (lpBuffer) FreeUp (lpBuffer); if (lpImgScanline) FreeUp ( lpImgScanline ); if (outType.ColorMap && (outType.ColorMap != inType.ColorMap)) FrameDestroyColorMap(outType.ColorMap); ProgressEnd(); return (fRet); }
BOOL 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); }
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 ); }
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 ); }
LPCTHEADER ReadCTHeader(CFile *pTheFile, LPSTR lpFileName, BITMAP_ERROR_CODE *pErr) { BOOL fRet = FALSE; LPCTHEADER lpTH; BYTE Buff[15]; BYTE tmp; WORD wtmp; *pErr = BEC_errNone; if (!(lpTH = (LPCTHEADER)Alloc((long)sizeof(CTHEADER)))) { *pErr = BEC_errMemory; return(NULL); } // Clear out all the header data clr( (LPTR)lpTH, sizeof(CTHEADER)); TRY { if (pTheFile->Read ((LPTR)&lpTH->FileName, 80) != 80) /* read FileName */ goto BadRead; lpTH->FileName[80] = 0; if (pTheFile->Read ((LPTR)&wtmp, 2) != 2) /* read File Type */ goto BadRead; if (wtmp != CT_TYPE) goto BadRead; pTheFile->Seek (1024, CFile::begin); if (pTheFile->Read ((LPTR)&tmp, 1) != 1) /* read Unit of measurement */ goto BadRead; lpTH->Units = tmp; if (pTheFile->Read ((LPTR)&tmp, 1) != 1) /* read Unit of measurement */ goto BadRead; lpTH->NumColSep = tmp; if (pTheFile->Read ((LPTR)&lpTH->ColSepMask, 2) != 2) /* read Unit of measurement */ goto BadRead; swapw (&lpTH->ColSepMask); if (pTheFile->Read ((LPTR)Buff, 14) != 14) /* read Unit of measurement */ goto BadRead; Buff[14] = 0; lpTH->Height = atof((const char *)Buff); if (pTheFile->Read ((LPTR)Buff, 14) != 14) /* read Unit of measurement */ goto BadRead; Buff[14] = 0; lpTH->Width = atof((const char *)Buff); if (pTheFile->Read ((LPTR)Buff, 12) != 12) /* read Unit of measurement */ goto BadRead; Buff[12] = 0; lpTH->Lines = atol((const char *)Buff); if (pTheFile->Read ((LPTR)Buff, 12) != 12) /* read Unit of measurement */ goto BadRead; Buff[12] = 0; lpTH->Pixels = atol((const char *)Buff); if (pTheFile->Read ((LPTR)&tmp, 1) != 1) /* read Unit of measurement */ goto BadRead; lpTH->Orientation = tmp; if (!(lpTH->ColSepMask & 0x000F)) // make sure at lease on of the CMYK goto BadRead; // channel do exist if (lpTH->Units) // inches lpTH->Resolution = (int)(lpTH->Pixels / lpTH->Width); else // mm lpTH->Resolution = (int)(lpTH->Pixels * 25.4 / lpTH->Width); if (lpTH->Pixels & 1) // odd pixels lpTH->ChannelSize = lpTH->Pixels + 1; else lpTH->ChannelSize = lpTH->Pixels; lpTH->LineSize = lpTH->ChannelSize * lpTH->NumColSep; if (lpTH->NumColSep > 4) lpTH->NumColSep = 4; if (!AllocLines( &lpTH->lpCTLine, 1, lpTH->LineSize, 1)) { *pErr = BEC_errMemory; goto Exit; } fRet = TRUE; goto Exit; } CATCH_ALL(e) { goto BadRead; } END_CATCH_ALL BadRead: *pErr = BEC_errFileRead; Exit: if (!fRet) { FreeCTHeader(lpTH); lpTH = NULL; } return(lpTH); }
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 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 ); }