Skip to content
This repository was archived by the owner on Nov 19, 2020. It is now read-only.

Conversation

@hzawary
Copy link
Contributor

@hzawary hzawary commented Aug 22, 2017

Hi dear Dr,

When developed 'FastBoxBlur' filter On Jan 8 was a correct and tested code, but today when use it, give this exception:

An unhandled exception of type 'System.AccessViolationException' occurred in mscorlib.dll

Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Finally I found some codes in changes! I used this before:
var pixelSize = ((image.PixelFormat == PixelFormat.Format8bppIndexed) || (image.PixelFormat == PixelFormat.Format16bppGrayScale)) ? 1 : 3;
but now see this in 140 and 219 lines:
int pixelSize = image.GetPixelFormatSizeInBytes();

Regards,
H.Zawary

Use of 'Accord.Imaging.GetPixelFormatSizeInBytes()' was wrong, cause of traverse the image incorrectly and attempted to read or write protected memory.
@cesarsouza
Copy link
Member

Hi Hashem,

Ops, the effects of my changes had not caught by the unit tests. Sorry about that.

However, if the pixel size for 8-bpp grayscale images is 1, then wouldn't the size for a 16-bpp grayscale image be 2 instead of 3?

I think that the problem is not in the use of GetPixelFormatSizeInBytes() function, but rather in line 188 (and related) where the algorithm is multiplying that value by 2. Also, maybe the code should not be using a byte*, but rather a short* which in this case would have the correct size of 2 bytes.

Thanks a lot again for the contribution and sorry for breaking it, but please let me know what you think about those changes!

Regards,
Cesar

@hzawary
Copy link
Contributor Author

hzawary commented Aug 23, 2017

First things I think the correct result is the matter! Test with 8, 16, 24 images, that's okey. If you like to change with the other way, correct result is the matter :) However, for this context pixel size set to 1 if we have a grayscale (8 or 16) image and set to 3 if color(32, 48).

@cesarsouza cesarsouza merged commit 5b52418 into accord-net:development Aug 25, 2017
@cesarsouza
Copy link
Member

Hi Hashem,

I understand. I think it is also better to restore the broken functionality as soon as possible. Thanks a lot for the fix!

Regards,
Cesar

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants