Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bmpcodec 16bpp decoding #276

Merged
merged 1 commit into from
Jul 17, 2018
Merged

Conversation

hughbe
Copy link
Contributor

@hughbe hughbe commented Apr 2, 2018

Fixes #189
Fixes #157

src/bmpcodec.c Outdated
return OutOfMemory;
bmi->bV5BlueMask = (data_read[3]<<24 | data_read[2]<<16 | data_read[1]<<8 | data_read[0]);

return Ok;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't sound right. I don't think the masks are even present there with BITMAPINFOHEADER when biCompression is BI_RGB. In that case it should use the default 16 bits per pixel values:

bmi->red_mask = 0x7C00;
bmi->green_mask = 0x3E0;
bmi->blue_mask = 0x1F;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cause of this issue was #285 which needs to be fixed (I'll do so separately)

Addressed this feedback though

tests/testtext Outdated
@@ -0,0 +1,210 @@
#! /bin/sh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now .gitignored right? Shouldn't be part of the commit. :-)

src/bmpcodec.c Outdated
@@ -738,7 +750,7 @@ gdip_read_BITMAPINFOHEADER (void *pointer, ImageSource source, BITMAPV5HEADER *b
bmi->bV5ClrUsed = 0;
bmi->bV5ClrImportant = 0;

return Ok;
goto fill_rgb_masks;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks kind of useless. There will never be masks since there's no compression and hence no BI_BITFIELDS (bV5Compression should be set to BI_RGB for clarity). And it will never be 16-bit since the allowed values for bcBitCount are only 1, 4, 8, and 24 (https://msdn.microsoft.com/en-us/library/windows/desktop/dd183372(v=vs.85).aspx).

src/bmpcodec.c Outdated
bmi->bV5GreenMask = 0x3E0;
bmi->bV5BlueMask = 0x1F;
return Ok;
}
Copy link
Contributor

@filipnavara filipnavara Apr 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two blocks could probably be moved up to the "goto fill_rgb_masks" point and then the mask reading code could be shared instead of being duplicated. In fact, I think the if (bmi->bV5BitCount != 16) block is unnecessary.

@hughbe hughbe force-pushed the bmp-codec-16bpp branch from 1d2dea7 to 96d51d1 Compare April 5, 2018 15:02
src/bmpcodec.c Outdated
return OutOfMemory;
bmi->bV5BlueMask = (data_read[3]<<24 | data_read[2]<<16 | data_read[1]<<8 | data_read[0]);
}

Copy link
Contributor

@filipnavara filipnavara Apr 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason why you don't fall through to the code below? Also, now the implicit BI_RGB masks from previous change are missing...

I meant something like

if (bmi->bV5Compression == BI_RGB) {
   ... // set the 16-bit 555 masks
   return Ok;
}

and later on after bmi->bV5BlueMask = (data_read[3]<<24 | data_read[2]<<16 | data_read[1]<<8 | data_read[0]); (line 807 in original, 840 now) add something like

if (bmi->bV5Size == sizeof (BITMAPINFOHEADER))
   return Ok;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the record I don't mind the code duplication if it makes the code more readable. It's matter of personal opinion and I find your version little more readable even though it's a bit verbose... but the BI_RGB part has to be fixed in either case.

@hughbe hughbe force-pushed the bmp-codec-16bpp branch from 96d51d1 to 48f0ac3 Compare April 6, 2018 07:06
Copy link
Contributor

@filipnavara filipnavara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure that 5-6-5 and 5-5-5 are the only supported 16 BPP formats? I realize that some conversion would be necessary and that it was not supported before.

Thanks for addressing my feedback. Looks good to me now.

@hughbe
Copy link
Contributor Author

hughbe commented Apr 6, 2018

Yeah these are the only 16bpp formats. I don't quite understand what happens yet with unknown masks because it seems a bit confusing: #292

@hughbe hughbe force-pushed the bmp-codec-16bpp branch from 48f0ac3 to bb647b9 Compare June 15, 2018 00:49
@marek-safar marek-safar merged commit 7be3455 into mono:master Jul 17, 2018
@hughbe hughbe deleted the bmp-codec-16bpp branch July 17, 2018 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants