-
-
Notifications
You must be signed in to change notification settings - Fork 887
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
Merged
Merged
Changes from 35 commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
4a5e075
Add decoding of 24 bit targa files
brianpopow 10ff875
Add support for decoding 8, 16, 32 bit tga files
brianpopow 2e1a6ff
Add tga decoder tests
brianpopow a2c4636
Fix decoding 16 bit tga files by making them opaque
brianpopow 5037380
Add RLE test images
brianpopow f6cce78
Add decoding of 24bit RLE tga images
brianpopow f69048f
Add decoding of 32 bit RLE
brianpopow 914d191
Avoid calculating the row start index inside the loop
brianpopow f1bfba6
Unified reading rle images
brianpopow e18481b
Add decoding of 16 and 8 bit rle images
brianpopow e7fe670
Add support for encoding 24 bit tga files
brianpopow 5aaf845
Support for encoding 8, 16 and 32 bit tga files
brianpopow bb92179
Add support for decoding tga image with palette
brianpopow d13b646
Add support for decoding rle tga with palette
brianpopow 391cb44
Change test images, add additional tests
brianpopow 6fda29b
Add tests for topleft origin
brianpopow b4a8778
Add support for images with top left origin
brianpopow 94b4f35
Treat bgra5551 pixels as opaque
brianpopow 6720f10
Add support for encoding RLE tga images
brianpopow 28222b5
Add support for encoding rle 8, 16 and bit tga images
brianpopow f8854c7
Add test for the tga encoder
brianpopow 8dfe6da
Skip palette bytes if image type indicates its no palette image
brianpopow b1572ae
A little cleanup and comments
brianpopow d4b7587
Add CompareToOriginal at the end of Issue1014 test
brianpopow ca6dcb3
Set expected default configuration count to 5
brianpopow a0728d9
Fix orientation of RLE images
brianpopow 56150f1
Fix encoding of 16 tga files
brianpopow 45a6a6b
Using tolerant comparer for 16 and 8 bit
brianpopow 30291a2
Add tga specification
brianpopow 178761a
Merge branch 'master' into feature/tga
brianpopow 10c9867
Fix build error in Release mode
brianpopow 5b478c5
Add check for valid tga image type in the format detector
brianpopow b1e8202
Add tests for bmp and tga header to throw UnknownImageFormatException…
brianpopow 5789599
Throw ImageFormatException when width or height is 0
brianpopow 32cd7a3
Merge branch 'master' into feature/tga
JimBobSquarePants 1b04fbe
Code review changes
brianpopow 7681c6a
Fix converting pixel to gray in histogram equalization
brianpopow 43fcf57
Add benchmarks for tga images
brianpopow 917c1e4
Merge branch 'master' into feature/tga
brianpopow e8e1e52
Add width and height as parameter for makeopaque, change currentPosit…
brianpopow d3f1d3c
Avoid second iteration over the stream in ReadBgra16 to make it opaque
brianpopow 006491f
Update external for issue 984 testimages
brianpopow 45cd31a
Add GetBT709Luminance with vector test
brianpopow d183a51
Merge remote-tracking branch 'upstream/master' into feature/tga
brianpopow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -93,6 +93,7 @@ | |
| *.gif binary | ||
| *.jpg binary | ||
| *.png binary | ||
| *.tga binary | ||
| *.ttf binary | ||
| *.snk binary | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # Encoder/Decoder for true vision targa files | ||
|
|
||
| Useful links for reference: | ||
|
|
||
| - [FileFront](https://www.fileformat.info/format/tga/egff.htm) | ||
| - [Tga Specification](http://www.dca.fee.unicamp.br/~martino/disciplinas/ea978/tgaffs.pdf) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // Copyright (c) Six Labors and contributors. | ||
| // Licensed under the Apache License, Version 2.0. | ||
|
|
||
| namespace SixLabors.ImageSharp.Formats.Tga | ||
| { | ||
| /// <summary> | ||
| /// The options for decoding tga images. Currently empty, but this may change in the future. | ||
| /// </summary> | ||
| internal interface ITgaDecoderOptions | ||
| { | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // Copyright (c) Six Labors and contributors. | ||
| // Licensed under the Apache License, Version 2.0. | ||
|
|
||
| namespace SixLabors.ImageSharp.Formats.Tga | ||
| { | ||
| /// <summary> | ||
| /// Configuration options for use during tga encoding. | ||
| /// </summary> | ||
| internal interface ITgaEncoderOptions | ||
| { | ||
| /// <summary> | ||
| /// Gets the number of bits per pixel. | ||
| /// </summary> | ||
| TgaBitsPerPixel? BitsPerPixel { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets a value indicating whether run length compression should be used. | ||
| /// </summary> | ||
| bool Compress { get; } | ||
JimBobSquarePants marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // Copyright (c) Six Labors and contributors. | ||
| // Licensed under the Apache License, Version 2.0. | ||
|
|
||
| namespace SixLabors.ImageSharp.Formats.Tga | ||
| { | ||
| /// <summary> | ||
| /// Enumerates the available bits per pixel the tga encoder supports. | ||
| /// </summary> | ||
| public enum TgaBitsPerPixel : byte | ||
| { | ||
| /// <summary> | ||
| /// 8 bits per pixel. Each pixel consists of 1 byte. | ||
| /// </summary> | ||
| Pixel8 = 8, | ||
|
|
||
| /// <summary> | ||
| /// 16 bits per pixel. Each pixel consists of 2 bytes. | ||
| /// </summary> | ||
| Pixel16 = 16, | ||
|
|
||
| /// <summary> | ||
| /// 24 bits per pixel. Each pixel consists of 3 bytes. | ||
| /// </summary> | ||
| Pixel24 = 24, | ||
|
|
||
| /// <summary> | ||
| /// 32 bits per pixel. Each pixel consists of 4 bytes. | ||
| /// </summary> | ||
| Pixel32 = 32 | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // Copyright (c) Six Labors and contributors. | ||
| // Licensed under the Apache License, Version 2.0. | ||
|
|
||
| namespace SixLabors.ImageSharp.Formats.Tga | ||
| { | ||
| /// <summary> | ||
| /// Registers the image encoders, decoders and mime type detectors for the tga format. | ||
| /// </summary> | ||
| public sealed class TgaConfigurationModule : IConfigurationModule | ||
| { | ||
| /// <inheritdoc/> | ||
| public void Configure(Configuration configuration) | ||
| { | ||
| configuration.ImageFormatsManager.SetEncoder(TgaFormat.Instance, new TgaEncoder()); | ||
| configuration.ImageFormatsManager.SetDecoder(TgaFormat.Instance, new TgaDecoder()); | ||
| configuration.ImageFormatsManager.AddImageFormatDetector(new TgaImageFormatDetector()); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // Copyright (c) Six Labors and contributors. | ||
| // Licensed under the Apache License, Version 2.0. | ||
|
|
||
| using System.Collections.Generic; | ||
|
|
||
| namespace SixLabors.ImageSharp.Formats.Tga | ||
| { | ||
| internal static class TgaConstants | ||
| { | ||
| /// <summary> | ||
| /// The list of mimetypes that equate to a targa file. | ||
| /// </summary> | ||
| public static readonly IEnumerable<string> MimeTypes = new[] { "image/x-tga", "image/x-targa" }; | ||
|
|
||
| /// <summary> | ||
| /// The list of file extensions that equate to a targa file. | ||
| /// </summary> | ||
| public static readonly IEnumerable<string> FileExtensions = new[] { "tga", "vda", "icb", "vst" }; | ||
|
|
||
| /// <summary> | ||
| /// The file header length of a tga image in bytes. | ||
| /// </summary> | ||
| public const int FileHeaderLength = 18; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // Copyright (c) Six Labors and contributors. | ||
| // Licensed under the Apache License, Version 2.0. | ||
|
|
||
| using System.IO; | ||
| using SixLabors.ImageSharp.PixelFormats; | ||
|
|
||
| namespace SixLabors.ImageSharp.Formats.Tga | ||
| { | ||
| /// <summary> | ||
| /// Image decoder for Truevision TGA images. | ||
| /// </summary> | ||
| public sealed class TgaDecoder : IImageDecoder, ITgaDecoderOptions, IImageInfoDetector | ||
| { | ||
| /// <inheritdoc/> | ||
| public Image<TPixel> Decode<TPixel>(Configuration configuration, Stream stream) | ||
| where TPixel : struct, IPixel<TPixel> | ||
| { | ||
| Guard.NotNull(stream, nameof(stream)); | ||
|
|
||
| return new TgaDecoderCore(configuration, this).Decode<TPixel>(stream); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public Image Decode(Configuration configuration, Stream stream) => this.Decode<Rgba32>(configuration, stream); | ||
|
|
||
| /// <inheritdoc/> | ||
| public IImageInfo Identify(Configuration configuration, Stream stream) | ||
| { | ||
| Guard.NotNull(stream, nameof(stream)); | ||
|
|
||
| return new TgaDecoderCore(configuration, this).Identify(stream); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.