Skip to content

Commit

Permalink
Remove export code as it's not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
warrengalyen committed Jan 4, 2024
1 parent 7ab487c commit 8bab9ab
Showing 1 changed file with 1 addition and 95 deletions.
96 changes: 1 addition & 95 deletions src/PixiEditor/Models/IO/PaletteParsers/CorelDrawPalParser.cs
Expand Up @@ -10,9 +10,6 @@ internal class CorelDrawPalParser : PaletteFileParser
public override string FileName { get; } = "CorelDRAW! 3.0 Palette";
public override string[] SupportedFileExtensions { get; } = { ".pal" };

// Default name to use for colors (color name is required by format)
private const string SWATCH_NAME = "PixiEditor Color";

public override async Task<PaletteFileData> Parse(string path)
{
try
Expand Down Expand Up @@ -72,51 +69,9 @@ await using (Stream stream = File.OpenRead(path))

public override bool CanSave => false;

// NOTE: saving data works but PixiEditor defaults to first .pal parser which
// is JASC so saving to an actual file is currently not available.
// Palette exporter needs to be refactored to support multiple formats of
// same file extension.
public override async Task<bool> Save(string path, PaletteFileData data)
{
StringBuilder sb = new StringBuilder(SWATCH_NAME.Length + 20);

try
{
await using (Stream stream = File.OpenWrite(path))
{
using (TextWriter writer = new StreamWriter(stream, Encoding.ASCII, 1024, true))
{
foreach (var color in data.Colors)
{
this.ConvertRgbToCmyk(color, out byte c, out byte m, out byte y, out byte k);

this.WriteName(sb, SWATCH_NAME);
this.WriteNumber(sb, c);
this.WriteNumber(sb, m);
this.WriteNumber(sb, y);
this.WriteNumber(sb, k);

writer.WriteLine(sb.ToString());
sb.Length = 0;
}
}
}
return true;
}
catch
{
return false;
}
}

private static byte ClampCmyk(float value)
{
if (value < 0 || float.IsNaN(value))
{
value = 0;
}

return Convert.ToByte(value * 100);
throw new SavingNotSupportedException("Saving palette as CorelDRAW! 3.0 palette directly is not supported.");
}

private PaletteColor ConvertCmykToRgb(int c, int m, int y, int k)
Expand All @@ -133,23 +88,6 @@ private PaletteColor ConvertCmykToRgb(int c, int m, int y, int k)
return new PaletteColor((byte)r, (byte)g, (byte)b);
}

private void ConvertRgbToCmyk(PaletteColor color, out byte c, out byte m, out byte y, out byte k)
{
float r, g, b;
float divisor;

r = color.R / 255F;
g = color.G / 255F;
b = color.B / 255F;

divisor = 1 - Math.Max(Math.Max(r, g), b);

c = ClampCmyk((1 - r - divisor) / (1 - divisor));
m = ClampCmyk((1 - g - divisor) / (1 - divisor));
y = ClampCmyk((1 - b - divisor) / (1 - divisor));
k = ClampCmyk(divisor);
}

private byte NextNumber(string line, ref int start)
{
int length;
Expand Down Expand Up @@ -185,36 +123,4 @@ private byte NextNumber(string line, ref int start)

return result;
}

private void WriteName(StringBuilder sb, string name)
{
sb.Append('"');
sb.Append(name);
sb.Append('"');

for (int j = (name ?? string.Empty).Length; j < name.Length; j++)
{
sb.Append(' ');
}
}

private void WriteNumber(StringBuilder sb, byte value)
{
if (value == 100)
{
sb.Append("100 ");
}
else
{
sb.Append(' ');
if (value < 10)
{
sb.Append(' ');
}

sb.Append(value);

sb.Append(' ');
}
}
}

0 comments on commit 8bab9ab

Please sign in to comment.