From: kiirala Date: Fri, 4 Jan 2008 21:22:26 +0000 (+0000) Subject: Added more error checking to filter effects code X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=b0fc1b5cad067af61ffdc6ff82667bfea7ef3f77;p=inkscape.git Added more error checking to filter effects code --- diff --git a/src/display/nr-filter-colormatrix.cpp b/src/display/nr-filter-colormatrix.cpp index e5a3ca33f..61f9970f1 100644 --- a/src/display/nr-filter-colormatrix.cpp +++ b/src/display/nr-filter-colormatrix.cpp @@ -29,6 +29,11 @@ FilterColorMatrix::~FilterColorMatrix() int FilterColorMatrix::render(FilterSlot &slot, FilterUnits const &/*units*/) { NRPixBlock *in = slot.get(_input); + if (!in) { + g_warning("Missing source image for feColorMatrix (in=%d)", _input); + return 1; + } + NRPixBlock *out = new NRPixBlock; nr_pixblock_setup_fast(out, in->mode, diff --git a/src/display/nr-filter-component-transfer.cpp b/src/display/nr-filter-component-transfer.cpp index 270e2296c..9b2003402 100644 --- a/src/display/nr-filter-component-transfer.cpp +++ b/src/display/nr-filter-component-transfer.cpp @@ -28,6 +28,11 @@ FilterComponentTransfer::~FilterComponentTransfer() int FilterComponentTransfer::render(FilterSlot &slot, FilterUnits const &/*units*/) { NRPixBlock *in = slot.get(_input); + if (!in) { + g_warning("Missing source image for feComponentTransfer (in=%d)", _input); + return 1; + } + NRPixBlock *out = new NRPixBlock; nr_pixblock_setup_fast(out, in->mode, @@ -38,6 +43,7 @@ int FilterComponentTransfer::render(FilterSlot &slot, FilterUnits const &/*units unsigned char *out_data = NR_PIXBLOCK_PX(out); //IMPLEMENT ME! + g_warning("Renderer for feComponentTransfer is not implemented."); (void)in_data; (void)out_data; diff --git a/src/display/nr-filter-convolve-matrix.cpp b/src/display/nr-filter-convolve-matrix.cpp index fe28c4b0b..360ff6567 100644 --- a/src/display/nr-filter-convolve-matrix.cpp +++ b/src/display/nr-filter-convolve-matrix.cpp @@ -36,6 +36,11 @@ static bool inside_area(int px, int py, int w, int h){ int FilterConvolveMatrix::render(FilterSlot &slot, FilterUnits const &/*units*/) { NRPixBlock *in = slot.get(_input); + if (!in) { + g_warning("Missing source image for feConvolveMatrix (in=%d)", _input); + return 1; + } + NRPixBlock *out = new NRPixBlock; nr_pixblock_setup_fast(out, in->mode, diff --git a/src/display/nr-filter-diffuselighting.cpp b/src/display/nr-filter-diffuselighting.cpp index 9ff3922e8..0fca45095 100644 --- a/src/display/nr-filter-diffuselighting.cpp +++ b/src/display/nr-filter-diffuselighting.cpp @@ -52,6 +52,11 @@ do {\ int FilterDiffuseLighting::render(FilterSlot &slot, FilterUnits const &units) { NRPixBlock *in = filter_get_alpha(slot.get(_input)); + if (!in) { + g_warning("Missing source image for feDiffuseLighting (in=%d)", _input); + return 1; + } + NRPixBlock *out = new NRPixBlock; int w = in->area.x1 - in->area.x0; diff --git a/src/display/nr-filter-flood.cpp b/src/display/nr-filter-flood.cpp index 55576842b..7eade2789 100644 --- a/src/display/nr-filter-flood.cpp +++ b/src/display/nr-filter-flood.cpp @@ -28,6 +28,11 @@ FilterFlood::~FilterFlood() int FilterFlood::render(FilterSlot &slot, FilterUnits const &/*units*/) { NRPixBlock *in = slot.get(_input); + if (!in) { + g_warning("Missing source image for feFlood (in=%d)", _input); + return 1; + } + NRPixBlock *out = new NRPixBlock; nr_pixblock_setup_fast(out, in->mode, diff --git a/src/display/nr-filter-gaussian.cpp b/src/display/nr-filter-gaussian.cpp index fdab94f1d..a3fa37bd7 100644 --- a/src/display/nr-filter-gaussian.cpp +++ b/src/display/nr-filter-gaussian.cpp @@ -508,9 +508,14 @@ upsample(PT *const dst, int const dstr1, int const dstr2, unsigned int const dn1 int FilterGaussian::render(FilterSlot &slot, FilterUnits const &units) { - Matrix trans = units.get_matrix_primitiveunits2pb(); /* in holds the input pixblock */ NRPixBlock *in = slot.get(_input); + if (!in) { + g_warning("Missing source image for feGaussianBlur (in=%d)", _input); + return 1; + } + + Matrix trans = units.get_matrix_primitiveunits2pb(); /* If to either direction, the standard deviation is zero or * input image is not defined, diff --git a/src/display/nr-filter-getalpha.cpp b/src/display/nr-filter-getalpha.cpp index 1aba770a3..72c05c797 100644 --- a/src/display/nr-filter-getalpha.cpp +++ b/src/display/nr-filter-getalpha.cpp @@ -21,6 +21,11 @@ NRPixBlock *filter_get_alpha(NRPixBlock *src) nr_pixblock_setup_fast(dst, NR_PIXBLOCK_MODE_R8G8B8A8P, src->area.x0, src->area.y0, src->area.x1, src->area.y1, false); + if (!dst || (dst->size != NR_PIXBLOCK_SIZE_TINY && dst->data.px == NULL)) { + g_warning("Memory allocation failed in filter_get_alpha"); + delete dst; + return NULL; + } nr_blit_pixblock_pixblock(dst, src); unsigned char *data = NR_PIXBLOCK_PX(dst); diff --git a/src/display/nr-filter-image.cpp b/src/display/nr-filter-image.cpp index 2d32cc51a..028744b5c 100644 --- a/src/display/nr-filter-image.cpp +++ b/src/display/nr-filter-image.cpp @@ -57,6 +57,11 @@ int FilterImage::render(FilterSlot &slot, FilterUnits const &/*units*/) { } int w,x,y; NRPixBlock *in = slot.get(_input); + if (!in) { + g_warning("Missing source image for feImage (in=%d)", _input); + return 1; + } + NRPixBlock *out = new NRPixBlock; int x0 = in->area.x0, y0 = in->area.y0; diff --git a/src/display/nr-filter-merge.cpp b/src/display/nr-filter-merge.cpp index ed060b649..977d4fbf8 100644 --- a/src/display/nr-filter-merge.cpp +++ b/src/display/nr-filter-merge.cpp @@ -57,12 +57,14 @@ int FilterMerge::render(FilterSlot &slot, FilterUnits const &/*units*/) { NRPixBlock *out; - // Bail out if either one of source images is missing + // Bail out if one of source images is missing for (unsigned int i = 0 ; i < _input_image.size() ; i++) { + bool missing = false; if (!in[i]) { g_warning("Missing source image for feMerge (number=%d slot=%d)", i, _input_image[i]); - return 1; + missing = true; } + if (missing) return 1; } out = new NRPixBlock; diff --git a/src/display/nr-filter-morphology.cpp b/src/display/nr-filter-morphology.cpp index abc529aad..4ef0b6ad3 100644 --- a/src/display/nr-filter-morphology.cpp +++ b/src/display/nr-filter-morphology.cpp @@ -27,6 +27,11 @@ FilterMorphology::~FilterMorphology() int FilterMorphology::render(FilterSlot &slot, FilterUnits const &/*units*/) { NRPixBlock *in = slot.get(_input); + if (!in) { + g_warning("Missing source image for feMorphology (in=%d)", _input); + return 1; + } + NRPixBlock *out = new NRPixBlock; int x0=in->area.x0; diff --git a/src/display/nr-filter-offset.cpp b/src/display/nr-filter-offset.cpp index 85df3351f..683c4f83d 100644 --- a/src/display/nr-filter-offset.cpp +++ b/src/display/nr-filter-offset.cpp @@ -34,14 +34,14 @@ FilterOffset::~FilterOffset() int FilterOffset::render(FilterSlot &slot, FilterUnits const &units) { NRPixBlock *in = slot.get(_input); - NRPixBlock *out = new NRPixBlock; - // Bail out if source image is missing if (!in) { g_warning("Missing source image for feOffset (in=%d)", _input); return 1; } + NRPixBlock *out = new NRPixBlock; + Matrix trans = units.get_matrix_primitiveunits2pb(); Point offset(dx, dy); offset *= trans; diff --git a/src/display/nr-filter-slot.cpp b/src/display/nr-filter-slot.cpp index 62a8717bb..432598b7c 100644 --- a/src/display/nr-filter-slot.cpp +++ b/src/display/nr-filter-slot.cpp @@ -205,7 +205,11 @@ void FilterSlot::set(int slot_nr, NRPixBlock *pb) min_x, min_y, max_x, max_y, true); if (trans_pb->size != NR_PIXBLOCK_SIZE_TINY && trans_pb->data.px == NULL) { - // memory allocation failed + /* TODO: this gets hit occasionally. Worst case scenario: + * images are exported in horizontal stripes. One stripe + * is not too high, but can get thousands of pixels wide. + * Rotate this 45 degrees -> _huge_ image */ + g_warning("Memory allocation failed in NR::FilterSlot::set (transform)"); return; } transform_nearest(trans_pb, pb, trans); @@ -231,7 +235,7 @@ void FilterSlot::set(int slot_nr, NRPixBlock *pb) nr_pixblock_setup_fast(trans_pb, pb->mode, min_x, min_y, max_x, max_y, true); if (trans_pb->size != NR_PIXBLOCK_SIZE_TINY && trans_pb->data.px == NULL) { - //memory allocation failed + g_warning("Memory allocation failed in NR::FilterSlot::set (scaling)"); return; } scale_bicubic(trans_pb, pb); diff --git a/src/display/nr-filter-specularlighting.cpp b/src/display/nr-filter-specularlighting.cpp index 3f459f164..d579bf5f7 100644 --- a/src/display/nr-filter-specularlighting.cpp +++ b/src/display/nr-filter-specularlighting.cpp @@ -61,6 +61,11 @@ do {\ int FilterSpecularLighting::render(FilterSlot &slot, FilterUnits const &units) { NRPixBlock *in = filter_get_alpha(slot.get(_input)); + if (!in) { + g_warning("Missing source image for feSpecularLighting (in=%d)", _input); + return 1; + } + NRPixBlock *out = new NRPixBlock; //Fvector *L = NULL; //vector to the light diff --git a/src/display/nr-filter-tile.cpp b/src/display/nr-filter-tile.cpp index b058db2bc..565bc8c7e 100644 --- a/src/display/nr-filter-tile.cpp +++ b/src/display/nr-filter-tile.cpp @@ -28,6 +28,11 @@ FilterTile::~FilterTile() int FilterTile::render(FilterSlot &slot, FilterUnits const &/*units*/) { NRPixBlock *in = slot.get(_input); + if (!in) { + g_warning("Missing source image for feTile (in=%d)", _input); + return 1; + } + NRPixBlock *out = new NRPixBlock; nr_pixblock_setup_fast(out, in->mode, @@ -38,6 +43,7 @@ int FilterTile::render(FilterSlot &slot, FilterUnits const &/*units*/) { unsigned char *out_data = NR_PIXBLOCK_PX(out); //IMPLEMENT ME! + g_warning("Renderer for feTile is not implemented."); (void)in_data; (void)out_data; diff --git a/src/display/nr-filter-turbulence.cpp b/src/display/nr-filter-turbulence.cpp index 8d3bc290c..74c229109 100644 --- a/src/display/nr-filter-turbulence.cpp +++ b/src/display/nr-filter-turbulence.cpp @@ -84,7 +84,6 @@ void FilterTurbulence::update_pixbuffer(FilterSlot &/*slot*/, IRect &area) { if (!pix){ pix = new NRPixBlock; nr_pixblock_setup_fast(pix, NR_PIXBLOCK_MODE_R8G8B8A8N, bbox_x0, bbox_y0, bbox_x1, bbox_y1, true); - pix_data = NR_PIXBLOCK_PX(pix); } else if (bbox_x0 != pix->area.x0 || bbox_y0 != pix->area.y0 || bbox_x1 != pix->area.x1 || bbox_y1 != pix->area.y1) @@ -93,9 +92,17 @@ void FilterTurbulence::update_pixbuffer(FilterSlot &/*slot*/, IRect &area) { * width and height don't change */ nr_pixblock_release(pix); nr_pixblock_setup_fast(pix, NR_PIXBLOCK_MODE_R8G8B8A8N, bbox_x0, bbox_y0, bbox_x1, bbox_y1, true); - pix_data = NR_PIXBLOCK_PX(pix); } + if (!pix || (pix->size != NR_PIXBLOCK_SIZE_TINY && pix->data.px == NULL)) { + /* TODO: Should render the visible area or something instead. */ + g_warning("Unable to reserve image buffer for feTurbulence"); + pix_data = NULL; + return; + } + + pix_data = NR_PIXBLOCK_PX(pix); + TurbulenceInit((long)seed); double point[2]; @@ -128,9 +135,17 @@ int FilterTurbulence::render(FilterSlot &slot, FilterUnits const &units) { IRect area = units.get_pixblock_filterarea_paraller(); // TODO: could be faster - updated_area only has to be same size as area if (!updated || updated_area != area) update_pixbuffer(slot, area); - + if (!pix_data) { + /* update_pixbuffer couldn't render the turbulence */ + return 1; + } NRPixBlock *in = slot.get(_input); + if (!in) { + g_warning("Missing source image for feTurbulence (in=%d)", _input); + return 1; + } NRPixBlock *out = new NRPixBlock; + int x,y; int x0 = in->area.x0, y0 = in->area.y0; int x1 = in->area.x1, y1 = in->area.y1;