Skip to content
Merged
Show file tree
Hide file tree
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 Oct 6, 2019
10ff875
Add support for decoding 8, 16, 32 bit tga files
brianpopow Oct 6, 2019
2e1a6ff
Add tga decoder tests
brianpopow Oct 6, 2019
a2c4636
Fix decoding 16 bit tga files by making them opaque
brianpopow Oct 6, 2019
5037380
Add RLE test images
brianpopow Oct 6, 2019
f6cce78
Add decoding of 24bit RLE tga images
brianpopow Oct 8, 2019
f69048f
Add decoding of 32 bit RLE
brianpopow Oct 8, 2019
914d191
Avoid calculating the row start index inside the loop
brianpopow Oct 8, 2019
f1bfba6
Unified reading rle images
brianpopow Oct 8, 2019
e18481b
Add decoding of 16 and 8 bit rle images
brianpopow Oct 8, 2019
e7fe670
Add support for encoding 24 bit tga files
brianpopow Oct 9, 2019
5aaf845
Support for encoding 8, 16 and 32 bit tga files
brianpopow Oct 9, 2019
bb92179
Add support for decoding tga image with palette
brianpopow Oct 10, 2019
d13b646
Add support for decoding rle tga with palette
brianpopow Oct 11, 2019
391cb44
Change test images, add additional tests
brianpopow Oct 11, 2019
6fda29b
Add tests for topleft origin
brianpopow Oct 12, 2019
b4a8778
Add support for images with top left origin
brianpopow Oct 13, 2019
94b4f35
Treat bgra5551 pixels as opaque
brianpopow Oct 13, 2019
6720f10
Add support for encoding RLE tga images
brianpopow Oct 13, 2019
28222b5
Add support for encoding rle 8, 16 and bit tga images
brianpopow Oct 13, 2019
f8854c7
Add test for the tga encoder
brianpopow Oct 13, 2019
8dfe6da
Skip palette bytes if image type indicates its no palette image
brianpopow Oct 13, 2019
b1572ae
A little cleanup and comments
brianpopow Oct 13, 2019
d4b7587
Add CompareToOriginal at the end of Issue1014 test
brianpopow Oct 13, 2019
ca6dcb3
Set expected default configuration count to 5
brianpopow Oct 13, 2019
a0728d9
Fix orientation of RLE images
brianpopow Oct 13, 2019
56150f1
Fix encoding of 16 tga files
brianpopow Oct 26, 2019
45a6a6b
Using tolerant comparer for 16 and 8 bit
brianpopow Oct 26, 2019
30291a2
Add tga specification
brianpopow Oct 26, 2019
178761a
Merge branch 'master' into feature/tga
brianpopow Oct 26, 2019
10c9867
Fix build error in Release mode
brianpopow Oct 26, 2019
5b478c5
Add check for valid tga image type in the format detector
brianpopow Oct 27, 2019
b1e8202
Add tests for bmp and tga header to throw UnknownImageFormatException…
brianpopow Oct 27, 2019
5789599
Throw ImageFormatException when width or height is 0
brianpopow Oct 27, 2019
32cd7a3
Merge branch 'master' into feature/tga
JimBobSquarePants Nov 5, 2019
1b04fbe
Code review changes
brianpopow Nov 7, 2019
7681c6a
Fix converting pixel to gray in histogram equalization
brianpopow Nov 8, 2019
43fcf57
Add benchmarks for tga images
brianpopow Nov 8, 2019
917c1e4
Merge branch 'master' into feature/tga
brianpopow Nov 8, 2019
e8e1e52
Add width and height as parameter for makeopaque, change currentPosit…
brianpopow Nov 9, 2019
d3f1d3c
Avoid second iteration over the stream in ReadBgra16 to make it opaque
brianpopow Nov 9, 2019
006491f
Update external for issue 984 testimages
brianpopow Nov 12, 2019
45cd31a
Add GetBT709Luminance with vector test
brianpopow Nov 12, 2019
d183a51
Merge remote-tracking branch 'upstream/master' into feature/tga
brianpopow Nov 12, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
*.gif binary
*.jpg binary
*.png binary
*.tga binary
*.ttf binary
*.snk binary

Expand Down
5 changes: 4 additions & 1 deletion src/ImageSharp/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using SixLabors.ImageSharp.Formats.Gif;
using SixLabors.ImageSharp.Formats.Jpeg;
using SixLabors.ImageSharp.Formats.Png;
using SixLabors.ImageSharp.Formats.Tga;
using SixLabors.ImageSharp.IO;
using SixLabors.ImageSharp.Processing;
using SixLabors.Memory;
Expand Down Expand Up @@ -150,6 +151,7 @@ public Configuration Clone()
/// <see cref="JpegConfigurationModule"/>
/// <see cref="GifConfigurationModule"/>
/// <see cref="BmpConfigurationModule"/>.
/// <see cref="TgaConfigurationModule"/>.
/// </summary>
/// <returns>The default configuration of <see cref="Configuration"/>.</returns>
internal static Configuration CreateDefaultInstance()
Expand All @@ -158,7 +160,8 @@ internal static Configuration CreateDefaultInstance()
new PngConfigurationModule(),
new JpegConfigurationModule(),
new GifConfigurationModule(),
new BmpConfigurationModule());
new BmpConfigurationModule(),
new TgaConfigurationModule());
}
}
}
6 changes: 4 additions & 2 deletions src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,10 @@ private void ReadRle24<TPixel>(Buffer2D<TPixel> pixels, int width, int height, b
if (rowHasUndefinedPixels)
{
// Slow path with undefined pixels.
int rowStartIdx = y * width * 3;
for (int x = 0; x < width; x++)
{
int idx = (y * width * 3) + (x * 3);
int idx = rowStartIdx + (x * 3);
if (undefinedPixels[x, y])
{
switch (this.options.RleSkippedPixelHandling)
Expand Down Expand Up @@ -418,9 +419,10 @@ private void ReadRle24<TPixel>(Buffer2D<TPixel> pixels, int width, int height, b
else
{
// Fast path without any undefined pixels.
int rowStartIdx = y * width * 3;
for (int x = 0; x < width; x++)
{
int idx = (y * width * 3) + (x * 3);
int idx = rowStartIdx + (x * 3);
color.FromBgr24(Unsafe.As<byte, Bgr24>(ref bufferSpan[idx]));
pixelRow[x] = color;
}
Expand Down
6 changes: 6 additions & 0 deletions src/ImageSharp/Formats/README.md
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)
12 changes: 12 additions & 0 deletions src/ImageSharp/Formats/Tga/ITgaDecoderOptions.cs
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
{
}
}
21 changes: 21 additions & 0 deletions src/ImageSharp/Formats/Tga/ITgaEncoderOptions.cs
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; }
}
}
Binary file added src/ImageSharp/Formats/Tga/TGA_Specification.pdf
Binary file not shown.
31 changes: 31 additions & 0 deletions src/ImageSharp/Formats/Tga/TgaBitsPerPixel.cs
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
}
}
19 changes: 19 additions & 0 deletions src/ImageSharp/Formats/Tga/TgaConfigurationModule.cs
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());
}
}
}
25 changes: 25 additions & 0 deletions src/ImageSharp/Formats/Tga/TgaConstants.cs
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;
}
}
34 changes: 34 additions & 0 deletions src/ImageSharp/Formats/Tga/TgaDecoder.cs
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);
}
}
}
Loading