Skip to content

Conversation

@brianpopow
Copy link
Collaborator

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following matches the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

As the title say already: This will add support for TGA images.

Still work in progress, because some unit test are failing.

@brianpopow brianpopow changed the title WIP: Add support for decoding and encoding of TGA images Add support for decoding and encoding of TGA images Oct 27, 2019
@brianpopow
Copy link
Collaborator Author

@JimBobSquarePants I think this is ready for review.

I noticed there is maybe an issue with InternalDetectFormat.
There a buffer will be allocated with a length of maxHeaderSize. This buffer will be passed to DetectFormat. In all DetectFormat methods of the different formats,
there is usally a check for a minimum length of the buffer. Since the buffer will be always maxHeaderSize this checks will alway be true.

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.

@JimBobSquarePants
Copy link
Member

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
Copy link

codecov bot commented Oct 28, 2019

Codecov Report

Merging #1026 into master will increase coverage by 0.04%.
The diff coverage is 92.94%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
tests/ImageSharp.Tests/TestImages.cs 100% <ø> (ø) ⬆️
...ImageSharp.Tests/Formats/Bmp/BmpFileHeaderTests.cs 100% <ø> (ø) ⬆️
src/ImageSharp/Formats/Tga/TgaThrowHelper.cs 0% <0%> (ø)
src/ImageSharp/Formats/Tga/TgaConstants.cs 100% <100%> (ø)
...ogramEqualizationSlidingWindowProcessor{TPixel}.cs 100% <100%> (ø) ⬆️
...ts/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs 100% <100%> (ø) ⬆️
...c/ImageSharp/Formats/Tga/TgaConfigurationModule.cs 100% <100%> (ø)
src/ImageSharp/Common/Helpers/ImageMaths.cs 87.5% <100%> (+0.32%) ⬆️
src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs 94.38% <100%> (+0.01%) ⬆️
...ts/ImageSharp.Tests/Formats/Tga/TgaEncoderTests.cs 100% <100%> (ø)
... and 38 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0049ca2...d183a51. Read the comment docs.

Copy link
Member

@JimBobSquarePants JimBobSquarePants left a 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];
Copy link
Member

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?

Copy link
Collaborator Author

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)
Copy link
Member

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!

Copy link
Collaborator Author

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.
Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

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

Why cast and switch?

Copy link
Collaborator Author

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>
Copy link
Member

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" />
Copy link
Member

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.

Copy link
Member

@JimBobSquarePants JimBobSquarePants left a comment

Choose a reason for hiding this comment

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

Perfect! 👏

@brianpopow
Copy link
Collaborator Author

@JimBobSquarePants i think this is done now and can be merged (if you dont see any more issues).
appveyor is failing for net472, but i dont think this is related to my changes.

@JimBobSquarePants JimBobSquarePants merged commit 133d908 into SixLabors:master Nov 12, 2019
@JimBobSquarePants
Copy link
Member

And we're in! Thanks so much for your help!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants