Thread: [Wavelet-commit] Wavelet ColorImage.cc, 1.9, 1.10 Image.cc, 1.26, 1.27 ImageResizer.cc, 1.3, 1.4
Status: Beta
Brought to you by:
herbert
From: Herbert M. D. <he...@us...> - 2007-08-24 15:24:36
|
Update of /cvsroot/wavelet/Wavelet In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv10904 Modified Files: ColorImage.cc Image.cc ImageResizer.cc Log Message: New Image::fill() and ColorImage::fill() operations, extensions to the ImageResizer class, the actual resizing after cropping can now be skipped. Index: ColorImage.cc =================================================================== RCS file: /cvsroot/wavelet/Wavelet/ColorImage.cc,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** ColorImage.cc 7 Aug 2007 17:00:58 -0000 1.9 --- ColorImage.cc 24 Aug 2007 15:24:27 -0000 1.10 *************** *** 55,58 **** --- 55,68 ---- } + ColorImage::ColorImage (int rows, int cols, int colors, clrmodel cmodel) + : ColorBuffer (colors, cmodel) + { + for (int i = 0; i < m_colors; i++) + { + m_images[i] = NEW (StillImage (rows, cols)); + } + } + + ColorImage::~ColorImage (void) { *************** *** 421,424 **** --- 431,452 ---- } + void + ColorImage::fill (coeff *values, int fromY, int fromX, int toY, int toX) + { + for (int i = 0; i < colors (); i++) + { + m_images[i]->fill (values[i], fromY, fromX, toY, toX); + } + } + + void + ColorImage::fill (int *values, int fromY, int fromX, int toY, int toX) + { + for (int i = 0; i < colors (); i++) + { + m_images[i]->fill (values[i], fromY, fromX, toY, toX); + } + } + ColorImage * ColorImage::fitInto (int rows, int cols, int *fill, int function) const Index: Image.cc =================================================================== RCS file: /cvsroot/wavelet/Wavelet/Image.cc,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** Image.cc 15 Aug 2007 13:13:57 -0000 1.26 --- Image.cc 24 Aug 2007 15:24:28 -0000 1.27 *************** *** 133,136 **** --- 133,151 ---- } + void + Image::fill (coeff value, int fromY, int fromX, int toY, int toX) + { + int lower = (toY < 0)? m_ysize: toY; + int right = (toX < 0)? m_xsize: toX; + + for (int y = (fromY < 0? 0: fromY); y < lower && y < m_ysize; y++) + { + for (int x = (fromX < 0? 0: fromX); x < right && x < m_xsize; x++) + { + this->to (y, x, value); + } + } + } + coeff Image::sqvariance (int fromY, int fromX, int toY, int toX) const *************** *** 810,814 **** { image->to (y, x, g_calc[function] (*this, ! y - rowOffset, x - colOffset, theFactor)); } } --- 825,831 ---- { image->to (y, x, g_calc[function] (*this, ! y - rowOffset, ! x - colOffset, ! theFactor)); } } Index: ImageResizer.cc =================================================================== RCS file: /cvsroot/wavelet/Wavelet/ImageResizer.cc,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ImageResizer.cc 10 Aug 2007 18:38:14 -0000 1.3 --- ImageResizer.cc 24 Aug 2007 15:24:28 -0000 1.4 *************** *** 27,36 **** int *fill, coeff threshold, bool optimizeImage, int scalingStrategy) ! : m_image (img), m_maxDetail (NULL), m_filter (flt), ! m_qRows (0), m_qCols (0), m_scalingStrategy (scalingStrategy), m_innerAvgPerSize (0), m_innerSDeviation (0), m_innerRegionSize (0), m_threshold (threshold), m_optimizeImage (optimizeImage), m_optimizationCalculated (false), ! m_cropMaxRows (0), m_cropMaxCols (0), m_rowsMapping (0), m_colsMapping (0) { if (fill == NULL) --- 27,36 ---- int *fill, coeff threshold, bool optimizeImage, int scalingStrategy) ! : m_image (img), m_maxDetail (NULL), m_filter (flt), m_qRows (0), m_qCols (0), m_scalingStrategy (scalingStrategy), m_innerAvgPerSize (0), m_innerSDeviation (0), m_innerRegionSize (0), m_threshold (threshold), m_optimizeImage (optimizeImage), m_optimizationCalculated (false), ! m_cropMaxRows (0), m_cropMaxCols (0), m_rowsMapping (0), m_colsMapping (0), ! m_steps (-1) { if (fill == NULL) *************** *** 65,68 **** --- 65,70 ---- WaveletTransform *transform = NULL; + DELETENOTNULL (m_maxDetail); + /* perform a wavelet transform on all channels and from this calculate the * image containing the max values from all channels' detail areas */ *************** *** 132,138 **** ColorImage* ! ImageResizer::doResizeImage(int rows, int cols, int discardRows, int discardCols) { ! ColorImage *tmp = NULL; if (discardRows > 0 || discardCols > 0) { --- 134,140 ---- ColorImage* ! ImageResizer::getCroppedImage (int discardRows, int discardCols) { ! ColorImage *result = NULL; if (discardRows > 0 || discardCols > 0) { *************** *** 144,153 **** /* TOOD this is far from optimal, but let's just see how it works first */ ! tmp = m_image.crop (fromY, fromX, sizeY, sizeX); } else { ! tmp = m_image.clone (); } if (m_cropWhat == CROP_AUTOMATICALLY) --- 146,235 ---- /* TOOD this is far from optimal, but let's just see how it works first */ ! result = m_image.crop (fromY, fromX, sizeY, sizeX); } else { ! result = m_image.clone (); ! } ! ! return result; ! } ! ! ColorImage* ! ImageResizer::getUnscaledImage (int rows, int cols, int discardRows, int discardCols) ! { ! ColorImage *tmp = getCroppedImage (discardRows, discardCols); ! ! if (m_fill == NULL) ! { ! return tmp; ! } ! ! int yoffs, xoffs, ysize, xsize; ! double oldRatio = (double)tmp->rows () / tmp->cols (); ! double newRatio = (double)rows / cols; ! if (oldRatio < newRatio) ! { ! // need to add rows ! // ysize / tmp->cols () == newRatio ! ysize = (int)(newRatio * tmp->cols () + 0.5); ! yoffs = (ysize - tmp->rows ()) / 2; ! xsize = tmp->cols (); ! xoffs = 0; ! assert (ysize >= tmp->rows ()); ! } ! else ! { ! // need to add cols ! // tmp->rows () / xsize == newRatio ! xsize = (int)(tmp->rows () / newRatio + 0.5); ! xoffs = (xsize - tmp->cols ()) / 2; ! ysize = tmp->rows (); ! yoffs = 0; ! assert (xsize >= tmp->cols ()); ! } ! assert (!(xsize != tmp->cols () && ysize != tmp->rows ())); ! ! if (ysize != tmp->rows () || xsize != tmp->cols ()) ! { ! ColorImage *result = NEW (ColorImage (ysize, xsize, ! tmp->colors (), tmp->colormodel ())); ! ! result->paste (yoffs, xoffs, *tmp); ! ! if (ysize > tmp->rows ()) ! { ! int fillRows = (result->rows () - tmp->rows () + 1) / 2; ! ! result->fill (m_fill, ! 0, 0, ! fillRows, result->cols ()); ! ! result->fill (m_fill, ! tmp->rows () + fillRows, 0, ! result->rows (), result->cols ()); ! } ! else ! { ! int fillCols = (result->cols () - tmp->cols () + 1) / 2; ! ! result->fill (m_fill, ! 0, 0, ! result->rows (), fillCols); ! ! result->fill (m_fill, ! 0, tmp->cols () + fillCols, ! result->rows (), result->cols ()); ! } ! DELETE (tmp); ! return result; } + return tmp; + } + + ColorImage* + ImageResizer::getScaledImage (int rows, int cols, int discardRows, int discardCols) + { + ColorImage *tmp = getCroppedImage (discardRows, discardCols); if (m_cropWhat == CROP_AUTOMATICALLY) *************** *** 349,353 **** ColorImage* ! ImageResizer::resize(int rows, int cols, int steps) { if ((rows <= 0 || cols <= 0) && !(rows == 0 && cols == 0 && m_optimizeImage)) --- 431,435 ---- ColorImage* ! ImageResizer::doResize (int rows, int cols, int steps, bool redimensionOnly) { if ((rows <= 0 || cols <= 0) && !(rows == 0 && cols == 0 && m_optimizeImage)) *************** *** 359,363 **** /* no dimension change necessary? do the job and go away */ ! if (m_cropWhat == CROP_BOTH_OR_NONE && !m_optimizeImage) { return m_image.scale (m_qRows, m_scalingStrategy); --- 441,445 ---- /* no dimension change necessary? do the job and go away */ ! if (m_cropWhat == CROP_BOTH_OR_NONE && !m_optimizeImage && !redimensionOnly) { return m_image.scale (m_qRows, m_scalingStrategy); *************** *** 365,370 **** /* We call genMaxDetail only once to save time */ ! if (m_maxDetail == NULL) { genMaxDetail (steps); } --- 447,453 ---- /* We call genMaxDetail only once to save time */ ! if (m_maxDetail == NULL || steps != m_steps) { + m_steps = steps; genMaxDetail (steps); } *************** *** 414,421 **** } ! ColorImage *ret = doResizeImage (rows, cols, nDiscardRows, nDiscardCols); ! ! return ret; } --- 497,515 ---- } ! return redimensionOnly? ! getUnscaledImage (rows, cols, nDiscardRows, nDiscardCols) : ! getScaledImage (rows, cols, nDiscardRows, nDiscardCols); } + ColorImage* + ImageResizer::resize (int rows, int cols, int steps) + { + return doResize (rows, cols, steps, false); + } + + ColorImage* + ImageResizer::redimension (int rows, int cols, int steps) + { + return doResize (rows, cols, steps, true); + } |