VBandInterp VImageColorInterp (VImage image) { VLong interp; VGetAttrResult result; if (VImageNBands (image) != (VImageNFrames (image) * VImageNViewpoints (image) * VImageNColors (image) * VImageNComponents (image))) VWarning ("VImageColorInterp: No. bands (%d) conflicts with no. " "of frames, etc. (%d %d %d %d)", VImageNBands (image), VImageNFrames (image), VImageNViewpoints (image), VImageNColors (image), VImageNComponents (image)); if (! VImageAttrList (image) || (result = VGetAttr (VImageAttrList (image), VColorInterpAttr, VBandInterpDict, VLongRepn, & interp)) == VAttrMissing) return VImageNColors (image) > 1 ? VBandInterpOther : VBandInterpNone; if (result == VAttrBadValue) return VBandInterpOther; switch (interp) { case VBandInterpRGB: if (VImageNColors (image) != 3) { VWarning ("VBandColorInterp: RGB image has %d color dimension(s)", VImageNColors (image)); return VBandInterpOther; } return VBandInterpRGB; } return VBandInterpOther; }
VImage VCopyImageAttrs (VImage src, VImage dest) { VAttrList list; if (src == dest) return dest; if (! dest) { dest = VCreateImage (VImageNBands (src), VImageNRows (src), VImageNColumns (src), VPixelRepn (src)); if (! dest) return NULL; } /* Clone the source image's attribute list if it isn't empty: */ if (! VAttrListEmpty (VImageAttrList (src))) { list = VImageAttrList (dest); VImageAttrList (dest) = VCopyAttrList (VImageAttrList (src)); } else if (! VAttrListEmpty (VImageAttrList (dest))) { list = VImageAttrList (dest); VImageAttrList (dest) = VCreateAttrList (); } else list = NULL; if (list) VDestroyAttrList (list); /* Preserve band interpretation attributes only if the source and destination images have the same number of bands: */ if (VImageNBands (src) > 1 && VImageNBands (dest) == VImageNBands (src)) { VImageNFrames (dest) = VImageNFrames (src); VImageNViewpoints (dest) = VImageNViewpoints (src); VImageNColors (dest) = VImageNColors (src); VImageNComponents (dest) = VImageNComponents (src); } else { VExtractAttr (VImageAttrList (dest), VFrameInterpAttr, NULL, VBitRepn, NULL, FALSE); VExtractAttr (VImageAttrList (dest), VViewpointInterpAttr, NULL, VBitRepn, NULL, FALSE); VExtractAttr (VImageAttrList (dest), VColorInterpAttr, NULL, VBitRepn, NULL, FALSE); VExtractAttr (VImageAttrList (dest), VComponentInterpAttr, NULL, VBitRepn, NULL, FALSE); VImageNComponents (dest) = VImageNColors (dest) = VImageNViewpoints (dest) = 1; VImageNFrames (dest) = VImageNBands (dest); } return dest; }
VBoolean VSetBandInterp (VImage image, VBandInterp frame_interp, int nframes, VBandInterp viewpoint_interp, int nviewpoints, VBandInterp color_interp, int ncolors, VBandInterp component_interp, int ncomponents) { VBoolean result = TRUE; VString str; if (VImageNBands (image) != nframes * nviewpoints * ncolors * ncomponents) { VWarning ("VSetBandInterp: No. bands (%d) conflicts with no. " "of frames, etc. (%d %d %d %d)", VImageNBands (image), nframes, nviewpoints, ncolors, ncomponents); result = FALSE; } if (frame_interp == VBandInterpNone) result &= VExtractAttr (VImageAttrList (image), VFrameInterpAttr, NULL, VStringRepn, & str, FALSE); else VSetAttr (VImageAttrList (image), VFrameInterpAttr, VBandInterpDict, VLongRepn, (VLong) frame_interp); VImageNFrames (image) = nframes; if (viewpoint_interp == VBandInterpNone) result &= VExtractAttr (VImageAttrList (image), VViewpointInterpAttr, NULL, VStringRepn, & str, FALSE); else VSetAttr (VImageAttrList (image), VViewpointInterpAttr, VBandInterpDict, VLongRepn, (VLong) viewpoint_interp); VImageNViewpoints (image) = nviewpoints; if (color_interp == VBandInterpNone) result &= VExtractAttr (VImageAttrList (image), VColorInterpAttr, NULL, VStringRepn, & str, FALSE); else VSetAttr (VImageAttrList (image), VColorInterpAttr, VBandInterpDict, VLongRepn, (VLong) color_interp); VImageNColors (image) = ncolors; if (component_interp == VBandInterpNone) result &= VExtractAttr (VImageAttrList (image), VComponentInterpAttr, NULL, VStringRepn, & str, FALSE); else VSetAttr (VImageAttrList (image), VComponentInterpAttr, VBandInterpDict, VLongRepn, (VLong) component_interp); VImageNComponents (image) = ncomponents; return result; }
static VAttrList VImageEncodeAttrMethod (VPointer value, size_t *lengthp) { VImage image = value; VAttrList list; size_t length; #define OptionallyPrepend(value, name) \ if (value != 1) \ VPrependAttr (list, name, NULL, VLongRepn, (VLong) value) /* Temporarily prepend several attributes to the image's attribute list: */ if ((list = VImageAttrList (image)) == NULL) list = VImageAttrList (image) = VCreateAttrList (); VPrependAttr (list, VRepnAttr, VNumericRepnDict, VLongRepn, (VLong) VPixelRepn (image)); VPrependAttr (list, VNColumnsAttr, NULL, VLongRepn, (VLong) VImageNColumns (image)); VPrependAttr (list, VNRowsAttr, NULL, VLongRepn, (VLong) VImageNRows (image)); OptionallyPrepend (VImageNComponents (image), VNComponentsAttr); OptionallyPrepend (VImageNColors (image), VNColorsAttr); OptionallyPrepend (VImageNViewpoints (image), VNViewpointsAttr); OptionallyPrepend (VImageNFrames (image), VNFramesAttr); OptionallyPrepend (VImageNBands (image), VNBandsAttr); /* Compute the file space needed for the image's binary data: */ length = VImageNPixels (image); if (VPixelRepn (image) == VBitRepn) length = (length + 7) / 8; else length *= VPixelPrecision (image) / 8; *lengthp = length; return list; #undef OptionallyPrepend }
void VImageManager::prepareScaleValue() { QPtrList<V_ImageRec>::iterator it = m_imageList.begin(); unsigned int lastIndex = 90; if ( lastIndex >= m_imageList.count() ) lastIndex = m_imageList.count(); for ( unsigned int i = 0; i < lastIndex; i++ ) { VImage src = m_imageList.at( i ); int ncols = VImageNColumns( src ); int nrows = VImageNRows( src ); int nbands = VImageNFrames( src ); int npixels = nbands * nrows * ncols; int smin = ( int )VRepnMinValue( VShortRepn ); int smax = ( int )VRepnMaxValue( VShortRepn ); int i = 0, j = 0; int dim = 2 * smax + 1; float *histo = new float[dim]; for ( j = 0; j < dim; j++ ) histo[j] = 0; VShort *src_pp = ( VShort * ) VImageData( src ); for ( i = 0; i < ( int )( npixels ); i++ ) { j = *src_pp; src_pp ++; j -= smin; histo[j]++; } float sum = 0; for ( j = 0; j < dim; j++ ) sum += histo[j]; for ( j = 0; j < dim; j++ ) histo[j] /= sum; sum = 0; for ( j = 0; j < dim; j++ ) { sum += histo[j]; if ( sum > m_black ) break; } int xmin = j + smin; sum = 0; for ( j = dim; j > 0; j-- ) { sum += histo[j]; if ( sum > m_white ) break; } int xmax = j + smin; if ( xmin < m_xmin ) m_xmin = xmin; if ( xmax > m_xmax ) m_xmax = xmax; } }
BilderCW::BilderCW( QWidget *parent, const char *name, prefs *pr_, VString pat, double *ca, double *cp, double *extent, double *fixpoint, const char *version, int *scalingfaktor ) : QWidget( parent, name ), pr(pr_), pat_m(pat), version_m(version), ca_m(ca), cp_m(cp), extent_m(extent), fixpoint_m(fixpoint), scalingfaktor_m(scalingfaktor) { if (pr->verbose) fprintf(stderr,"Starting bilderCW...\n"); rows=VImageNRows(src[0]); columns=VImageNColumns(src[0]); bands=VImageNFrames(src[0]); if (fnc[0]) { fnc_rows=VImageNRows(fnc[pr->active]); fnc_columns=VImageNColumns(fnc[pr->active]); fnc_bands=VImageNFrames(fnc[pr->active]); } else { fnc_rows=0; fnc_columns=0; fnc_bands=0; } if (pr->hgfarbe[0]==1) { setPalette( QPalette( QColor( 255, 255, 255 ) ) ); } else { setPalette( QPalette( QColor( 0,0,0) ) ); } hlayout = new QHBoxLayout( this, 0 ); layout = new QGridLayout( hlayout, 0, (int)pr->infilenum/4, 0); pr->ogl=0; if ( QGLFormat::hasOpenGL() && pr->graph[0] ) pr->ogl=1; QBitmap cb( cb_width, cb_height, cb_bits, TRUE ); QBitmap cm( cm_width, cm_height, cm_bits, TRUE ); QCursor custom( cb, cm ); // create bitmap cursor if (pr->verbose) qDebug("GL-Support %d\n", pr->ogl); files=pr->infilenum; if (pr->infilenum>=pr->zmapfilenum) { if (pr->infilenum>pr->zmapfilenum && pr->zmapfilenum>1) { QMessageBox::warning( this, "error", "error\n" ); } files=pr->infilenum; } else { if (pr->infilenum<pr->zmapfilenum && pr->infilenum>1) { QMessageBox::warning( this, "error", "error\n" ); } else files=pr->zmapfilenum; } bild1 = (pictureView **) VMalloc(sizeof(pictureView *) * (files+1) ); bild2 = (pictureView **) VMalloc(sizeof(pictureView *) * (files+1) ); bild3 = (pictureView **) VMalloc(sizeof(pictureView *) * (files+1) ); ogl = (MyGLDrawer **) VMalloc(sizeof(MyGLDrawer *) * (files+1) ); if (fnc[0]) { pr->slidefaktor[0] = 1000.0/(pr->pmax-pr->zeropoint); pr->slidefaktor[1] = 1000.0/(pr->nmax+pr->zeropoint); posslide = new QSlider( QSlider::Vertical, this, "positive" ); posslide->setPalette( parent->palette() ); posslide->setCursor( pointingHandCursor ); QToolTip::add( posslide, QRect( 0, 0, 2, 2 ), "positive slider" ); QWhatsThis::add( posslide, "This is a Slider.\n" "Here you can change the positive threshold for the z-value."); negslide = new QSlider( QSlider::Vertical, this, "negative" ); negslide->setPalette( parent->palette() ); negslide->setCursor( pointingHandCursor ); QToolTip::add( negslide, QRect( 0, 0, 2, 2 ), "negative slider" ); QWhatsThis::add( negslide, "This is a Slider.\n" "Here you can change the negative threshold for the z-value."); posslide->setGeometry( 10, 80, 100, 15 ); posslide->setRange( int(pr->zeropoint*pr->slidefaktor[0]), int(pr->pmax*pr->slidefaktor[0]) ); posslide->setValue( int(pr->thresh*pr->slidefaktor[0]) ); posslide->setTickmarks(QSlider::TickSetting( 2 )); posslide->setTickInterval((int)100); posslide->setFocusPolicy ( QWidget::NoFocus); negslide->setGeometry( 10, 80, 100, 15 ); negslide->setRange( int(-pr->zeropoint*pr->slidefaktor[1]), int(pr->nmax*pr->slidefaktor[1]) ); if ( pr->thresh ) negslide->setValue( int(pr->nmax*pr->slidefaktor[1]) ); else negslide->setValue( int(pr->zeropoint*pr->slidefaktor[1]) ); negslide->setTickmarks(QSlider::TickSetting( 2 )); negslide->setTickInterval((int)100); negslide->setFocusPolicy ( QWidget::NoFocus); } gLayout(this); if (pr->verbose) fprintf(stderr,"end of bilderCW.C\n"); }
VBandInterp VImageComponentInterp (VImage image) { VLong interp; VGetAttrResult result; if (VImageNBands (image) != (VImageNFrames (image) * VImageNViewpoints (image) * VImageNColors (image) * VImageNComponents (image))) VWarning ("VImageComponentInterp: No. bands (%d) conflicts with no. " "of frames, etc. (%d %d %d %d)", VImageNBands (image), VImageNFrames (image), VImageNViewpoints (image), VImageNColors (image), VImageNComponents (image)); if (! VImageAttrList (image) || (result = VGetAttr (VImageAttrList (image), VComponentInterpAttr, VBandInterpDict, VLongRepn, & interp)) == VAttrMissing) return VImageNComponents (image) > 1 ? VBandInterpOther : VBandInterpNone; if (result == VAttrBadValue) return VBandInterpOther; switch (interp) { case VBandInterpComplex: if (VImageNComponents (image) != 2) { VWarning ("VBandColorInterp: Complex image has %d component(s)", VImageNComponents (image)); return VBandInterpOther; } return VBandInterpComplex; case VBandInterpGradient: if (VImageNComponents (image) > 3) { VWarning ("VBandColorInterp: Gradient image has %d component(s)", VImageNComponents (image)); return VBandInterpOther; } return VBandInterpGradient; case VBandInterpIntensity: if (VImageNComponents (image) > 1) { VWarning ("VBandColorInterp: Intensity image has %d component(s)", VImageNComponents (image)); return VBandInterpOther; } return VBandInterpIntensity; case VBandInterpOrientation: if (VImageNComponents (image) > 1) { VWarning ("VBandColorInterp: " "Orientation image has %d component(s)", VImageNComponents (image)); return VBandInterpOther; } return VBandInterpOrientation; } return VBandInterpOther; }
static VPointer VImageDecodeMethod (VStringConst name, VBundle b) { VImage image; VLong nbands, nrows, ncolumns, pixel_repn; VLong nframes, nviewpoints, ncolors, ncomponents; VAttrList list; size_t length; #define Extract(name, dict, locn, required) \ VExtractAttr (b->list, name, dict, VLongRepn, & locn, required) /* Extract the number of bands, rows, columns, pixel repn, etc.: */ nbands = nframes = nviewpoints = ncolors = ncomponents = 1; /* defaults */ if (! Extract (VNBandsAttr, NULL, nbands, FALSE) || ! Extract (VNRowsAttr, NULL, nrows, TRUE) || ! Extract (VNColumnsAttr, NULL, ncolumns, TRUE) || ! Extract (VRepnAttr, VNumericRepnDict, pixel_repn, TRUE) || ! Extract (VNFramesAttr, NULL, nframes, FALSE) || ! Extract (VNViewpointsAttr, NULL, nviewpoints, FALSE) || ! Extract (VNColorsAttr, NULL, ncolors, FALSE) || ! Extract (VNComponentsAttr, NULL, ncomponents, FALSE)) return NULL; /* Ensure that nbands == nframes * nviewpoints * ncolors * ncomponents. For backwards compatibility, set ncomponents to nbands if nbands != 1 but nframes == nviewpoints == ncolors == ncomponents == 1. */ if (nbands != nframes * nviewpoints * ncolors * ncomponents) { if (nbands != 1 && nframes == 1 && nviewpoints == 1 && ncolors == 1 && ncomponents == 1) ncomponents = nbands; else { VWarning ("VImageDecodeMethod: %s image has inconsistent nbands", name); return NULL; } } /* Create an image with the specified properties: */ if (! (image = VCreateImage ((int) nbands, (int) nrows, (int) ncolumns, (VRepnKind) pixel_repn))) return NULL; VImageNFrames (image) = nframes; VImageNViewpoints (image) = nviewpoints; VImageNColors (image) = ncolors; VImageNComponents (image) = ncomponents; /* Give it whatever attributes remain: */ list = VImageAttrList (image); VImageAttrList (image) = b->list; b->list = list; /* Check that the expected amount of binary data was read: */ length = VImageNPixels (image); if (VPixelRepn (image) == VBitRepn) length = (length + 7) / 8; else length *= VPixelPrecision (image) / 8; if (length != b->length) { VWarning ("VImageDecodeMethod: %s image has wrong data length", name); Fail: VDestroyImage (image); return NULL; } /* Unpack the binary pixel data: */ length = VImageSize (image); if (! VUnpackData (VPixelRepn (image), VImageNPixels (image), b->data, VMsbFirst, & length, & VImageData (image), NULL)) goto Fail; return image; #undef Extract }