LPFRAME EXPORT grabber_frame_open( WORD Depth, int x_size, int y_size, int Resolution ) /************************************************************************/ { LPFRAME lpNewFrame = NULL; switch(Depth) { case 0 : lpNewFrame = FrameOpen(FDT_LINEART, x_size, y_size, Resolution); break; case 1 : lpNewFrame = FrameOpen(FDT_GRAYSCALE, x_size, y_size, Resolution); break; case 3 : lpNewFrame = FrameOpen(FDT_RGBCOLOR, x_size, y_size, Resolution); break; case 4 : lpNewFrame = FrameOpen(FDT_CMYKCOLOR, x_size, y_size, Resolution); break; } if (lpNewFrame == NULL) FrameError( IDS_EPROCESSOPEN ); return(lpNewFrame); }
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); }
int GetCompleteMemoryImage( HWND hWnd, TW_SETUPMEMXFER dcMemSetup ) { TW_IMAGEINFO dcImageInfo; TW_IMAGEMEMXFER dcImageData; TW_UINT16 dcRC; LPTR lpBuffer = NULL; LPFRAME lpFrame; int imageWidth; int need_new; int save_type, expand; FRMDATATYPE Type; dcImageData.Memory.Flags = TWMF_APPOWNS | TWMF_POINTER; dcImageData.Memory.Length = dcMemSetup.Preferred; dcImageData.Memory.TheMem = LineBuffer[0]; // Get the image information, nice to know a little about the // image the Source will be sending if( !( *lpDSM_Entry )( &appID, &dsID, DG_IMAGE, DAT_IMAGEINFO, MSG_GET, ( TW_MEMREF )&dcImageInfo ) == TWRC_SUCCESS ) { return( FALSE ); } // We have the information about the type/size/depth of the image // Stored in dcImageInfo. imageWidth = dcImageInfo.ImageWidth; need_new = FALSE; // If we have to shrink the image.( hand scanners ) if( dcImageInfo.ImageLength == -1 ) { // Unknown length - hand scanner dcImageInfo.ImageLength = HS_MAXLENGTH * dcImageInfo.YResolution.Whole; need_new = TRUE; } if( dcImageInfo.ImageWidth == -1 ) { // Unknown width - hand scanner dcImageInfo.ImageWidth = HS_MAXWIDTH * dcImageInfo.XResolution.Whole; need_new = TRUE; } expand = 0; lpTwainPalette = ( pTW_PALETTE8 )NULL; // Find out the proper file save type for this image. switch( dcImageInfo.PixelType ) { case TWPT_BW : if( Control.LineArtAsGray ) { // Create Continuous tone Type = FDT_GRAYSCALE; save_type = IDC_SAVECT; expand = 1; } else { // Line Art Type = FDT_LINEART; save_type = IDC_SAVELA; } break; case TWPT_GRAY : Type = FDT_GRAYSCALE; save_type = IDC_SAVECT; break; case TWPT_RGB : Type = FDT_RGBCOLOR; save_type = IDC_SAVE24BITCOLOR; break; case TWPT_PALETTE : lpTwainPalette = ( pTW_PALETTE8 )Alloc( sizeof( TW_PALETTE8 ) + ( 256 * sizeof( TW_ELEMENT8 ))); if( lpTwainPalette == ( pTW_PALETTE8 )NULL ) return( FALSE ); if( !( *lpDSM_Entry )( &appID, &dsID, DG_IMAGE, DAT_PALETTE8, MSG_GET,( TW_MEMREF )lpTwainPalette ) == TWRC_SUCCESS ) { twainError( IDS_UNSUPPORTEDPIXTYPE ); return( FALSE ); } if( lpTwainPalette->PaletteType != TWPA_RGB ) { twainError( IDS_UNSUPPORTEDPIXTYPE ); return( FALSE ); } Type = FDT_PALETTECOLOR; save_type = IDC_SAVE8BITCOLOR; break; default : twainError( IDS_INVALIDPIXTYPE ); return( FALSE ); break; } // Open the new frame. if( !( lpFrame = FrameOpen( Type, ( WORD )imageWidth, ( WORD )dcImageInfo.ImageLength, ( WORD )dcImageInfo.XResolution.Whole ))) { // Issue the error message Message( IDS_ESCROPEN,( LPTR )Control.RamDisk ); return( FALSE ); } if( Type == FDT_PALETTECOLOR ) { int i; LPCOLORMAP lpColorMap = FrameGetColorMap( lpFrame ); int NumColors = lpTwainPalette->NumColors; if( NumColors > 256 ) NumColors = 256; for( i = 0; i < NumColors; ++i ) { lpColorMap->RGBData[i].red = lpTwainPalette->Colors[i].Channel1; lpColorMap->RGBData[i].green = lpTwainPalette->Colors[i].Channel2; lpColorMap->RGBData[i].blue = lpTwainPalette->Colors[i].Channel3; if( fInvert ) { lpColorMap->RGBData[i].red ^= 0xFF; lpColorMap->RGBData[i].green ^= 0xFF; lpColorMap->RGBData[i].blue ^= 0xFF; } } lpColorMap->NumEntries = NumColors; } if( dcImageInfo.Planar ) ImagePlane = 0; while( dcRC != TWRC_XFERDONE ) { dcRC = ( *lpDSM_Entry )( &appID, &dsID, DG_IMAGE, DAT_IMAGEMEMXFER, MSG_GET,( TW_MEMREF )&dcImageData ); switch( dcRC ) { case TWRC_SUCCESS: case TWRC_XFERDONE: if( dcImageData.YOffset == 0 ) ImagePlane++; StoreImageRect( lpFrame, dcImageInfo, dcImageData, Type, expand ); break; case TWRC_CANCEL: case TWRC_FAILURE: default: // something wrong, abort the transfer and delete the image if( dcRC == TWRC_FAILURE ) { twainError( IDS_TWAINFAILURE ); } // Close the garbage frame FrameClose( lpFrame ); return( FALSE ); break; } } // Bring up the new image window. SendMessage( hWnd, PM_XFERDONE, ( unsigned short )save_type,( unsigned long )lpFrame ); return( TRUE ); }
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 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 COlelistBox::OnLButtonDown(UINT nFlags, CPoint point) { FNAME *lpResult; CDataItem *pDataItem; LPIMAGE lpImage = GetActiveImage(); CServerDoc *pDoc = PictPubApp.GetDocument(lpImage); int num; CRect r,rr; BOOL bCreateDoc = (pDoc == NULL); CPoint p; CListBox::OnLButtonDown(nFlags, point); FORWARD_WM_LBUTTONUP(GetSafeHwnd(), point.x, point.y, nFlags, ::SendMessage); lpResult = ExtBsr_GetSelection(GetParent()->GetSafeHwnd(), &num); if (!lpResult || num != 1) return; lstrcpy(Names.Clipboard, lpResult[0]); if (LookupExtFileN(Names.Clipboard, Names.PasteImageFile, IDN_CLIPBOARD, NO)) { if (bCreateDoc) { LPFRAME lpFrame = FrameOpen(FDT_GRAYSCALE, 1, 1, 72); if (lpFrame) { POSITION Pos; lpImage = CreateImage(NULL,lpFrame,NULL,NULL, IDN_PP,IDC_SAVECT,IMG_DOCUMENT,NULL); if (!lpImage) { FrameClose(lpFrame); return; } pDoc = (CServerDoc*)PictPubApp.OpenDocumentFile( lpImage->CurFile, lpImage, FALSE); if (!pDoc) { DestroyImage(lpImage); return; } } else return; } if (pDoc) { pDataItem = new CDataItem(pDoc, Names.Clipboard, YES); GetParent()->GetWindowRect(&r); ClientToScreen(&point); GetItemRect(GetCurSel(), &rr); ClientToScreen(&rr); p.x = rr.Width() / 2; p.y = rr.Height() / 2; // NOTE!!the pDataItem will be internally destroyed once the drag/drop // operation is completed therefore we do not need to delete the pDataItem pDataItem->DoDragDrop(&rr, p, FALSE, DROPEFFECT_COPY, &r); if (bCreateDoc) pDoc->OnCloseDocument(); } } else if(Names.Clipboard[0]) { // deleted the file...notify the browser UpdatePasteFromFile(NULL); } }
LPFRAME DIBToPaletteFrame( LPTR lpDIBMem, BOOL bForceRGB ) { FRMDATATYPE FrameDataType; LPBITMAPINFO lpInfo; LPCOLORMAP lpColorMap; LPRGBQUAD lpRGBQColorMap; LPFRAME lpFrame; HPTR lpSrcLine; HPTR lpSrc; LPTR lpDst; BOOL bGrayMap; int iColorMapEntries; int iResolution; int iFrameXSize; int iFrameYSize; int iSrcWidth; int iDstWidth; int iCount; int y; int i; lpInfo = (LPBITMAPINFO)lpDIBMem; // Get the important bitmap information iFrameXSize = lpInfo->bmiHeader.biWidth; iFrameYSize = lpInfo->bmiHeader.biHeight; iResolution = ((lpInfo->bmiHeader.biXPelsPerMeter) * 254L) / 10000L; // Make sure that we have something to do if ((iFrameXSize <= 0) || (iFrameYSize <= 0)) { return(NULL); } // Validate the image resolution if (iResolution <= 0) { iResolution = 75; } lpRGBQColorMap = &lpInfo->bmiColors[0]; bGrayMap = TRUE; if (lpInfo->bmiHeader.biBitCount == 4) iColorMapEntries = 16; else iColorMapEntries = 256; // Find out whether or not this is a grayscale image for(i=0;i<iColorMapEntries;i++) { if (bGrayMap) { if ((lpRGBQColorMap[i].rgbBlue != lpRGBQColorMap[i].rgbRed) || (lpRGBQColorMap[i].rgbBlue != lpRGBQColorMap[i].rgbRed)) { bGrayMap = FALSE; break; } } } if (bGrayMap) { FrameDataType = FDT_GRAYSCALE; bForceRGB = FALSE; } else { if (bForceRGB) { FrameDataType = FDT_RGBCOLOR; } else { FrameDataType = FDT_PALETTECOLOR; } } // Create the new image frame lpFrame = FrameOpen(FrameDataType, iFrameXSize, iFrameYSize, iResolution); if (!lpFrame) return(NULL); // Add the colormap to the frame if necessary if (!bGrayMap) { // Allocate space for the colormap lpColorMap = (LPCOLORMAP)Alloc( sizeof(COLORMAP)+ sizeof(RGBS) * 256); if (!lpColorMap) { FrameClose(lpFrame); return(NULL); } lpColorMap->NumEntries = 256; for(i=0;i<iColorMapEntries;i++) { lpColorMap->RGBData[i].red = lpRGBQColorMap[i].rgbRed; lpColorMap->RGBData[i].green = lpRGBQColorMap[i].rgbGreen; lpColorMap->RGBData[i].blue = lpRGBQColorMap[i].rgbBlue; } for(i=iColorMapEntries;i<256;i++) { lpColorMap->RGBData[i].red = 0; lpColorMap->RGBData[i].green = 0; lpColorMap->RGBData[i].blue = 0; } if (FrameDataType == FDT_RGBCOLOR) if (!FrameSetColorMap( lpFrame, lpColorMap )) { FrameClose( lpFrame ); return(NULL); } } // Find the DIB data pointer and width lpSrcLine = lpDIBMem + lpInfo->bmiHeader.biSize + iColorMapEntries * (sizeof(RGBQUAD)); //OLD VERSION USED lpInfo->bmiHeader.biClrUsed instead of iColorMapEntries // some 4 bit DIB's don't set biCLrUsed that way if (lpInfo->bmiHeader.biBitCount == 4) iSrcWidth = ((lpInfo->bmiHeader.biWidth+7)/8)*4; else iSrcWidth = ((lpInfo->bmiHeader.biWidth+3)/4)*4; iDstWidth = FrameByteWidth( lpFrame ); if (bForceRGB) { // Copy the DIB data into the RGB Frame if (lpInfo->bmiHeader.biBitCount == 4) { for(y=iFrameYSize-1;y >= 0;y--) { lpSrc = lpSrcLine; lpDst = FramePointer( lpFrame, 0, y, TRUE ); iCount = (iFrameXSize+1)/2; while(iCount-- > 0) { *lpDst++ = lpColorMap->RGBData[(*lpSrc & 0xF0)>>4].red; *lpDst++ = lpColorMap->RGBData[(*lpSrc & 0xF0)>>4].green; *lpDst++ = lpColorMap->RGBData[(*lpSrc & 0xF0)>>4].blue; *lpDst++ = lpColorMap->RGBData[(*lpSrc & 0x0F)].red; *lpDst++ = lpColorMap->RGBData[(*lpSrc & 0x0F)].green; *lpDst++ = lpColorMap->RGBData[(*lpSrc & 0x0F)].blue; lpSrc++; } lpSrcLine += iSrcWidth; } } else { for(y=iFrameYSize-1;y >= 0;y--) { lpSrc = lpSrcLine; lpDst = FramePointer( lpFrame, 0, y, TRUE ); iCount = iFrameXSize; while(iCount-- > 0) { *lpDst++ = lpColorMap->RGBData[*lpSrc].red; *lpDst++ = lpColorMap->RGBData[*lpSrc].green; *lpDst++ = lpColorMap->RGBData[*lpSrc].blue; lpSrc++; } lpSrcLine += iSrcWidth; } } }
LPFRAME DIBToLineArtFrame( LPTR lpDIBMem, BOOL bForceRGB ) { LPBITMAPINFO lpInfo; LPFRAME lpFrame; HPTR lpSrc; HPTR lpSrcLine; LPTR lpDst; int iResolution; int iFrameXSize; int iFrameYSize; int iPixelFlavor; int iSrcWidth; int iDstWidth; int iCount; int y; lpInfo = (LPBITMAPINFO)lpDIBMem; // Get the important bitmap information iFrameXSize = lpInfo->bmiHeader.biWidth; iFrameYSize = lpInfo->bmiHeader.biHeight; iResolution = ((lpInfo->bmiHeader.biXPelsPerMeter) * 254L) / 10000L; // Make sure that we have something to do if ((iFrameXSize <= 0) || (iFrameYSize <= 0)) { return(NULL); } // Validate the image resolution if (iResolution <= 0) { iResolution = 75; } // Find out whether or not we need to invert iPixelFlavor = (lpInfo->bmiColors[0].rgbBlue == 0); // Create the new image frame lpFrame = FrameOpen(FDT_LINEART, iFrameXSize, iFrameYSize, iResolution); if (!lpFrame) return(NULL); // Find the DIB data pointer and width lpSrcLine = lpDIBMem + lpInfo->bmiHeader.biSize + lpInfo->bmiHeader.biClrUsed * (sizeof(RGBQUAD)); iSrcWidth = ((lpInfo->bmiHeader.biWidth+31)/32) * 4; iDstWidth = FrameByteWidth( lpFrame ); // Copy the DIB data into the Frame for(y=iFrameYSize-1;y >= 0;y--) { lpSrc = lpSrcLine; lpDst = FramePointerRaw( lpFrame, 0, y, TRUE ); iCount = iDstWidth; if (iPixelFlavor) { while(iCount-- > 0) { *lpDst++ = *lpSrc++; } } else { while(iCount-- > 0) { *lpDst++ = (*lpSrc++)^0xFF; } } lpSrcLine += iSrcWidth; } return(lpFrame); }
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); }
BOOL CReadBitmap::CTRead() { LPCTHEADER lpTH; LPFRAME lpFrame; BOOL fConvert = FALSE, fRet = FALSE; CFile theFile; CFile* pTheFile; FRMTYPEINFO inType, outType; LPTR lpIn, lpIn2,lpOut, lpFrmLine; int x,y,j; UINT bytes_read; BOOL GrayScale; BITMAP_ERROR_CODE err; CFrameTypeConvert Convert; ProgressBegin(1); if ((pTheFile = OpenFile()) == NULL) { ProgressEnd(); return(FALSE); } lpFrame = NULL; if ( !(lpTH = ReadCTHeader(pTheFile, m_lpFileName, &err))) { SetError(err); goto Exit; } GrayScale = lpTH->ColSepMask == 8 && lpTH->NumColSep == 1; if (GrayScale) FrameSetTypeInfo(&inType, FDT_GRAYSCALE, NULL); else FrameSetTypeInfo(&inType, FDT_CMYKCOLOR, NULL); if (!SetupTypes(&inType, &outType)) goto Exit; fConvert = !FrameTypeInfoEqual( inType, outType ); if( fConvert ) { if( !Convert.Init( inType, outType, lpTH->Pixels ) ) { SetError(BEC_errMemory); goto Exit; } } /* Create the image frame store */ if ( !(lpFrame = FrameOpen(outType, lpTH->Pixels, lpTH->Lines, lpTH->Resolution))) { SetError(BEC_errFrameOpen); goto Exit; } pTheFile->Seek (2048, CFile::begin); for (y=0; y < lpTH->Lines; y++) { if ( Progress(y, lpTH->Lines, YES)) goto Exit; TRY { bytes_read = pTheFile->Read(lpTH->lpCTLine, lpTH->LineSize); } CATCH_ALL(e) { goto BadRead; } END_CATCH_ALL if (bytes_read != lpTH->LineSize) goto BadRead; if ( !(lpFrmLine = FramePointerRaw( lpFrame, 0, y, YES))) goto BadWrite; lpIn = lpTH->lpCTLine; lpOut = lpFrmLine; lpIn2 = lpIn; for (x=0; x < lpTH->Pixels; x++) { j = 0; if (!GrayScale) { if (lpTH->ColSepMask & 0x1) // cyan { j += lpTH->ChannelSize; *lpOut++ = 255 - *lpIn2; } else *lpOut++ = 0; if (lpTH->ColSepMask & 0x2) // magenta { *lpOut++ = 255 - *(lpIn2 + j); j += lpTH->ChannelSize; } else *lpOut++ = 0; if (lpTH->ColSepMask & 0x4) // yellow { *lpOut++ = 255 - *(lpIn2 + j); j += lpTH->ChannelSize; } else *lpOut++ = 0; } if (lpTH->ColSepMask & 0x8) // black *lpOut++ = 255 - *(lpIn2 + j); else *lpOut++ = 0; lpIn2++; } if( fConvert ) Convert.ConvertData( lpFrmLine, lpFrmLine, y, lpTH->Pixels ); } m_iWidth = lpTH->Pixels; m_iHeight = lpTH->Lines; m_iRes = (int)lpTH->Resolution; m_lpFrame = lpFrame; fRet = TRUE; goto Exit; BadRead: SetError(BEC_errFileRead); goto Exit; BadWrite: SetError(BEC_errFrameRead); Exit: FreeCTHeader(lpTH); CloseFile(pTheFile); if (!fRet && lpFrame) FrameClose(lpFrame); ProgressEnd(); return( fRet ); }