Bug 329 - Removed asserts and replaced with proper debug/errors.

git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@1967 e3e1d417-86f3-4887-817a-d78f3d33393f
This commit is contained in:
stan 2006-05-08 12:46:53 +00:00
parent 79ca312388
commit 8a49cf7e12
2 changed files with 62 additions and 17 deletions

View File

@ -91,7 +91,10 @@ Image::BlendTablePtr Image::GetBlendTable( int transparency )
Image *Image::HighlightEdges( Rgb colour, const Box *limits ) Image *Image::HighlightEdges( Rgb colour, const Box *limits )
{ {
assert( colours = 1 ); if ( colours != 1 )
{
Fatal(( "Attempt to highlight image edges when colours = %d", colours ));
}
Image *high_image = new Image( width, height, 3 ); Image *high_image = new Image( width, height, 3 );
int lo_x = limits?limits->Lo().X():0; int lo_x = limits?limits->Lo().X():0;
int lo_y = limits?limits->Lo().Y():0; int lo_y = limits?limits->Lo().Y():0;
@ -202,7 +205,13 @@ bool Image::ReadJpeg( const char *filename )
height = cinfo->image_height; height = cinfo->image_height;
pixels = width*height; pixels = width*height;
colours = cinfo->num_components; colours = cinfo->num_components;
assert( colours == 1 || colours == 3 ); if ( !(colours == 1 || colours == 3) )
{
Error(( "Unexpected colours (%d) when reading jpeg image", colours ));
jpeg_abort_decompress( cinfo );
fclose( infile );
return( false );
}
int new_size = width*height*colours; int new_size = width*height*colours;
if ( !buffer || size < new_size ) if ( !buffer || size < new_size )
{ {
@ -320,7 +329,12 @@ bool Image::DecodeJpeg( const JOCTET *inbuffer, int inbuffer_size )
height = cinfo->image_height; height = cinfo->image_height;
pixels = width*height; pixels = width*height;
colours = cinfo->num_components; colours = cinfo->num_components;
assert( colours == 1 || colours == 3 ); if ( !(colours == 1 || colours == 3) )
{
Error(( "Unexpected colours (%d) when decoding jpeg image", colours ));
jpeg_abort_decompress( cinfo );
return( false );
}
int new_size = width*height*colours; int new_size = width*height*colours;
if ( !buffer || size < new_size ) if ( !buffer || size < new_size )
{ {
@ -437,7 +451,7 @@ bool Image::Crop( int lo_x, int lo_y, int hi_x, int hi_y )
} }
if ( lo_x < 0 || hi_x > (width-1) || ( lo_y < 0 || hi_y > (height-1) ) ) if ( lo_x < 0 || hi_x > (width-1) || ( lo_y < 0 || hi_y > (height-1) ) )
{ {
Error(( "Attempting to crop outside image, %d,%d -> %d,%d not in %d,%d", lo_x, lo_y, hi_x, hi_y, width, height )); Error(( "Attempting to crop outside image, %d,%d -> %d,%d not in %d,%d", lo_x, lo_y, hi_x, hi_y, width-1, height-1 ));
return( false ); return( false );
} }
@ -478,8 +492,10 @@ bool Image::Crop( int lo_x, int lo_y, int hi_x, int hi_y )
void Image::Overlay( const Image &image ) void Image::Overlay( const Image &image )
{ {
//assert( width == image.width && height == image.height && colours == image.colours ); if ( !(width == image.width && height == image.height) )
assert( width == image.width && height == image.height ); {
Fatal(( "Attempt to overlay different sized images, expected %dx%d, got %dx%d", width, height, image.width, image.height ));
}
unsigned char *pdest = buffer; unsigned char *pdest = buffer;
unsigned char *psrc = image.buffer; unsigned char *psrc = image.buffer;
@ -547,7 +563,10 @@ void Image::Overlay( const Image &image )
void Image::Blend( const Image &image, int transparency ) const void Image::Blend( const Image &image, int transparency ) const
{ {
assert( width == image.width && height == image.height && colours == image.colours ); if ( !(width == image.width && height == image.height && colours == image.colours) )
{
Fatal(( "Attempt to blend different sized images, expected %dx%dx%d, got %dx%dx%d", width, height, colours, image.width, image.height, image.colours ));
}
if ( config.fast_image_blends ) if ( config.fast_image_blends )
{ {
@ -599,7 +618,10 @@ Image *Image::Merge( int n_images, Image *images[] )
int colours = images[0]->colours; int colours = images[0]->colours;
for ( int i = 1; i < n_images; i++ ) for ( int i = 1; i < n_images; i++ )
{ {
assert( width == images[i]->width && height == images[i]->height && colours == images[i]->colours ); if ( !(width == images[i]->width && height == images[i]->height && colours == images[i]->colours) )
{
Fatal(( "Attempt to merge different sized images, expected %dx%dx%d, got %dx%dx%d, for image %d", width, height, colours, images[i]->width, images[i]->height, images[i]->colours, i ));
}
} }
Image *result = new Image( width, height, images[0]->colours ); Image *result = new Image( width, height, images[0]->colours );
@ -630,7 +652,10 @@ Image *Image::Merge( int n_images, Image *images[], double weight )
int colours = images[0]->colours; int colours = images[0]->colours;
for ( int i = 1; i < n_images; i++ ) for ( int i = 1; i < n_images; i++ )
{ {
assert( width == images[i]->width && height == images[i]->height && colours == images[i]->colours ); if ( !(width == images[i]->width && height == images[i]->height && colours == images[i]->colours) )
{
Fatal(( "Attempt to merge different sized images, expected %dx%dx%d, got %dx%dx%d, for image %d", width, height, colours, images[i]->width, images[i]->height, images[i]->colours, i ));
}
} }
Image *result = new Image( *images[0] ); Image *result = new Image( *images[0] );
@ -661,7 +686,10 @@ Image *Image::Highlight( int n_images, Image *images[], const Rgb threshold, con
int colours = images[0]->colours; int colours = images[0]->colours;
for ( int i = 1; i < n_images; i++ ) for ( int i = 1; i < n_images; i++ )
{ {
assert( width == images[i]->width && height == images[i]->height && colours == images[i]->colours ); if ( !(width == images[i]->width && height == images[i]->height && colours == images[i]->colours) )
{
Fatal(( "Attempt to highlight different sized images, expected %dx%dx%d, got %dx%dx%d, for image %d", width, height, colours, images[i]->width, images[i]->height, images[i]->colours, i ));
}
} }
Image *result = new Image( width, height, images[0]->colours ); Image *result = new Image( width, height, images[0]->colours );
@ -691,7 +719,10 @@ Image *Image::Highlight( int n_images, Image *images[], const Rgb threshold, con
Image *Image::Delta( const Image &image ) const Image *Image::Delta( const Image &image ) const
{ {
assert( width == image.width && height == image.height && colours == image.colours ); if ( !(width == image.width && height == image.height && colours == image.colours) )
{
Fatal(( "Attempt to get delta of different sized images, expected %dx%dx%d, got %dx%dx%d", width, height, colours, image.width, image.height, image.colours ));
}
Image *result = new Image( width, height, 1 ); Image *result = new Image( width, height, 1 );
@ -938,7 +969,10 @@ void Image::DeColourise()
void Image::Fill( Rgb colour, const Box *limits ) void Image::Fill( Rgb colour, const Box *limits )
{ {
assert( colours == 1 || colours == 3 ); if ( !(colours == 1 || colours == 3 ) )
{
Fatal(( "Attempt to fill image with unexpected colours %d", colours ));
}
int lo_x = limits?limits->Lo().X():0; int lo_x = limits?limits->Lo().X():0;
int lo_y = limits?limits->Lo().Y():0; int lo_y = limits?limits->Lo().Y():0;
int hi_x = limits?limits->Hi().X():width-1; int hi_x = limits?limits->Hi().X():width-1;
@ -972,7 +1006,10 @@ void Image::Fill( Rgb colour, const Box *limits )
void Image::Fill( Rgb colour, int density, const Box *limits ) void Image::Fill( Rgb colour, int density, const Box *limits )
{ {
assert( colours == 1 || colours == 3 ); if ( !(colours == 1 || colours == 3 ) )
{
Fatal(( "Attempt to fill image with unexpected colours %d", colours ));
}
int lo_x = limits?limits->Lo().X():0; int lo_x = limits?limits->Lo().X():0;
int lo_y = limits?limits->Lo().Y():0; int lo_y = limits?limits->Lo().Y():0;
@ -1002,7 +1039,10 @@ void Image::Fill( Rgb colour, int density, const Box *limits )
void Image::Outline( Rgb colour, const Polygon &polygon ) void Image::Outline( Rgb colour, const Polygon &polygon )
{ {
assert( colours == 1 || colours == 3 ); if ( !(colours == 1 || colours == 3 ) )
{
Fatal(( "Attempt to outline image with unexpected colours %d", colours ));
}
int n_coords = polygon.getNumCoords(); int n_coords = polygon.getNumCoords();
for ( int j = 0, i = n_coords-1; j < n_coords; i = j++ ) for ( int j = 0, i = n_coords-1; j < n_coords; i = j++ )
{ {
@ -1088,7 +1128,10 @@ void Image::Outline( Rgb colour, const Polygon &polygon )
void Image::Fill( Rgb colour, int density, const Polygon &polygon ) void Image::Fill( Rgb colour, int density, const Polygon &polygon )
{ {
assert( colours == 1 || colours == 3 ); if ( !(colours == 1 || colours == 3 ) )
{
Fatal(( "Attempt to fill image with unexpected colours %d", colours ));
}
int n_coords = polygon.getNumCoords(); int n_coords = polygon.getNumCoords();
int n_global_edges = 0; int n_global_edges = 0;

View File

@ -24,7 +24,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <assert.h>
#include <time.h> #include <time.h>
#include <math.h> #include <math.h>
#include <zlib.h> #include <zlib.h>
@ -226,7 +225,10 @@ public:
inline void CopyBuffer( const Image &image ) inline void CopyBuffer( const Image &image )
{ {
assert( width == image.width && height == image.height && colours == image.colours ); if ( image.size != size )
{
Fatal(( "Attempt to copy different size image buffers, expected %d, got %d", size, image.size ));
}
memcpy( buffer, image.buffer, size ); memcpy( buffer, image.buffer, size );
} }
inline Image &operator=( const unsigned char *new_buffer ) inline Image &operator=( const unsigned char *new_buffer )