suicao / aforge

Automatically exported from code.google.com/p/aforge
Other
0 stars 0 forks source link

Convolution filter generating AccessViolationException for 640x480 16bpp gray scale image #262

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

Apply the convolution filter to a 16bpp gray scale image having resolution 
640x480, the following exception is thrown:

System.AccessViolationException was unhandled
  Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

The offending line is no. 395:

  r += k * p[RGB.R];

using a 3x3 kernel {{-1, 0, 0}, {0, 1, 0}, {0, 0, 0}}

What is the expected output? What do you see instead?

The expected result is the exception not being thrown

What version of the product are you using?

2.2.2

Please provide any additional information below.

The problem occurs with 640x480 resolution only. Tried 320x240, 800x600 and it 
doesn't happen.

My idea is that this line (261) has a bug:

// check pixel size to find if we deal with 8 or 16 bpp channels
if ( pixelSize <= 4 )

I've fixed changing it as follows:

if ((pixelSize <= 4) && (destination.PixelFormat != 
PixelFormat.Format16bppGrayScale))

but not 100% sure it's the correct way to handle it.
I've just noticed that the else branch has comments regarding 16bpp grayscale, 
but it is never reached as pixel size for 16bpp is 2.

Original issue reported on code.google.com by jede...@gmail.com on 11 Nov 2011 at 3:39

GoogleCodeExporter commented 9 years ago

Original comment by andrew.k...@gmail.com on 11 Nov 2011 at 3:59

GoogleCodeExporter commented 9 years ago
Fixing Convolution filter so it processes correctly 16bpp grayscale images. 
Previously there was a bug causing 16 bpp grayscale images to be processed as 
24/32 colour image.

Committed in revision 1630. Will be released in version 2.2.3.

P.S. Yes, the suggested fix is correct. Another way could be 
if ((pixelSize <= 4) && (pixelSize != 2))
This type of check was aready there for some other filters.

Original comment by andrew.k...@gmail.com on 11 Nov 2011 at 4:04

GoogleCodeExporter commented 9 years ago
Great.

Thank you very much for your quick fix release :)

And congrats for this excellent framework.

Original comment by jede...@gmail.com on 11 Nov 2011 at 4:17

GoogleCodeExporter commented 9 years ago
It is not released. It is just fixed. So for now users need to build from SVN 
if they want to get the fix. Formal release will be done later.

Original comment by andrew.k...@gmail.com on 11 Nov 2011 at 4:36

GoogleCodeExporter commented 9 years ago

Original comment by andrew.k...@gmail.com on 12 Dec 2011 at 9:16