Skip to content

Commit

Permalink
Palette color format.
Browse files Browse the repository at this point in the history
  • Loading branch information
juliusfriedman committed Oct 27, 2024
1 parent 8602a3d commit b315478
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
14 changes: 13 additions & 1 deletion Codecs/Image/ImageFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class ImageFormat : Codec.MediaFormat

public const byte PreMultipliedAlphaChannelId = (byte)'p';

//Possibly a type which has multiplied and straight types...
//Possibly a type which has multiplied and normal types...
//public const byte MixedAlphaChannelId = (byte)'@';

public const byte DeltaChannelId = (byte)'d';
Expand All @@ -39,6 +39,10 @@ public class ImageFormat : Codec.MediaFormat

public const byte BlueChannelId = (byte)'b';

//

public const byte PaletteChannelId = (byte)'p';

//Printing...

public const byte CyanChannelId = (byte)'c';
Expand Down Expand Up @@ -107,6 +111,14 @@ public static ImageFormat Monochrome(int bitsPerComponent)
});
}

public static ImageFormat Palette(int bitsPerComponent)
{
return new ImageFormat(Common.Binary.ByteOrder.Little, Codec.DataLayout.Packed, new Codec.MediaComponent[]
{
new(PaletteChannelId, bitsPerComponent)
});
}

public static ImageFormat RGB(int bitsPerComponent, Common.Binary.ByteOrder byteOrder = Common.Binary.ByteOrder.Little, Codec.DataLayout dataLayout = Codec.DataLayout.Packed)
{
return new ImageFormat(byteOrder, dataLayout, new Codec.MediaComponent[]
Expand Down
8 changes: 6 additions & 2 deletions Codecs/Image/Png/Codec.Png/PngImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ private static ImageFormat CreateImageFormat(byte bitDepth, byte colorType)
switch (colorType)
{
case 0: // Grayscale
case 3: // Indexed-color
return ImageFormat.Monochrome(bitDepth);
case 3: // Indexed-color
return ImageFormat.Palette(bitDepth);
case 4: // Grayscale with alpha
return ImageFormat.WithPreceedingAlphaComponent(ImageFormat.Monochrome(bitDepth / 2), bitDepth / 2);
case 2: // Truecolor (RGB)
Expand All @@ -43,7 +44,10 @@ private static ColorType ResolveColorType(ImageFormat imageFormat)
switch (imageFormat.Components.Length)
{
case 1:
return ColorType.Grayscale;
return
imageFormat.Components[0].Id == ImageFormat.PaletteChannelId
? ColorType.Palette
: ColorType.Grayscale;
case 2:
return ColorType.GrayscaleWithAlpha;
case 3:
Expand Down

0 comments on commit b315478

Please sign in to comment.