[Wavelet-commit] Wavelet ImageArray.cc, 1.9, 1.10 ImageResizer.cc, 1.5, 1.6 MagickInter.cc, 1.5, 1.
Status: Beta
Brought to you by:
herbert
From: Herbert M. D. <he...@us...> - 2010-05-19 11:42:44
|
Update of /cvsroot/wavelet/Wavelet In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv17092 Modified Files: ImageArray.cc ImageResizer.cc MagickInter.cc avilib.h Log Message: Set a limit to target sizes for image resizing. Index: MagickInter.cc =================================================================== RCS file: /cvsroot/wavelet/Wavelet/MagickInter.cc,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** MagickInter.cc 19 Oct 2009 12:37:01 -0000 1.5 --- MagickInter.cc 19 May 2010 11:42:36 -0000 1.6 *************** *** 15,19 **** #include <Magick++.h> ! using MagickLib::Quantum; #ifdef WIN32 --- 15,19 ---- #include <Magick++.h> ! //using namespace MagickLib; #ifdef WIN32 Index: avilib.h =================================================================== RCS file: /cvsroot/wavelet/Wavelet/avilib.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** avilib.h 3 Nov 2004 14:19:48 -0000 1.8 --- avilib.h 19 May 2010 11:42:36 -0000 1.9 *************** *** 99,102 **** --- 99,103 ---- #include <stdio.h> #include <fcntl.h> + #include <stdint.h> #if !defined(COMP_MSC) Index: ImageResizer.cc =================================================================== RCS file: /cvsroot/wavelet/Wavelet/ImageResizer.cc,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ImageResizer.cc 21 Sep 2007 08:13:49 -0000 1.5 --- ImageResizer.cc 19 May 2010 11:42:36 -0000 1.6 *************** *** 95,100 **** /* now restore the old image's ratio for the one produced from the max * coefficients in the detail areas */ ! m_maxDetail->resize(m_maxDetail->rows() * oldY / tmp->rows(), ! m_maxDetail->cols() * oldX / tmp->cols()); m_colsMapping = m_image.cols () / m_maxDetail->cols (); m_rowsMapping = m_image.rows () / m_maxDetail->rows (); --- 95,102 ---- /* now restore the old image's ratio for the one produced from the max * coefficients in the detail areas */ ! int newY = m_maxDetail->rows () * oldY / tmp->rows (); ! int newX = m_maxDetail->cols () * oldX / tmp->cols (); ! ! m_maxDetail->resize (newY, newX); m_colsMapping = m_image.cols () / m_maxDetail->cols (); m_rowsMapping = m_image.rows () / m_maxDetail->rows (); Index: ImageArray.cc =================================================================== RCS file: /cvsroot/wavelet/Wavelet/ImageArray.cc,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** ImageArray.cc 29 May 2009 10:25:13 -0000 1.9 --- ImageArray.cc 19 May 2010 11:42:35 -0000 1.10 *************** *** 18,25 **** #endif #include <stdexcept> #include "WImage/tools.h" template <class T> ! ImageArray<T>::ImageArray (void) { m_ar = NULL; --- 18,28 ---- #endif #include <stdexcept> + #include <cassert> + #include <climits> + #include <cstdio> #include "WImage/tools.h" template <class T> ! ImageArray<T>::ImageArray (void) { m_ar = NULL; *************** *** 31,35 **** template <class T> ! ImageArray<T>::ImageArray (int rows, int cols) { m_rows = NULL; --- 34,38 ---- template <class T> ! ImageArray<T>::ImageArray (int rows, int cols) { m_rows = NULL; *************** *** 50,54 **** template <class T> ! ImageArray<T>::~ImageArray (void) { DELETENOTNULLAR (m_ar); --- 53,57 ---- template <class T> ! ImageArray<T>::~ImageArray (void) { DELETENOTNULLAR (m_ar); *************** *** 56,66 **** } ! template <class T>void ImageArray<T>::resize (int rows, int cols) { ! int size = rows*cols; ! int ymin = MIN (rows, m_ysize); ! int xmin = MIN (cols, m_xsize); ! int x = 0, y = 0; if (rows < 0 || cols < 0) { --- 59,66 ---- } ! template <class T>void ImageArray<T>::resize (int rows, int cols) { ! static const int maxSize = INT_MAX / 10; if (rows < 0 || cols < 0) { *************** *** 73,78 **** --- 73,94 ---- "array size cannot be zero."); } + if (INT_MAX / rows < cols || rows * cols > maxSize) + { + char buf[512]; + snprintf (buf, sizeof buf - 1, + "resize: array size would be larger than " + "max allowed size of %d elements.", maxSize); + throw std::invalid_argument (buf); + } + int size = rows * cols; + int ymin = MIN (rows, m_ysize); + int xmin = MIN (cols, m_xsize); + int oldXySize = m_xysize; + int x = 0, y = 0; + //std::cout << "rows: " << rows << std::endl; + //std::cout << "cols: " << cols << std::endl; T *tmp = NEW (T[size]); + //std::cout << "size: " << size << std::endl; m_ysize = rows; *************** *** 85,89 **** //DPRINTF (("resize (%d, %d)\n", m_ysize, m_xsize)); ! for (y = 0; y < ymin; y++) { --- 101,105 ---- //DPRINTF (("resize (%d, %d)\n", m_ysize, m_xsize)); ! for (y = 0; y < ymin; y++) { *************** *** 92,97 **** for (x = 0; x < xmin; x++) { ! //DPRINTF (("tmp[%d+%d] = m_ar[%d+%d]: %d\n", // y1offs, x, y2offs, x, (int)m_ar[y2offs])); tmp[y1offs + x] = m_ar[y2offs + x]; } --- 108,117 ---- for (x = 0; x < xmin; x++) { ! //DPRINTF (("tmp[%d+%d] = m_ar[%d+%d]: %d\n", // y1offs, x, y2offs, x, (int)m_ar[y2offs])); + assert (y1offs + x >= 0); + assert (y2offs + x >= 0); + assert (y1offs + x < size); + assert (y2offs + x < oldXySize); tmp[y1offs + x] = m_ar[y2offs + x]; } *************** *** 102,106 **** } } ! for (; y < m_ysize; y++) { --- 122,126 ---- } } ! for (; y < m_ysize; y++) { *************** *** 118,122 **** } ! template <class T>void ImageArray<T>::import (int rows, int cols, T *array) { --- 138,142 ---- } ! template <class T>void ImageArray<T>::import (int rows, int cols, T *array) { *************** *** 144,148 **** template <class T>void ! ImageArray<T>::copy (ImageArray<T> &ia) { if (ia.size () == 0) --- 164,168 ---- template <class T>void ! ImageArray<T>::copy (ImageArray<T> &ia) { if (ia.size () == 0) *************** *** 167,171 **** ImageArray<T>::epsilons (ImageArray<T> &ia, T epsilon) const { ! if (!(ia.rows () == this->rows () && ia.cols () == this->cols () && ia.size () == this->size ())) --- 187,191 ---- ImageArray<T>::epsilons (ImageArray<T> &ia, T epsilon) const { ! if (!(ia.rows () == this->rows () && ia.cols () == this->cols () && ia.size () == this->size ())) *************** *** 200,206 **** int maxY = (toY < 0? rows (): toY); int maxX = (toX < 0? cols (): toX); ! max = at (fromY, fromX); ! for (int y = fromY; y < maxY; y++) { --- 220,226 ---- int maxY = (toY < 0? rows (): toY); int maxX = (toX < 0? cols (): toX); ! max = at (fromY, fromX); ! for (int y = fromY; y < maxY; y++) { *************** *** 224,230 **** int maxY = (toY < 0? rows (): toY); int maxX = (toX < 0? cols (): toX); ! min = at (fromY, fromX); ! for (int y = fromY; y < maxY; y++) { --- 244,250 ---- int maxY = (toY < 0? rows (): toY); int maxX = (toX < 0? cols (): toX); ! min = at (fromY, fromX); ! for (int y = fromY; y < maxY; y++) { *************** *** 248,255 **** int maxY = (toY < 0? rows (): toY); int maxX = (toX < 0? cols (): toX); ! max = at (fromY, fromX); max = (max < 0? -1*max: max); ! for (int y = fromY; y < maxY; y++) { --- 268,275 ---- int maxY = (toY < 0? rows (): toY); int maxX = (toX < 0? cols (): toX); ! max = at (fromY, fromX); max = (max < 0? -1*max: max); ! for (int y = fromY; y < maxY; y++) { *************** *** 274,281 **** int maxY = (toY < 0? rows (): toY); int maxX = (toX < 0? cols (): toX); ! min = at (fromY, fromX); min = (min < 0? -1*min : min); ! for (int y = fromY; y < maxY; y++) { --- 294,301 ---- int maxY = (toY < 0? rows (): toY); int maxX = (toX < 0? cols (): toX); ! min = at (fromY, fromX); min = (min < 0? -1*min : min); ! for (int y = fromY; y < maxY; y++) { *************** *** 309,313 **** } } ! return (nVals > 0)? ret / static_cast < T > (nVals): 0; } --- 329,333 ---- } } ! return (nVals > 0)? ret / static_cast < T > (nVals): 0; } *************** *** 330,334 **** } } ! return (nVals > 0)? ret / static_cast < T > (nVals): 0; } --- 350,354 ---- } } ! return (nVals > 0)? ret / static_cast < T > (nVals): 0; } *************** *** 336,340 **** ! template <class T>void ImageArray<T>::updateRowsArray (void) { --- 356,360 ---- ! template <class T>void ImageArray<T>::updateRowsArray (void) { |