Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Layers and Entities true color property #102

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 5 additions & 2 deletions ACadSharp/Color.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ public bool IsByBlock
/// </summary>
public bool IsTrueColor => _color >= (1 << 30);


/// <summary>
/// Represents the actual stored color. Either a True Color or an indexed color.
/// </summary>
Expand Down Expand Up @@ -415,8 +416,10 @@ public ReadOnlySpan<byte> GetTrueColorRgb()
{
return new ReadOnlySpan<byte>(BitConverter.GetBytes(_color), 0, 3);
}

return default;
else
{
return Color.GetIndexRGB(this.Index);
}
}

public bool Equals(Color other)
Expand Down
29 changes: 28 additions & 1 deletion ACadSharp/IO/DWG/DwgStreamReaders/DwgMergedReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ public XYZ Read3BitDoubleWithDefault(XYZ defValues)

public Color ReadCmColor()
{


if (!(_mainReader is DwgStreamReaderAC18))
return _mainReader.ReadCmColor();

Expand All @@ -162,8 +164,10 @@ public Color ReadCmColor()
//CMC:
//BS: color index(always 0)
short colorIndex = ReadBitShort();

//BL: RGB value
int rgb = ReadBitLong();
Color color = GetColor(rgb);

//RC : Color Byte
byte id = ReadByte();
Expand All @@ -178,7 +182,30 @@ public Color ReadCmColor()
if ((id & 2) == 2)
bookName = ReadVariableText();

return new Color(colorIndex);
return color;
}

public Color GetColor (int blColor)
{
byte[] values = BitConverter.GetBytes(blColor);
//if (!BitConverter.IsLittleEndian) Array.Reverse(values);
byte r = values[2];
byte g = values[1];
byte b = values[0];
byte acadColorIndex = values[0];

if (r == 0 && g == 0)
{
// AutoCAD indexed color
var trueColor = Color.GetIndexRGB(acadColorIndex);
return new Color(acadColorIndex);
}
else
{
// True color
return new Color(r, g, b);
}

}

public Color ReadEnColor(out Transparency transparency, out bool flag)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Linq;
using System.IO;
using System;
using System.Diagnostics;

namespace ACadSharp.IO.DWG
{
Expand Down
11 changes: 9 additions & 2 deletions ACadSharp/IO/DWG/DwgStreamReaders/DwgStreamReaderAC18.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using System;
using System.IO;

namespace ACadSharp.IO.DWG
{
Expand Down Expand Up @@ -55,7 +56,13 @@ public override Color ReadEnColor(out Transparency transparency, out bool flag)
else if ((flags & 0x8000) > 0)
{
//Next value is a BS containing the RGB value(last 24 bits).
color = new Color((short)this.ReadBitLong());
var blColor = this.ReadBitLong();
byte[] values = BitConverter.GetBytes(blColor);
byte r = values[2];
byte g = values[1];
byte b = values[0];
color = new Color(r, g, b);

}
else
{
Expand Down