add new DataFormats and reorganize directory structure
This commit is contained in:
parent
9813377c12
commit
49c77e5904
@ -0,0 +1,73 @@
|
||||
//
|
||||
// ACOColorSpace.cs
|
||||
//
|
||||
// Author:
|
||||
// Michael Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// Copyright (c) 2021 Mike Becker's Software
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
using System;
|
||||
namespace UniversalEditor.DataFormats.Multimedia.Palette.Adobe
|
||||
{
|
||||
public enum ACOColorSpace : ushort
|
||||
{
|
||||
/// <summary>
|
||||
/// The first three values in the color data are red, green, and blue.
|
||||
/// They are full unsigned 16-bit values as in Apple's RGBColor data
|
||||
/// structure. Pure red = 65535, 0, 0.
|
||||
/// </summary>
|
||||
RGB = 0,
|
||||
/// <summary>
|
||||
/// The first three values in the color data are hue, saturation, and
|
||||
/// brightness. They are full unsigned 16-bit values as in Apple's
|
||||
/// HSVColor data structure. Pure red = 0, 65535, 65535.
|
||||
/// </summary>
|
||||
HSB = 1,
|
||||
/// <summary>
|
||||
/// The four values in the color data are cyan, magenta, yellow, and
|
||||
/// black. They are full unsigned 16-bit values. 0 = 100% ink.
|
||||
/// </summary>
|
||||
CMYK = 2,
|
||||
/// <summary>
|
||||
/// Pantone matching system (custom colorspace)
|
||||
/// </summary>
|
||||
Pantone = 3,
|
||||
/// <summary>
|
||||
/// Focoltone colour system (custom colorspace)
|
||||
/// </summary>
|
||||
Focoltone = 4,
|
||||
/// <summary>
|
||||
/// Trumatch color (custom colorspace)
|
||||
/// </summary>
|
||||
Trumatch = 5,
|
||||
/// <summary>
|
||||
/// Toyo 88 colorfinder 1050 (custom colorspace)
|
||||
/// </summary>
|
||||
Toyo88 = 6,
|
||||
/// <summary>
|
||||
/// The first three values in the color data are lightness,
|
||||
/// a-chrominance, and b-chrominance.
|
||||
/// </summary>
|
||||
LAB = 7,
|
||||
/// <summary>
|
||||
/// The first value in the color data is the gray value, from 0...10000.
|
||||
/// </summary>
|
||||
Grayscale = 8,
|
||||
/// <summary>
|
||||
/// HKS colors (custom colorspace)
|
||||
/// </summary>
|
||||
HKS = 10
|
||||
}
|
||||
}
|
||||
@ -41,11 +41,19 @@ namespace UniversalEditor.DataFormats.Multimedia.Palette.Adobe
|
||||
_dfr.Capabilities.Add(typeof(PaletteObjectModel), DataFormatCapabilities.All);
|
||||
_dfr.Sources.Add("http://www.nomodes.com/aco.html");
|
||||
_dfr.ExportOptions.Add(new CustomOptionNumber(nameof(Version), "_Version", 1, 1, ushort.MaxValue));
|
||||
/*
|
||||
_dfr.ExportOptions.Add(new CustomOptionChoice(nameof(ColorSpace), "Color _space", true, new CustomOptionFieldChoice[]
|
||||
{
|
||||
new CustomOptionFieldChoice("RGB", ACOColorSpace.RGB, true),
|
||||
new CustomOptionFieldChoice("CMYK", ACOColorSpace.CMYK)
|
||||
}));
|
||||
*/
|
||||
}
|
||||
return _dfr;
|
||||
}
|
||||
|
||||
public ushort Version { get; set; } = 1;
|
||||
// public ACOColorSpace ColorSpace { get; set; } = ACOColorSpace.RGB;
|
||||
|
||||
protected override void LoadInternal(ref ObjectModel objectModel)
|
||||
{
|
||||
@ -61,7 +69,7 @@ namespace UniversalEditor.DataFormats.Multimedia.Palette.Adobe
|
||||
// occupies five words:
|
||||
for (ushort i = 0; i < colorCount; i++)
|
||||
{
|
||||
ushort colorSpace = br.ReadUInt16();
|
||||
ACOColorSpace colorSpace = (ACOColorSpace)br.ReadUInt16();
|
||||
ushort w = br.ReadUInt16();
|
||||
ushort x = br.ReadUInt16();
|
||||
ushort y = br.ReadUInt16();
|
||||
@ -76,9 +84,8 @@ namespace UniversalEditor.DataFormats.Multimedia.Palette.Adobe
|
||||
|
||||
switch (colorSpace)
|
||||
{
|
||||
case 0:
|
||||
case ACOColorSpace.RGB:
|
||||
{
|
||||
// RGB
|
||||
int R = (w / 256);
|
||||
int G = (x / 256);
|
||||
int B = (y / 256);
|
||||
@ -88,6 +95,36 @@ namespace UniversalEditor.DataFormats.Multimedia.Palette.Adobe
|
||||
palette.Entries.Add(entry);
|
||||
break;
|
||||
}
|
||||
case ACOColorSpace.HSB:
|
||||
{
|
||||
// The first three values in the color data are hue,
|
||||
// saturation, and brightness. They are full unsigned
|
||||
// 16-bit values as in Apple's HSVColor data structure.
|
||||
// Pure red = 0,65535, 65535.
|
||||
double H = ((double)w / 256);
|
||||
double S = ((double)x / 256);
|
||||
double B = ((double)y / 256);
|
||||
|
||||
PaletteEntry entry = new PaletteEntry();
|
||||
entry.Color = Color.FromHSL(H, S, B);
|
||||
palette.Entries.Add(entry);
|
||||
break;
|
||||
}
|
||||
case ACOColorSpace.CMYK:
|
||||
{
|
||||
// The four values in the color data are cyan, magenta,
|
||||
// yellow, and black. They are full unsigned 16-bit
|
||||
// values.
|
||||
double C = ((double)(UInt16.MaxValue - w) / 256);
|
||||
double M = ((double)(UInt16.MaxValue - x) / 256);
|
||||
double Y = ((double)(UInt16.MaxValue - y) / 256);
|
||||
double K = ((double)(UInt16.MaxValue - z) / 256);
|
||||
|
||||
PaletteEntry entry = new PaletteEntry();
|
||||
entry.Color = Color.FromCMYKDouble(C, M, Y, K);
|
||||
palette.Entries.Add(entry);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -107,16 +144,16 @@ namespace UniversalEditor.DataFormats.Multimedia.Palette.Adobe
|
||||
// occupies five words:
|
||||
foreach (PaletteEntry color in palette.Entries)
|
||||
{
|
||||
ushort colorSpace = 0; // RGB
|
||||
bw.WriteUInt16(colorSpace);
|
||||
ACOColorSpace colorSpace = ACOColorSpace.RGB;
|
||||
bw.WriteUInt16((ushort)colorSpace);
|
||||
|
||||
switch (colorSpace)
|
||||
{
|
||||
case 0:
|
||||
case ACOColorSpace.RGB:
|
||||
{
|
||||
ushort w = (ushort)((color.Color.R * 255) * 256);
|
||||
ushort x = (ushort)((color.Color.G * 255) * 256);
|
||||
ushort y = (ushort)((color.Color.B * 255) * 256);
|
||||
ushort w = (ushort)(color.Color.GetRedByte() * 256);
|
||||
ushort x = (ushort)(color.Color.GetGreenByte() * 256);
|
||||
ushort y = (ushort)(color.Color.GetBlueByte() * 256);
|
||||
ushort z = 0;
|
||||
|
||||
bw.WriteUInt16(w);
|
||||
@ -0,0 +1,106 @@
|
||||
//
|
||||
// ACTDataFormat.cs
|
||||
//
|
||||
// Author:
|
||||
// Michael Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// Copyright (c) 2021 Mike Becker's Software
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
using System;
|
||||
using MBS.Framework.Drawing;
|
||||
using UniversalEditor.IO;
|
||||
using UniversalEditor.ObjectModels.Multimedia.Palette;
|
||||
|
||||
namespace UniversalEditor.DataFormats.Multimedia.Palette.Adobe.ACT
|
||||
{
|
||||
public class ACTDataFormat : DataFormat
|
||||
{
|
||||
public bool IncludeExtendedInformation { get; set; } = false;
|
||||
|
||||
public ushort UsableColorCount { get; set; } = 0;
|
||||
public ushort TransparencyColorIndex { get; set; } = 0;
|
||||
|
||||
private static DataFormatReference _dfr;
|
||||
protected override DataFormatReference MakeReferenceInternal()
|
||||
{
|
||||
if (_dfr == null)
|
||||
{
|
||||
_dfr = base.MakeReferenceInternal();
|
||||
_dfr.Capabilities.Add(typeof(PaletteObjectModel), DataFormatCapabilities.All);
|
||||
}
|
||||
return _dfr;
|
||||
}
|
||||
|
||||
protected override void LoadInternal(ref ObjectModel objectModel)
|
||||
{
|
||||
PaletteObjectModel palette = (objectModel as PaletteObjectModel);
|
||||
if (palette == null) throw new ObjectModelNotSupportedException();
|
||||
|
||||
Reader reader = Accessor.Reader;
|
||||
|
||||
int nColors = 0;
|
||||
while (!reader.EndOfStream)
|
||||
{
|
||||
byte r = reader.ReadByte();
|
||||
byte g = reader.ReadByte();
|
||||
byte b = reader.ReadByte();
|
||||
palette.Entries.Add(new PaletteEntry(Color.FromRGBAByte(r, g, b)));
|
||||
|
||||
nColors++;
|
||||
if (nColors == 256)
|
||||
{
|
||||
if (!reader.EndOfStream)
|
||||
{
|
||||
UsableColorCount = reader.ReadUInt16();
|
||||
TransparencyColorIndex = reader.ReadUInt16();
|
||||
|
||||
IncludeExtendedInformation = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void SaveInternal(ObjectModel objectModel)
|
||||
{
|
||||
PaletteObjectModel palette = (objectModel as PaletteObjectModel);
|
||||
if (palette == null) throw new ObjectModelNotSupportedException();
|
||||
|
||||
Writer writer = Accessor.Writer;
|
||||
for (int i = 0; i < Math.Min(palette.Entries.Count, 768); i++)
|
||||
{
|
||||
writer.WriteByte(palette.Entries[i].Color.GetRedByte());
|
||||
writer.WriteByte(palette.Entries[i].Color.GetGreenByte());
|
||||
writer.WriteByte(palette.Entries[i].Color.GetBlueByte());
|
||||
}
|
||||
|
||||
int remaining = 768 - palette.Entries.Count;
|
||||
if (remaining > 0)
|
||||
{
|
||||
for (int i = 0; i < remaining; i++)
|
||||
{
|
||||
writer.WriteByte(0);
|
||||
writer.WriteByte(0);
|
||||
writer.WriteByte(0);
|
||||
}
|
||||
}
|
||||
|
||||
if (IncludeExtendedInformation)
|
||||
{
|
||||
writer.WriteUInt16(UsableColorCount);
|
||||
writer.WriteUInt16(TransparencyColorIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -26,7 +26,7 @@ using MBS.Framework.Drawing;
|
||||
using UniversalEditor.IO;
|
||||
using UniversalEditor.ObjectModels.Multimedia.Palette;
|
||||
|
||||
namespace UniversalEditor.DataFormats.Multimedia.Palette.Adobe
|
||||
namespace UniversalEditor.DataFormats.Multimedia.Palette.Adobe.SwatchExchange
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides a <see cref="DataFormat" /> for manipulating color palettes in Adobe ASE format.
|
||||
@ -128,7 +128,33 @@ namespace UniversalEditor.DataFormats.Multimedia.Palette.Adobe
|
||||
|
||||
protected override void SaveInternal(ObjectModel objectModel)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
PaletteObjectModel palette = (objectModel as PaletteObjectModel);
|
||||
if (palette == null) throw new ObjectModelNotSupportedException();
|
||||
|
||||
IO.Writer writer = base.Accessor.Writer;
|
||||
writer.Endianness = IO.Endianness.BigEndian;
|
||||
writer.Accessor.DefaultEncoding = Encoding.UTF8;
|
||||
writer.WriteFixedLengthString("ASEF");
|
||||
|
||||
writer.WriteInt16(1);
|
||||
writer.WriteInt16(0);
|
||||
|
||||
writer.WriteInt32(palette.Entries.Count);
|
||||
foreach (PaletteEntry entry in palette.Entries)
|
||||
{
|
||||
writer.WriteUInt16(0x0001);
|
||||
writer.WriteInt32(16 + entry.Name.Length); // colorName.Length + colorModel.Length + R G B
|
||||
writer.WriteUInt16((ushort)entry.Name.Length);
|
||||
writer.WriteFixedLengthString(entry.Name);
|
||||
|
||||
// only RGB supported right now
|
||||
writer.WriteFixedLengthString("RGB ");
|
||||
writer.WriteSingle((float)entry.Color.R);
|
||||
writer.WriteSingle((float)entry.Color.G);
|
||||
writer.WriteSingle((float)entry.Color.B);
|
||||
|
||||
writer.WriteUInt16(2); // colorType = Normal
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user