Skip to content

Commit

Permalink
color writer
Browse files Browse the repository at this point in the history
  • Loading branch information
DomCR committed Oct 28, 2023
1 parent 9c523f6 commit 634ad5c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
20 changes: 18 additions & 2 deletions ACadSharp/Color.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using CSUtilities.Converters;
using System;

namespace ACadSharp
{
Expand Down Expand Up @@ -323,6 +324,21 @@ public bool IsTrueColor
}
}

/// <summary>
/// Red component of the color
/// </summary>
public byte R { get { return this.GetRgb()[0]; } }

/// <summary>
/// Green component of the color
/// </summary>
public byte G { get { return this.GetRgb()[1]; } }

/// <summary>
/// Blue component of the color
/// </summary>
public byte B { get { return this.GetRgb()[2]; } }

/// <summary>
/// Represents the actual stored color. Either a True Color or an indexed color.
/// </summary>
Expand Down Expand Up @@ -501,7 +517,7 @@ private static uint getInt24(byte[] array)

private static ReadOnlySpan<byte> getRGBfromTrueColor(uint color)
{
return new ReadOnlySpan<byte>(BitConverter.GetBytes(color), 0, 3);
return new ReadOnlySpan<byte>(LittleEndianConverter.Instance.GetBytes(color), 0, 3);
}
}
}
22 changes: 18 additions & 4 deletions ACadSharp/IO/DWG/DwgStreamWriters/DwgStreamWriterAC18.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using CSUtilities.Converters;
using System.IO;
using System.Text;

namespace ACadSharp.IO.DWG
Expand All @@ -11,14 +12,27 @@ public DwgStreamWriterAC18(Stream stream, Encoding encoding) : base(stream, enco

public override void WriteCmColor(Color value)
{
//TODO: Finish writer color implementation

//CMC:
//BS: color index(always 0)
this.WriteBitShort(0);

byte[] arr = new byte[4];

if (value.IsTrueColor)
{
arr[0] = (byte)(value.R);
arr[1] = (byte)(value.G);
arr[2] = (byte)(value.B);
arr[3] = 0b1100_0010;
}
else
{
arr[3] = 0b1100_0011;
arr[0] = (byte)value.Index;
}

//BL: RGB value
this.WriteBitLong(0);
this.WriteBitLong(LittleEndianConverter.Instance.ToInt32(arr));

//RC: Color Byte
this.WriteByte(0);
Expand Down

0 comments on commit 634ad5c

Please sign in to comment.