BOOL HistoInit() /************************************************************************/ { LPFRAME lpFrame; int x, y, i; LPTR lpLine; RGBS rgb; lpFrame = frame_set(NULL); if (!lpFrame) return(FALSE); lpRHisto = AllocPtr(256 * sizeof(long)); lpGHisto = AllocPtr(256 * sizeof(long)); lpBHisto = AllocPtr(256 * sizeof(long)); if (!lpRHisto || !lpGHisto || !lpBHisto) { HistoDone(); return(FALSE); } clr(lpRHisto, 256 * sizeof(long)); clr(lpGHisto, 256 * sizeof(long)); clr(lpBHisto, 256 * sizeof(long)); AstralWaitCursor(); for (y = 0; y < lpFrame->Ysize; ++y) { AstralClockCursor(y, lpFrame->Ysize, TRUE); lpLine = CachePtr(0, 0, y, NO); for (x = 0; x < lpFrame->Xsize; ++x, lpLine += DEPTH) { frame_getRGB( lpLine, &rgb ); ++lpRHisto[rgb.red]; ++lpGHisto[rgb.green]; ++lpBHisto[rgb.blue]; } } change_cursor(0); TotalHisto = (long)lpFrame->Ysize * (long)lpFrame->Xsize; MaxHisto = 0; for (i = 0; i < 256; ++i) { if (lpRHisto[i] > MaxHisto) MaxHisto = lpRHisto[i]; if (lpGHisto[i] > MaxHisto) MaxHisto = lpGHisto[i]; if (lpBHisto[i] > MaxHisto) MaxHisto = lpBHisto[i]; } for (i = 0; i < 8; ++i) grayPat[i] = (i & 1) ? 0x55 : 0xAA; for (i = 0; i < QTONEPOINTS; ++i) QTone.QTmoved[i] = NO; MapInit(); QTone.ActiveMark = 0; HistoValue = PNTX(QT(QTone.ActiveMark)); return(TRUE); }
BOOL CopyFile1( /************************************************************************/ LPSTR lpInFile, LPSTR lpOutFile, BOOL bClock, BOOL bEscapable) { int i, ifp, ofp; char Buffer[2048]; int nTotal, nCount; nTotal = FileSize(lpInFile) / 2048; lstrcpy( Buffer, lpInFile ); if ((ifp = _lopen( Buffer, OF_READ )) < 0) return( FALSE ); lstrcpy( Buffer, lpOutFile ); if ((ofp = _lcreat( Buffer, 0 )) < 0) { _lclose( ifp ); return( FALSE ); } i = sizeof(Buffer); nCount = 0; while( 1 ) { if (bClock) { if (AstralClockCursor(nCount, nTotal, bEscapable)) { _lclose( ifp ); _lclose( ofp ); lstrcpy( Buffer, lpOutFile ); unlink(Buffer); return( FALSE ); } } if ( (i = _lread(ifp, Buffer, i)) <= 0 ) { _lclose( ifp ); _lclose( ofp ); return( i == 0 ); } if ( _lwrite(ofp, Buffer, i) != i ) { _lclose( ifp ); _lclose( ofp ); lstrcpy( Buffer, lpOutFile ); unlink(Buffer); return( FALSE ); } ++nCount; } }
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); }
void RemoveCodedBackground() { LPFRAME lpFrame; int x, y; int Width; int Height; LPTR lpSrcLine; BYTE r, g, b; if (!lpImage) return; ImgCombineObjects(lpImage, TRUE, FALSE, TRUE); lpFrame = ImgGetBaseEditFrame(lpImage); if (!lpFrame) return; Width = FrameXSize (lpFrame); Height = FrameYSize (lpFrame); for (y=0;y<Height;y++) { AstralClockCursor( y, Height, NO ); lpSrcLine = FramePointer (lpFrame,0,y,TRUE); for (x=0;x<Width;x++) { RGBS Pixel; FrameGetRGB (lpFrame,lpSrcLine,&Pixel,1); r = Pixel.red; g = Pixel.green; b = Pixel.blue; if (r >= 100 && !g && !b) { // a dot Pixel.red = 255; Pixel.green = 255; Pixel.blue = 255; FrameSetRGB (lpFrame,&Pixel,lpSrcLine,1); } else if ( (r != g) || (g != b) ) { // not white or black Pixel.red = 0; Pixel.green = 0; Pixel.blue = 0; FrameSetRGB (lpFrame,&Pixel,lpSrcLine,1); } lpSrcLine += 3; } // Width } // Height }
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(); }
int EXPORT grabber_AstralClockCursor( int part, int whole ) /************************************************************************/ { return(AstralClockCursor(part, whole, YES)); }
void grabber( LPSTR lpExtName, int port, HINSTANCE hInstance, HWND hWindow ) { HWND hWnd; /* special conditions: hand scan interface -- with hand scanners the dialog box has a scan frame which gets filled with image data. the dialog box must remain up during reads, so we use the exported frame_open, cacheptr, and frame_close to create the frame instead of device reads. Devopen just returns devcaps, devstart does everything else. special willow gs -- the gs board has 4 different buffers, which contain the following: 0-even pix/even lines, 1-odd pix/even lines, 2-even pix/odd lines, 3-odd pix/odd lines. each call to devread will layer the data so that the buffers will be combined correctly. Device Requirements Byte Decoding: XXXXXXX1b = need to take over display XXXXXXX0b = no need to take over display XXXXXX1Xb = special willow gs read XXXXXX0Xb = no special read XXXX00XXb = image depth, special case palette color 8-bit XXXX01XXb = depth == 1 XXXX10XXb = depth == 2 XXXX11XXb = depth == 3 X1XXXXXXb = special hand scan i/f X0XXXXXXb = standard grab i/f XX1XXXXXb = don't free DLL after exit XX0XXXXXb = free DLL after exit 1XXXXXXXb = putting data from cache to external device 0XXXXXXXb = putting data from external device into cache */ BYTE devreq; // device requirements LPFRAME lpFrame, lpOldFrame; BYTE depth; int lncnt,Datatype; HMODULE hDLL; LPIMAGE lpImage; if ( !(hDLL = (HMODULE)LoadGrabberLibrary(lpExtName)) ) { Message( IDS_EBADDRIVER, NULL ); return; } if ( !(lpImage = GetActiveImage())) lpFrame = NULL; else lpFrame = ImgGetBaseEditFrame(lpImage); lpfnDevName = (DEVNAMEPROC)GetProcAddress(hDLL, MAKEINTRESOURCE(301)); lpfnDevOpen = (DEVOPENPROC)GetProcAddress(hDLL, MAKEINTRESOURCE(302)); lpfnDevCall = (DEVCALLPROC)GetProcAddress(hDLL, MAKEINTRESOURCE(303)); lpfnDevClose = (DEVCLOSEPROC)GetProcAddress(hDLL, MAKEINTRESOURCE(304)); lpfnAcquireProc = (DLGPROC)GetProcAddress(hDLL, MAKEINTRESOURCE(305)); /* get device's intentions -- is this a put to or read from cache */ DevInfo.hInst = hInstance; /* set the data structures */ DevInfo.hPw = hWindow; DevInfo.bFile_is_open = ( lpFrame != NULL ); if(DevInfo.bFile_is_open) { DevInfo.bImg_type = (lpImage->DataType==IDC_SAVECT ? TRUE : FALSE); /* pass the current filename */ lstrcpy(DevInfo.cfname, lpImage->CurFile); } if(!DevOpen(&DevInfo)) { DevCall(DEV_MSG, (LPTR)&DevMsg); /* if MsgNo == 0, then user cancelled */ if(DevMsg.MsgNo) { if(DevMsg.MsgNo > 0) { Message( DevMsg.MsgNo ); } else { /* print the driver's message */ Print("%ls", (LPTR)DevMsg.szMsg); } } return; } bKeepDLL = (DevInfo.device_caps & 0x20); devreq = DevInfo.device_caps; /* doing a put cache to an external device */ if(!(devreq & 0x80)) { /* fill up the device info data structure */ DevInfo.npix = FrameXSize( lpFrame ); DevInfo.nlin = FrameYSize( lpFrame ); DevInfo.bpl = FrameXSize( lpFrame ); DevInfo.xres = DevInfo.yres = FrameResolution( lpFrame ); DevInfo.bpp = 8; } else { DevInfo.port = port; /* set the port for devices which require it */ #ifndef WIN32 DevInfo.vgaaddr = GetA000H(); /* set the VGA buffer address */ #endif } /* see if we need to take over display */ if(devreq & 1) { /* Hide the Cursor */ ShowCursor( FALSE ); /* Create the acquire window: it doesn't have the visable bit set */ AstralDlg( YES, hInstance, hWindow, IDD_GRAB, AcquireProc); AstralDlgShow( IDD_GRAB ); /* Enter the picture window command processor */ SetCapture( AstralDlgGet( IDD_GRAB ) ); /* set the data structures */ DevInfo.hInst = hInstance; DevInfo.hPw = AstralDlgGet( IDD_GRAB ); /* call display driver disable */ #ifndef WIN32 PicwinOn((LPSTR)palette1); #endif } if(devreq & 0x40) { // devstart does everything DevInfo.FpPtr = (LPTRPROC)MakeProcInstance( (FARPROC)grabber_frame_ptr, DevInfo.hInst); DevInfo.FoPtr = (LPTRPROC)MakeProcInstance( (FARPROC)grabber_frame_open, DevInfo.hInst); DevInfo.FsPtr = (LPTRPROC)MakeProcInstance( (FARPROC)grabber_frame_set, DevInfo.hInst); DevInfo.FcPtr = (LPROC)MakeProcInstance( (FARPROC)grabber_frame_close, DevInfo.hInst); DevInfo.CcPtr = (LPROC)MakeProcInstance( (FARPROC)grabber_AstralClockCursor, DevInfo.hInst); } DevInfo.bLineArtAsGray = Control.LineArtAsGray; if(!DevCall(DEV_START, (LPTR)&DevInfo)) { /* if get, fill struct */ back_to_windows(devreq & 1); /* restore if true */ DevCall(DEV_MSG, (LPTR)&DevMsg); /* if MsgNo == 0, then user cancelled */ if(DevMsg.MsgNo) { if(DevMsg.MsgNo > 0) { Message( DevMsg.MsgNo ); } else { /* print the driver's message */ Print("%ls", (LPTR)DevMsg.szMsg); } } if(devreq & 0x40) { // devstart does everything FreeProcInstance((FARPROC)DevInfo.FpPtr); FreeProcInstance((FARPROC)DevInfo.FoPtr); FreeProcInstance((FARPROC)DevInfo.FsPtr); FreeProcInstance((FARPROC)DevInfo.FcPtr); FreeProcInstance((FARPROC)DevInfo.CcPtr); } DevClose(); /* close the device */ return; } /* DEV_START returned ok, now get or put image data if not done */ if((devreq & 0xc0) == 0x80) { // putting data into the cache with devreads if(((devreq & 4) == 4) || ((devreq & 0x0c) == 0)) { depth = 1; } else { if((devreq & 8) == 8) { depth = 2; } else { if((devreq & 0x0c) == 0x0c) { depth = 3; } } } lpOldFrame = frame_set( NULL ); if(!(lpFrame = FrameOpen( (FRMDATATYPE)depth,DevInfo.npix,DevInfo.nlin,DevInfo.xres))) { back_to_windows(devreq & 1); /* Restore if true */ FrameError(IDS_EIMAGEOPEN); return; } frame_set(lpFrame); if(!(devreq & 2)) { for ( lncnt=0; lncnt<DevInfo.nlin; lncnt++ ) { DevData.ImageAddress = FramePointer(lpFrame, 0, lncnt, YES); if(!DevCall(DEV_READ, (LPTR)&DevData)) { back_to_windows(devreq & 1); /* Restore if true */ DevCall(DEV_MSG, (LPTR)&DevMsg); /* if MsgNo == 0, then user cancelled */ if(DevMsg.MsgNo) { Print("Unable to get data from device"); } else { DevInfo.nlin = lncnt; // hand scanner, get total lines } return; } } } else { /* special willow gs reader */ /* read even bytes, even lines */ for ( lncnt=0; lncnt<DevInfo.nlin; lncnt+=2 ) { DevData.ImageAddress = FramePointer(lpFrame, 0, lncnt, YES); if(!DevCall(DEV_READ0, (LPTR)&DevData)) { back_to_windows(devreq & 1); /* Restore if true */ Print("Unable to get data from device"); return; } } /* read odd bytes, even lines */ for ( lncnt=0; lncnt<DevInfo.nlin; lncnt+=2 ) { DevData.ImageAddress = FramePointer(lpFrame, 1, lncnt, YES); if(!DevCall(DEV_READ1, (LPTR)&DevData)) { back_to_windows(devreq & 1); /* Restore if true */ Print("Unable to get data from device"); return; } } /* read even bytes, odd lines */ for ( lncnt=1; lncnt<DevInfo.nlin; lncnt+=2 ) { DevData.ImageAddress = FramePointer(lpFrame, 0, lncnt, YES); if(!DevCall(DEV_READ2, (LPTR)&DevData)) { back_to_windows(devreq & 1); /* Restore if true */ Print("Unable to get data from device"); return; } } /* read odd bytes, odd lines */ for ( lncnt=1; lncnt<DevInfo.nlin; lncnt+=2 ) { DevData.ImageAddress = FramePointer(lpFrame, 1, lncnt, YES); if(!DevCall(DEV_READ3, (LPTR)&DevData)) { back_to_windows(devreq & 1); /* Restore if true */ Print("Unable to get data from device"); return; } } } FrameClose( lpOldFrame ); back_to_windows(devreq & 1); /* Restore if true */ if(DevInfo.bpp == 1) { Datatype = IDC_SAVELA; } else { if(DevInfo.bpp == 8) { Datatype = IDC_SAVECT; } else { Datatype = IDC_SAVE24BITCOLOR; } } /* Setup the new image and bring up the new image window */ LPIMAGE lpNewImage = CreateImage(NULL, lpFrame, NULL, NULL, Control.DefaultFileType, Datatype, IMG_DOCUMENT, NULL); if (lpNewImage) { if (PictPubApp.OpenDocumentFile((LPSTR)lpNewImage->CurFile, lpNewImage)) { /* only version of image is in the cache */ /* so insure user is asked about saving when done */ lpNewImage->fChanged = TRUE; } else DestroyImage(lpNewImage); } DevClose(); /* close the device */ } else { LPIMAGE lpNewImage = NULL; /* enable the frame created by DevStart */ lpFrame = frame_set(NULL); /* putting data to external device with DevWrites */ if((devreq & 0xc0) == 0) { for ( lncnt=0; lncnt<DevInfo.nlin; lncnt++ ) { AstralClockCursor( lncnt, DevInfo.nlin, NO ); DevData.ImageAddress = FramePointer(lpFrame, 0, lncnt, NO); if(!DevCall(DEV_WRITE, (LPTR)&DevData)) { Print("Unable to put data to device"); return; } } } else { /* devstart has created a frame with image data */ FreeProcInstance((FARPROC)DevInfo.FpPtr); FreeProcInstance((FARPROC)DevInfo.FoPtr); FreeProcInstance((FARPROC)DevInfo.FsPtr); FreeProcInstance((FARPROC)DevInfo.FcPtr); if(DevInfo.bpp == 1) { Datatype = IDC_SAVELA; } else { if(DevInfo.bpp == 8) { Datatype = IDC_SAVECT; } else { Datatype = IDC_SAVE24BITCOLOR; } } back_to_windows(devreq & 1); /* Restore if true */ /* enable the frame created by DevStart */ lpFrame = frame_set(NULL); /* DevInfo.nlin returns the actual line count */ if(FrameYSize(lpFrame) <= DevInfo.nlin) { /* Setup the new image and bring up the new image window */ { lpNewImage = CreateImage(NULL, lpFrame, NULL, NULL, Control.DefaultFileType, Datatype, IMG_DOCUMENT, NULL); if (lpNewImage) { if (!PictPubApp.OpenDocumentFile((LPSTR)lpNewImage->CurFile, lpNewImage)) { DestroyImage(lpNewImage); lpNewImage = NULL; } } } } else { /* create a new frame of the right size and copy */ /* the right number of lines to it */ lpOldFrame = FrameOpen( FrameType(lpFrame), FrameXSize(lpFrame), DevInfo.nlin, FrameResolution(lpFrame)); AstralCursor( IDC_WAIT ); for(lncnt=0; lncnt<DevInfo.nlin; lncnt++) { FrameCopyLine(lpFrame, lpOldFrame, lncnt); } FrameClose(lpFrame); lpFrame = lpOldFrame; AstralCursor( NULL ); /* Setup the new image and bring up the new image window */ lpNewImage = CreateImage(NULL, lpFrame, NULL, NULL, Control.DefaultFileType, Datatype, IMG_DOCUMENT, NULL); if (lpNewImage) { if (!PictPubApp.OpenDocumentFile((LPSTR)lpNewImage->CurFile, lpNewImage)) { DestroyImage(lpNewImage); lpNewImage = NULL; } } } /* only version of image is in the cache */ /* so insure user is asked about saving when done */ if (lpNewImage) lpNewImage->fChanged = TRUE; DevClose(); /* close the device */ } } }
BOOL FAR EXPORT ExportClockCursor(int part, int whole, BOOL bEscapable) { return(AstralClockCursor(part, whole, bEscapable)); }
int FAR PASCAL EXPORT GetSet_DialogStatus( HWND hDialog, int Flag, int Code, int Import, int Export, int n, LPSTR FAR *Strings ) ////////////////////////////////////////////////////////////////////////// // This is a call back procedure for getting or setting dialog // // status. What it does depends on the Flag. The flags are: // // 1 ) IME_STATUS: Only checking if user wants to cancel. No // // message is displayed, so we don't pause the // // processing.( CALLED from chk_esc( ).) // // // // 2 ) IME_NOTIFY: Only imforming the user( e.g. a process has // // started ). No checking for cancel takes place. // // We don't pause the information because the user // // should have time to see it before it scrolls // // off the screen.( CALLED from message(). // // // // 3 ) IME_WARNING: Warning the user that a non-fatal error has // // taken place. The user is allowed to continue // // or to abort the process. Thus we check for // // cancel, and we pause to allow them to respond. // // ( CALLED from ask_yeno( ). ) // // // // 3 ) IME_ERROR: Telling the user that a fatal error has // // occured. We pause to allow the user to see // // the error message. However, we will abort, so // // we return IME_ABORT.( CALLED from error(). ) // // // ////////////////////////////////////////////////////////////////////////// { int Escape = IME_OK; int PercentComplete = 0; switch( Flag ) { case IME_STATUS: // No message strings for simple STATUSes switch( Code ) { case IME_UPDATE_PERCENT : PercentComplete = Calc_PercentRestraints( Import, Export ); if( AstralClockCursor( PercentComplete, 100, YES )) Escape = IME_ABORT; else Escape = IME_OK; return( Escape ); case IME_INIT_IMPORT : isPrescan = FALSE; ImportPercentRestraint = 100; ExportPercentRestraint = 0; PrescanPercentRestraint = Import; ScanPercentRestraint = Export; isPrescan = FALSE; return( IME_OK ); case IME_INIT_EXPORT : ImportPercentRestraint = Import; ExportPercentRestraint = Export; return( IME_OK ); case IME_PRESCAN : isPrescan = TRUE; return( IME_OK ); case IME_IMPORT : isPrescan = FALSE; return( IME_OK ); } case IME_NOTIFY: return( IME_OK ); // don't checkstatus -- will check next // time that a chk_esc() is called. case IME_WARNING: return( IME_OK ); case IME_ERROR: return( IME_ABORT ); } return( IME_OK ); }
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 ); }
void InitPoints() { int i; LPFRAME lpFrame; int Width; int Height; int x,y; LPTR lpSrcLine; BYTE r, g, b; iActiveDot = 0; iNumDots = 0; // Clear out the array for (i=0; i<MAX_DOTS; i++) { DotPoints[i].x = 0; DotPoints[i].y = 0; } if (!lpImage) return; lpFrame = ImgGetBaseEditFrame(lpImage); if (!lpFrame) return; Width = FrameXSize (lpFrame); Height = FrameYSize (lpFrame); // Find all the points in the image. // Search for coded dots that indicate a dot-to-dot point. // These dot points will be drawn as circles for the user to click in. // An array of points - DotPoints[] is maintained to remember these dots. for (y=0;y<Height;y++) { AstralClockCursor( y, Height, NO ); lpSrcLine = FramePointer (lpFrame,0,y,FALSE); for (x=0;x<Width;x++) { RGBS Pixel; FrameGetRGB (lpFrame,lpSrcLine,&Pixel,1); r = Pixel.red; g = Pixel.green; b = Pixel.blue; if (r >= 100 && g == 0 && b == 0) { // This is a coded pixel that contains: // 1) green - No coding. MUST be 0. // 2) red - Sequence that the dot is found. // 3) blue - No coding. MUST be 0. r -= 100; if (r >= 0 && r <= MAX_DOTS) { // Save the Dot position. // Do not allow the dot to go off the screen. DotPoints[r].x = min(x, Width - ((DOT_DIAMETER / 2) + 2)); DotPoints[r].y = min(y, Height - ((DOT_DIAMETER / 2) + 2)); iNumDots = max(iNumDots, r); } } lpSrcLine += 3; } // Width } // Height }
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); }
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 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 ); }