-
-
Couldn't load subscription status.
- Fork 888
Add support for decoding and encoding of TGA images #1026
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
Conversation
|
@JimBobSquarePants I think this is ready for review. I noticed there is maybe an issue with InternalDetectFormat. For example you could pass in the two bytes stream 0xFFD8 and it will passs as a valid JPEG file, even though the length check indicates it should be at least 11 bytes. |
|
Thanks @brianpopow I'm amazed how good you are at working with all these formats! I'll have a good read of the supplied specification (thanks for adding that) and go through your code. On the point of the format detector. Yes, that sounds dangerous, we should review it. 👍 |
Codecov Report
@@ Coverage Diff @@
## master #1026 +/- ##
==========================================
+ Coverage 89.89% 89.94% +0.04%
==========================================
Files 1107 1123 +16
Lines 49156 49768 +612
Branches 3447 3515 +68
==========================================
+ Hits 44191 44764 +573
- Misses 4253 4279 +26
- Partials 712 725 +13
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really great work!! 👍
Just a few comments and what looks like a bug to me.
| } | ||
|
|
||
| int colorMapPixelSizeInBytes = this.fileHeader.CMapDepth / 8; | ||
| var palette = new byte[this.fileHeader.CMapLength * colorMapPixelSizeInBytes]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the maximum size here? Maybe we should stackalloc a Span<byte> or if too large use pooling?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a typical size would be between 512 and 768, but the specification states its possible to have a CmapLength of 4096 with 8 bit for each entry.
| { | ||
| // There is no magick bytes in a tga file, so at least the image type | ||
| // and the colormap type in the header will be checked for a valid value. | ||
| if (header[1] != 0 && header[1] != 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Astonishing that there are no identifiers!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes its really strange. As far as i know its the only image format without some sort of magick bytes
| { | ||
| /// <summary> | ||
| /// No image data included. | ||
| /// Not sure what this is used for. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove this comment from the summary. I don't think the type is ever used but it's in the spec so no need for the comment.
| { | ||
| byte imageTypeVal = (byte)imageType; | ||
|
|
||
| switch (imageTypeVal) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why cast and switch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good question, does not make sense. Its changed now.
| /// Converts all pixels in 'source` span of <see cref="<#=pixelType#>"/> into a span of <typeparamref name="TPixel"/>-s. | ||
| /// </summary> | ||
| /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param> | ||
| /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well spotted 😄
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Magick.NET-Q16-AnyCPU" /> | ||
| <PackageReference Include="Magick.NET-Q16-AnyCPU" Version="7.14.4" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't add the version here. You have to add it to the Directory.Targets file.
…ion to pixelDataStart
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect! 👏
|
@JimBobSquarePants i think this is done now and can be merged (if you dont see any more issues). |
|
And we're in! Thanks so much for your help! |
Prerequisites
Description
As the title say already: This will add support for TGA images.
Still work in progress, because some unit test are failing.