void BWCopy(Widget w, Position at_x, Position at_y, int value) { BitmapWidget BW = (BitmapWidget) w; XImage *storage; char *storage_data; Dimension width, height; if (QuerySet(BW->bitmap.mark.from_x, BW->bitmap.mark.from_y)) { width = BW->bitmap.mark.to_x - BW->bitmap.mark.from_x + 1; height = BW->bitmap.mark.to_y - BW->bitmap.mark.from_y + 1; storage_data = CreateCleanData(Length(width, height)); storage = CreateBitmapImage(BW, storage_data, width, height); CopyImageData(BW->bitmap.image, storage, BW->bitmap.mark.from_x, BW->bitmap.mark.from_y, BW->bitmap.mark.to_x, BW->bitmap.mark.to_y, 0, 0); DrawImageData(BW, storage, at_x, at_y, value); DestroyBitmapImage(&storage); } }
void BWStore(Widget w) { BitmapWidget BW = (BitmapWidget) w; Dimension width, height; char *storage_data; if (QuerySet(BW->bitmap.mark.from_x, BW->bitmap.mark.from_y)) { DestroyBitmapImage(&BW->bitmap.storage); width = BW->bitmap.mark.to_x - BW->bitmap.mark.from_x + 1; height = BW->bitmap.mark.to_y - BW->bitmap.mark.from_y + 1; storage_data = CreateCleanData(Length(width, height)); BW->bitmap.storage = CreateBitmapImage(BW, storage_data, width, height); CopyImageData(BW->bitmap.image, BW->bitmap.storage, BW->bitmap.mark.from_x, BW->bitmap.mark.from_y, BW->bitmap.mark.to_x, BW->bitmap.mark.to_y, 0, 0); } }
/* ARGSUSED */ static Boolean ConvertSelection(Widget w, Atom *selection, Atom *target, Atom *type, XtPointer *val_ret, unsigned long *length, int *format) { XPointer *value = (XPointer *)val_ret; BitmapWidget BW = (BitmapWidget) w; Pixmap *pixmap; char *data; XImage *image; Dimension width, height; switch (*target) { /* XA_TARGETS undefined ?!? case XA_TARGETS: *type = XA_ATOM; *value = (XPointer) bitmapClassRec.bitmap_class.targets; *length = bitmapClassRec.bitmap_class.num_targets; *format = 32; return True; */ case XA_BITMAP: case XA_PIXMAP: if (BWQueryMarked(w)) { width = BW->bitmap.mark.to_x - BW->bitmap.mark.from_x + 1; height = BW->bitmap.mark.to_y - BW->bitmap.mark.from_y + 1; data = CreateCleanData(Length(width, height)); image = CreateBitmapImage(BW, data, width, height); CopyImageData(BW->bitmap.image, image, BW->bitmap.mark.from_x, BW->bitmap.mark.from_y, BW->bitmap.mark.to_x, BW->bitmap.mark.to_y, 0, 0); pixmap = (Pixmap *) XtMalloc(sizeof(Pixmap)); *pixmap = GetPixmap(BW, image); DestroyBitmapImage(&image); } else if (BWQueryStored(w)) { pixmap = (Pixmap *) XtMalloc(sizeof(Pixmap)); *pixmap = GetPixmap(BW, BW->bitmap.storage); } else return False; *type = XA_PIXMAP; *value = (XPointer) pixmap; *length = 1; *format = 32; return True; default: return False; } }
void ImageData::CombineImageData (int nMsg, CkReductionMsg **msgs, byte* dest) { // Copy in the merged image header memcpy (dest, m_header, m_headerSize); // Initialize image data to all 0's. memset (dest+m_headerSize, 0, m_size-m_headerSize); // combine image data into buff for (int i=0; i<nMsg; i++) { CopyImageData (dest, m_numDataLines, msgs[i], ((ImageHeader *)dest)->m_combine); } }
void CImageDisplay::DisplayImage(CDC * pDC, const LPVOID lpBuf, UINT nCount) { if (lpBuf == NULL || nCount == 0) { pDC->FillSolidRect(&m_rc, RGB(0, 0, 0)); pDC->SetTextColor(RGB(240, 240, 240)); pDC->SelectObject(&m_fontTag); pDC->DrawText(_T("NO IMAGE"), &m_rc, DT_VCENTER | DT_CENTER | DT_SINGLELINE); } else { CopyImageData(lpBuf, nCount); DrawBitmap(pDC->m_hDC, m_rc); } }
void correct (TrformStr *TrPtr, cPrefs *prefs) { int i=0,j,k, kstart, kend, kdone, color; double scale_params[2]; // scaling factors for resize; double shear_params[2]; // shear values double radial_params[6]; // coefficients for polynomial correction (0,...3) // and source width/2 (4) and correctionradius (5) double lum_params[2]; // parameters to correct luminance variation struct fDesc stack[10]; // Parameters for execute stack function struct fDesc stackinv[10]; // Parameters for execute stack function int destwidth, destheight; int xoff = 0, yoff = 0; int sizesqr; double xdoff, ydoff; Image im, *dest, *src; fDesc fD; fDesc fDinv; im.data = NULL; src = TrPtr->src; dest = TrPtr->dest; // Apply filters, if required TrPtr->success = 1; if( prefs->luminance ) { destwidth = TrPtr->src->width; destheight = TrPtr->src->height; // Allocate memory for destination image // If no further Xform: simply use SetDest if( !( prefs->resize || prefs->shear || prefs->horizontal || prefs->vertical || prefs->radial || prefs->cutFrame || prefs->fourier) ) { if( SetDestImage(TrPtr, destwidth, destheight) != 0 ) { TrPtr->success = 0; PrintError( "Not enough Memory."); return; } } else // Further Xform requested: use separate new image { memcpy( &im, TrPtr->src, sizeof(Image) ); im.data = (unsigned char**) mymalloc( (size_t)im.dataSize ); if( im.data == NULL ) { TrPtr->success = 0; PrintError( "Not enough Memory."); return; } TrPtr->dest = &im; } // JMW 2003/08/25 Use the smaller of the width or height to // calculate luminance so that the same change is made to portrait and // landscape images. // MRDL 2003/08/25 Makes behavior consistent with lens distortion correction // algorithm if( TrPtr->src->width < TrPtr->src->height ) sizesqr = (int)((TrPtr->src->width/2.0) * (TrPtr->src->width/2.0)); else sizesqr = (int)((TrPtr->src->height/2.0) * (TrPtr->src->height/2.0)); if( prefs->lum_params[0] == prefs->lum_params[1] && prefs->lum_params[1] == prefs->lum_params[2] ) // Color independent { lum_params[0] = - prefs->lum_params[0] / sizesqr; lum_params[1] = prefs->lum_params[0] / 2.0 ; if( TrPtr->success != 0 ) { filter( TrPtr, radlum, radlum16, (void*) lum_params, 0 ); } } else // Color dependent { for(k=1; k<4; k++) { lum_params[0] = - prefs->lum_params[k-1] / sizesqr; lum_params[1] = prefs->lum_params[k-1] / 2.0 ; if( TrPtr->success != 0 ) { filter( TrPtr, radlum, radlum16, (void*) lum_params, k ); } } } } if( TrPtr->success && prefs->fourier ) // Fourier filtering required { if( prefs->luminance ) { CopyImageData( src, &im ); TrPtr->src = src; } if( prefs->fourier_mode == _fresize ) { if( prefs->width == 0 && prefs->height == 0 ) { TrPtr->success = 0; PrintError( "Zero Destination Image Size" ); return; } if( prefs->width ) destwidth = prefs->width; else destwidth = (int)((double)TrPtr->src->width * (double)prefs->height / (double)TrPtr->src->height); if( prefs->height) destheight = prefs->height; else destheight = (int)((double)TrPtr->src->height * (double)prefs->width / (double)TrPtr->src->width); } else { destwidth = TrPtr->src->width; destheight = TrPtr->src->height; } // Allocate memory for destination image // If no further Xform: simply use SetDest if( !( prefs->resize || prefs->shear || prefs->horizontal || prefs->vertical || prefs->radial || prefs->cutFrame ) ) { if( SetDestImage(TrPtr, destwidth, destheight) != 0 ) { TrPtr->success = 0; PrintError( "Not enough Memory."); return; } } else // Further Xform requested: use separate new image { if( prefs->luminance ) // since then we have allocated im already { if( im.data ) myfree( (void**)im.data ); } memcpy( &im, TrPtr->src, sizeof(Image) ); im.width = destwidth; im.height = destheight; im.bytesPerLine = im.width * im.bitsPerPixel/8; im.dataSize = im.height * im.bytesPerLine; im.data = (unsigned char**) mymalloc( (size_t)im.dataSize ); if( im.data == NULL ) { TrPtr->success = 0; PrintError( "Not enough Memory."); return; } TrPtr->dest = &im; } fourier( TrPtr, prefs ); } if( TrPtr->success && ( prefs->resize || prefs->shear || prefs->horizontal || prefs->vertical || prefs->radial || prefs->cutFrame) ) // Displacement Xform requested { // First check whether recent luminance or fourier filtering if( prefs->luminance || prefs->fourier ) TrPtr->src = &im; TrPtr->dest = dest; // Set destination image parameters // most Xforms: dest = src destwidth = TrPtr->src->width; destheight = TrPtr->src->height; if( prefs->cutFrame ) { if( getFrame( TrPtr->src, &xoff, &yoff, prefs->fwidth, prefs->fheight, TrPtr->mode & _show_progress ) != 0 ) { TrPtr->success = 0; return; } //PrintError("x= %d, y= %d", xoff, yoff); destwidth = prefs->fwidth ; destheight = prefs->fheight ; } if(prefs->resize) { if( prefs->width == 0 && prefs->height == 0 ) { TrPtr->success = 0; PrintError( "Zero Destination Image Size" ); return; } if( prefs->width ) destwidth = prefs->width; else destwidth = (int)((double)TrPtr->src->width * (double)prefs->height / (double)TrPtr->src->height); if( prefs->height) destheight = prefs->height; else destheight = (int)((double)TrPtr->src->height * (double)prefs->width / (double)TrPtr->src->width); } if( destwidth <= 0 || destheight <= 0 ) { TrPtr->success = 0; PrintError( "Zero Destination Image Size" ); return; } // Allocate memory for destination image if( SetDestImage(TrPtr, destwidth, destheight) != 0 ) { TrPtr->success = 0; PrintError( "Not enough Memory."); goto _correct_exit; } // Check to see if the colors have the same or different displacement paras if( isColorSpecific( prefs ) ) // Color dependent { if( haveSameColorParas( prefs,0,1)) // R==G?? { fprintf(stderr, "PT correct "PROGRESS_VERSION" R==G\n" ); if( ! hasUsefulColorParas(prefs,0)) { fprintf(stderr, "Red/Green do NOTHING! Copying image data...\n" ); CopyImageData( TrPtr->dest, TrPtr->src ); fprintf(stderr, "Displacing just the Blue...\n" ); kstart=3; kend =3; } else if( ! hasUsefulColorParas(prefs,2)) { fprintf(stderr, "Blue does NOTHING! Copying image data...\n" ); CopyImageData( TrPtr->dest, TrPtr->src ); fprintf(stderr, "Displacing the Red/Green simultaneously...\n" ); kstart=4; kend =4; } else { kstart=4; kend =3; } } else if( haveSameColorParas( prefs,1,2)) // G==B?? { fprintf(stderr, "PT correct "PROGRESS_VERSION" G==B\n" ); if( ! hasUsefulColorParas(prefs,1)) { fprintf(stderr, "Green/Blue do NOTHING! Copying image data...\n" ); CopyImageData( TrPtr->dest, TrPtr->src ); fprintf(stderr, "Displacing just the Red...\n" ); kstart=1; kend =1; } else if( ! hasUsefulColorParas(prefs,0)) { fprintf(stderr, "Red does NOTHING! Copying image data...\n" ); CopyImageData( TrPtr->dest, TrPtr->src ); fprintf(stderr, "Displacing the Green/Blue simultaneously...\n" ); kstart=6; kend =6; } else { kstart=6; kend =1; } } else if( haveSameColorParas( prefs,2,0)) // R==B?? { fprintf(stderr, "PT correct "PROGRESS_VERSION" R==B\n" ); if( ! hasUsefulColorParas(prefs,0)) { fprintf(stderr, "Red/Blue do NOTHING! Copying image data...\n" ); CopyImageData( TrPtr->dest, TrPtr->src ); fprintf(stderr, "Displacing just the Green...\n" ); kstart=2; kend =2; } else if( ! hasUsefulColorParas(prefs,1)) { fprintf(stderr, "Green does NOTHING! Copying image data...\n" ); CopyImageData( TrPtr->dest, TrPtr->src ); fprintf(stderr, "Displacing the Red/Blue simultaneously...\n" ); kstart=5; kend =5; } else { kstart=5; kend =2; } } else { fprintf(stderr, "PT correct "PROGRESS_VERSION" R!=G!=B\n" ); if( ! hasUsefulColorParas(prefs,0)) { fprintf(stderr, "Red does NOTHING! Copying image data...\n" ); CopyImageData( TrPtr->dest, TrPtr->src ); fprintf(stderr, "Displacing the Green then Blue separately...\n" ); kstart=2; kend =3; } else if( ! hasUsefulColorParas(prefs,1)) { fprintf(stderr, "Green does NOTHING! Copying image data...\n" ); CopyImageData( TrPtr->dest, TrPtr->src ); fprintf(stderr, "Displacing the Blue then Red separately...\n" ); kstart=3; kend =1; } else if( ! hasUsefulColorParas(prefs,2)) { fprintf(stderr, "Blue does NOTHING! Copying image data...\n" ); CopyImageData( TrPtr->dest, TrPtr->src ); fprintf(stderr, "Displacing the Red then Green separately...\n" ); kstart=1; kend =2; } else { kstart = 1; kend = 3; } } } else // Color independent { fprintf(stderr, "PT correct "PROGRESS_VERSION" R==G==B\n" ); if( ! hasUsefulColorParas(prefs,0)) { fprintf(stderr, "Red,Green,Blue do NOTHING! But you asked for it...\n" ); } kstart = 0; kend = 0; } // Do the necessary displacements, either per color, 2-colors, or on all 3 colors. kdone=0; k=kstart; while(!kdone) { switch(k) // choose which color's paras to use { case 0: // RGB color = 0;// Use the Red paras break; case 1: // [0] = R case 2: // [1] = G case 3: // [2] = B color = k-1; break; case 4:// RG color=0; break; case 5:// RB color=0; break; case 6:// GB color=1; break; default: color=0; break; } i = 0; if( prefs->resize ) { if(prefs->cutFrame) { if( prefs->width ) scale_params[0] = ((double)prefs->fwidth)/ prefs->width; else scale_params[0] = ((double)prefs->fheight)/ prefs->height; if( prefs->height ) scale_params[1] = ((double)prefs->fheight)/ prefs->height; else scale_params[1] = scale_params[0]; } else { if( prefs->width ) scale_params[0] = ((double)TrPtr->src->width)/ prefs->width; else scale_params[0] = ((double)TrPtr->src->height)/ prefs->height; if( prefs->height ) scale_params[1] = ((double)TrPtr->src->height)/ prefs->height; else scale_params[1] = scale_params[0]; } SetDesc(stack[i],resize,scale_params); i++; } // JMW 2008/01/03 make the order the same as Adjust doing correct if( prefs->radial ) { switch( prefs->correction_mode) { case correction_mode_radial: SetDesc(stack[i],radial, radial_params); i++; radial_params[4] = ( (double)( TrPtr->src->width < TrPtr->src->height ? TrPtr->src->width : TrPtr->src->height) ) / 2.0; break; case correction_mode_vertical: SetDesc(stack[i],vertical, radial_params); i++; radial_params[4] = ((double)TrPtr->src->height) / 2.0; break; case correction_mode_deregister: SetDesc(stack[i],deregister, radial_params); i++; radial_params[4] = ((double)TrPtr->src->height) / 2.0; break; } for(j=0; j<4; j++) radial_params[j] = prefs->radial_params[color][j]; radial_params[5] = prefs->radial_params[color][4]; } if (prefs->vertical) { SetDesc(stack[i],vert,&(prefs->vertical_params[color])); i++; } if (prefs->horizontal) { SetDesc(stack[i],horiz,&(prefs->horizontal_params[color]) ); i++; } if( prefs->shear ) { shear_params[0] = prefs->shear_x / TrPtr->src->height; shear_params[1] = prefs->shear_y / TrPtr->src->width; SetDesc(stack[i],shear,shear_params); i++; } if( prefs->cutFrame ) { if( xoff != 0 ) { xdoff = (double) xoff + 0.5 * ( prefs->fwidth - TrPtr->src->width ) ; SetDesc(stack[i],horiz, &xdoff ); i++; } if( yoff != 0 ) { ydoff = (double)yoff + 0.5 * ( prefs->fheight - TrPtr->src->height) ; SetDesc(stack[i],vert,&ydoff); i++; } } stack[i].func = (trfn)NULL; if( !prefs->resize && !prefs->shear && !prefs->horizontal && !prefs->vertical && !prefs->radial && prefs->cutFrame ) // Only cutframe { ShiftImage(TrPtr, xoff, yoff); } else if( TrPtr->success != 0 && i != 0 ) { // Copy and reverse the stack to make the inverse stack int ii = 0; while(i) { stackinv[ii] = stack[i-1]; i--; ii++; } stackinv[ii].func = (trfn)NULL; fD.func = execute_stack_new; fD.param = stack; fDinv.func = execute_stack_new; fDinv.param = stackinv; transFormEx( TrPtr, &fD, &fDinv, k, 1 ); i = ii; } switch(k) // We use k as control var for a little statemachine: { case 0:// RGB kdone=1; break; case 1:// R case 2:// G case 3:// B if(k==kend) { kdone=1; } else { k++; if(k==4) k=1; } break; case 4:// RG case 5:// RB case 6:// GB if(k==kend) { kdone=1; } else { k=kend; } break; default: kdone=1; break; } }// END:while(!kdone) } if( !prefs->luminance && !prefs->fourier && !prefs->cutFrame && i == 0 ) // We did nothing! { TrPtr->success = 0; } if( TrPtr->success == 0 && ! (TrPtr->mode & _destSupplied)) myfree( (void**)TrPtr->dest->data ); _correct_exit: TrPtr->src = src; TrPtr->dest = dest; if( im.data != NULL ) myfree((void**)im.data); }