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

ReadEnColor creates bad Color #197

Closed
mme1950 opened this issue Nov 6, 2023 · 4 comments · Fixed by #199 or #207
Closed

ReadEnColor creates bad Color #197

mme1950 opened this issue Nov 6, 2023 · 4 comments · Fixed by #199 or #207
Labels
bug Something isn't working

Comments

@mme1950
Copy link
Contributor

mme1950 commented Nov 6, 2023

We read a complex DWG with several colors.
It worked "quite well" before. But now it seems all colors are ByBlock.

ReadEnColol has been changed recently:

old: color = new Color((short)(size & 0b111111111111));
new: color = new Color((byte)(size & 0b111111111111));

Rolling back to the old code seems to fix the problem.

BTW: These lines cannot be correct: A true color using the RGB value cannot be created this way:

//Next value is a BS containing the RGB value(last 24 bits).
color = new Color((byte)this.ReadBitLong());

@mme1950 mme1950 added the bug Something isn't working label Nov 6, 2023
@DomCR
Copy link
Owner

DomCR commented Nov 6, 2023

Hi @mme1950

I've been working on the colors in this PR:

There is an investigation of how the color is stored in ReadCmColor and how the color is stored, it seems that the documentation don't cover this.

I'll open a branch to check the current implementation and add some Asserts to check the entity color and transparency.

@DomCR DomCR linked a pull request Nov 6, 2023 that will close this issue
@mme1950
Copy link
Contributor Author

mme1950 commented Nov 11, 2023

Sorry to say: The color is still not OK.

This line should be changed:
color = new Color((byte)(size & 0b111111111111));

This seems to fix part of the problem:
color = new Color((short)(size & 0b111111111111));

Some colors are black instead of the values we saw previously.

@mme1950
Copy link
Contributor Author

mme1950 commented Nov 11, 2023

I do not understand the details.
readCmColor has different implementations in DwgMergedReader and in DwgStreamReaderAC18.

I changed these lines in DwgMergedReader:

			//CECOLOR:
			//3221225472
			//0b11000000000000000000000000000000
			//0b1100_0000_0000_0000_0000_0000_0000_0000 --> this should be ByLayer
			//0xC0000000

			//True color
			//color = new Color(arr[0], arr[1], arr[2]);
			uint trueColor = (uint)((int)rgb - 0xC2000000);

			//Needs the check just in case the flag is not set
			if (trueColor < (1 << 24))
			{
				color = Color.FromTrueColor(trueColor);
			}

Now I get the color as before.

@DomCR DomCR reopened this Nov 14, 2023
@DomCR
Copy link
Owner

DomCR commented Nov 14, 2023

I need to read more documentation about how the colors are encoded and used in the DWG files, I'll keep this open and see what I can find out.

@DomCR DomCR linked a pull request Nov 20, 2023 that will close this issue
mme1950 added a commit to mme1950/ACadSharp that referenced this issue Nov 20, 2023
mme1950 added a commit to mme1950/ACadSharp that referenced this issue Nov 28, 2023
-  Work-around: Preliminary fix for DomCR/AcadSharp/DomCR#197
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants