📄 discalet.h
字号:
{ *(q++) = value; ++x; } while (x <= d_right) // - middle { *(q++) = *(p++); ++x; } while (x < this->Src_X) // - right { *(q++) = value; ++x; } p += x_feed; } for (i = b_feed; i != 0; --i) // bottom *(q++) = value; p += y_feed; } } } /** enlarge image by an integer factor. * Pixels are replicated independently in both directions. * ** @param src array of pointers to source image pixels * @param dest array of pointers to destination image pixels */ void replicatePixel(const T *src[], T *dest[]) { const Uint16 x_factor = this->Dest_X / this->Src_X; const Uint16 y_factor = this->Dest_Y / this->Src_Y; const unsigned long x_feed = Columns; const unsigned long y_feed = OFstatic_cast(unsigned long, Rows - this->Src_Y) * OFstatic_cast(unsigned long, Columns); const T *sp; register Uint16 x; register Uint16 y; register Uint16 dx; register Uint16 dy; register const T *p; register T *q; register T value; for (int j = 0; j < this->Planes; ++j) { sp = src[j] + OFstatic_cast(unsigned long, Top) * OFstatic_cast(unsigned long, Columns) + Left; q = dest[j]; for (Uint32 f = this->Frames; f != 0; --f) { for (y = this->Src_Y; y != 0; --y) { for (dy = y_factor; dy != 0; --dy) { for (x = this->Src_X, p = sp; x != 0; --x) { value = *(p++); for (dx = x_factor; dx != 0; --dx) *(q++) = value; } } sp += x_feed; } sp += y_feed; } } } /** shrink image by an integer divisor * Pixels are suppressed independently in both directions. * ** @param src array of pointers to source image pixels * @param dest array of pointers to destination image pixels */ void suppressPixel(const T *src[], T *dest[]) { const unsigned int x_divisor = this->Src_X / this->Dest_X; const unsigned long x_feed = OFstatic_cast(unsigned long, this->Src_Y / this->Dest_Y) * OFstatic_cast(unsigned long, Columns) - this->Src_X; const unsigned long y_feed = OFstatic_cast(unsigned long, Rows - this->Src_Y) * OFstatic_cast(unsigned long, Columns); register Uint16 x; register Uint16 y; register const T *p; register T *q; for (int j = 0; j < this->Planes; ++j) { p = src[j] + OFstatic_cast(unsigned long, Top) * OFstatic_cast(unsigned long, Columns) + Left; q = dest[j]; for (Uint32 f = this->Frames; f != 0; --f) { for (y = this->Dest_Y; y != 0; --y) { for (x = this->Dest_X; x != 0; --x) { *(q++) = *p; p += x_divisor; } p += x_feed; } p += y_feed; } } } /** free scaling method without interpolation. * This algorithm is necessary for overlays (1 bpp). * ** @param src array of pointers to source image pixels * @param dest array of pointers to destination image pixels */ void scalePixel(const T *src[], T *dest[]) { const Uint16 xmin = (this->Dest_X < this->Src_X) ? this->Dest_X : this->Src_X; // minimum width const Uint16 ymin = (this->Dest_Y < this->Src_Y) ? this->Dest_Y : this->Src_Y; // minimum height Uint16 *x_step = new Uint16[xmin]; Uint16 *y_step = new Uint16[ymin]; Uint16 *x_fact = new Uint16[xmin]; Uint16 *y_fact = new Uint16[ymin]; /* * Approach: If one pixel line has to be added or removed it is taken from the middle of the image (1/2). * For two lines it is at 1/3 and 2/3 of the image and so on. It sounds easy but it was a hard job ;-) */ if ((x_step != NULL) && (y_step != NULL) && (x_fact != NULL) && (y_fact != NULL)) { register Uint16 x; register Uint16 y; if (this->Dest_X < this->Src_X) setScaleValues(x_step, this->Dest_X, this->Src_X); else if (this->Dest_X > this->Src_X) setScaleValues(x_fact, this->Src_X, this->Dest_X); if (this->Dest_X <= this->Src_X) OFBitmanipTemplate<Uint16>::setMem(x_fact, 1, xmin); // initialize with default values if (this->Dest_X >= this->Src_X) OFBitmanipTemplate<Uint16>::setMem(x_step, 1, xmin); // initialize with default values x_step[xmin - 1] += Columns - this->Src_X; // skip to next line if (this->Dest_Y < this->Src_Y) setScaleValues(y_step, this->Dest_Y, this->Src_Y); else if (this->Dest_Y > this->Src_Y) setScaleValues(y_fact, this->Src_Y, this->Dest_Y); if (this->Dest_Y <= this->Src_Y) OFBitmanipTemplate<Uint16>::setMem(y_fact, 1, ymin); // initialize with default values if (this->Dest_Y >= this->Src_Y) OFBitmanipTemplate<Uint16>::setMem(y_step, 1, ymin); // initialize with default values y_step[ymin - 1] += Rows - this->Src_Y; // skip to next frame const T *sp; register Uint16 dx; register Uint16 dy; register const T *p; register T *q; register T value; for (int j = 0; j < this->Planes; ++j) { sp = src[j] + OFstatic_cast(unsigned long, Top) * OFstatic_cast(unsigned long, Columns) + Left; q = dest[j]; for (Uint32 f = 0; f < this->Frames; ++f) { for (y = 0; y < ymin; ++y) { for (dy = 0; dy < y_fact[y]; ++dy) { for (x = 0, p = sp; x < xmin; ++x) { value = *p; for (dx = 0; dx < x_fact[x]; ++dx) *(q++) = value; p += x_step[x]; } } sp += OFstatic_cast(unsigned long, y_step[y]) * OFstatic_cast(unsigned long, Columns); } } } } delete[] x_step; delete[] y_step; delete[] x_fact; delete[] y_fact; } /** free scaling method with interpolation. * ** @param src array of pointers to source image pixels * @param dest array of pointers to destination image pixels */ void interpolatePixel(const T *src[], T *dest[]) { if ((this->Src_X != Columns) || (this->Src_Y != Rows)) { if (DicomImageClass::checkDebugLevel(DicomImageClass::DL_Errors)) { ofConsole.lockCerr() << "ERROR: interpolated scaling and clipping at the same time not implemented" << endl << " ... ignoring clipping region !" << endl; ofConsole.unlockCerr(); } this->Src_X = Columns; // temporarily removed 'const' for 'Src_X' in class 'DiTransTemplate' this->Src_Y = Rows; // ... 'Src_Y' ... } /* * based on scaling algorithm from "Extended Portable Bitmap Toolkit" (pbmplus10dec91) * (adapted to be used with signed pixel representation and inverse images - mono2) */ register Uint16 x; register Uint16 y; register const T *p; register T *q; T const *sp = NULL; // initialization avoids compiler warning T const *fp; T *sq; const unsigned long sxscale = OFstatic_cast(unsigned long, (OFstatic_cast(double, this->Dest_X) / OFstatic_cast(double, this->Src_X)) * SCALE_FACTOR); const unsigned long syscale = OFstatic_cast(unsigned long, (OFstatic_cast(double, this->Dest_Y) / OFstatic_cast(double, this->Src_Y)) * SCALE_FACTOR); DiPixelRepresentationTemplate<T> rep; const signed long maxvalue = DicomImageClass::maxval(this->Bits - rep.isSigned()); T *xtemp = new T[this->Src_X]; signed long *xvalue = new signed long[this->Src_X]; if ((xtemp == NULL) || (xvalue == NULL)) { if (DicomImageClass::checkDebugLevel(DicomImageClass::DL_Errors)) { ofConsole.lockCerr() << "ERROR: can't allocate temporary buffers for interpolation scaling !" << endl; ofConsole.unlockCerr(); } const unsigned long count = OFstatic_cast(unsigned long, this->Dest_X) * OFstatic_cast(unsigned long, this->Dest_Y) * this->Frames; for (int j = 0; j < this->Planes; ++j) OFBitmanipTemplate<T>::zeroMem(dest[j], count); // delete destination buffer } else { for (int j = 0; j < this->Planes; ++j) { fp = src[j]; sq = dest[j]; for (Uint32 f = this->Frames; f != 0; --f) { for (x = 0; x < this->Src_X; ++x) xvalue[x] = HALFSCALE_FACTOR; register unsigned long yfill = SCALE_FACTOR; register unsigned long yleft = syscale; register int yneed = 1; int ysrc = 0; for (y = 0; y < this->Dest_Y; ++y) { if (this->Src_Y == this->Dest_Y) { sp = fp; for (x = this->Src_X, p = sp, q = xtemp; x != 0; --x) *(q++) = *(p++); fp += this->Src_X; } else { while (yleft < yfill) { if (yneed && (ysrc < OFstatic_cast(int, this->Src_Y))) { sp = fp; fp += this->Src_X; ++ysrc; } for (x = 0, p = sp; x < this->Src_X; ++x) xvalue[x] += yleft * OFstatic_cast(signed long, *(p++)); yfill -= yleft; yleft = syscale; yneed = 1; } if (yneed && (ysrc < OFstatic_cast(int, this->Src_Y))) { sp = fp; fp += this->Src_X; ++ysrc; yneed = 0; } for (x = 0, p = sp, q = xtemp; x < this->Src_X; ++x) { register signed long v = xvalue[x] + yfill * OFstatic_cast(signed long, *(p++)); v /= SCALE_FACTOR; *(q++) = OFstatic_cast(T, (v > maxvalue) ? maxvalue : v); xvalue[x] = HALFSCALE_FACTOR; } yleft -= yfill; if (yleft == 0) { yleft = syscale; yneed = 1; } yfill = SCALE_FACTOR; } if (this->Src_X == this->Dest_X) { for (x = this->Dest_X, p = xtemp, q = sq; x != 0; --x) *(q++) = *(p++); sq += this->Dest_X; } else { register signed long v = HALFSCALE_FACTOR; register unsigned long xfill = SCALE_FACTOR; register unsigned long xleft; register int xneed = 0; q = sq; for (x = 0, p = xtemp; x < this->Src_X; ++x, ++p) { xleft = sxscale; while (xleft >= xfill) { if (xneed) { ++q; v = HALFSCALE_FACTOR; } v += xfill * OFstatic_cast(signed long, *p); v /= SCALE_FACTOR; *q = OFstatic_cast(T, (v > maxvalue) ? maxvalue : v); xleft -= xfill; xfill = SCALE_FACTOR; xneed = 1; } if (xleft > 0) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -