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

add support for rgb colors and transparency #49

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 src/drw_entities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ bool DRW_Entity::parseCode(int code, dxfReader *reader){
case 430:
colorName = reader->getString();
break;
case 440:
transparency = reader->getInt32();
break;
case 67:
space = static_cast<DRW::Space>(reader->getInt32());
break;
Expand Down Expand Up @@ -316,7 +319,7 @@ bool DRW_Entity::parseDwg(DRW::Version version, dwgBuffer *buf, dwgBuffer* strBu
DRW_DBG(", haveNextLinks (forced): "); DRW_DBG(haveNextLinks); DRW_DBG("\n");
}
//ENC color
color = buf->getEnColor(version); //BS or CMC //ok for R14 or negate
color = buf->getEnColor( version, color24, transparency ); //BS or CMC //OK for R14 or negate
ltypeScale = buf->getBitDouble(); //BD
DRW_DBG(" entity color: "); DRW_DBG(color);
DRW_DBG(" ltScale: "); DRW_DBG(ltypeScale); DRW_DBG("\n");
Expand Down Expand Up @@ -2961,7 +2964,7 @@ bool DRW_Viewport::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){
DRW_DBG("Brightness: "); DRW_DBG(buf->getBitDouble()); DRW_DBG("\n");
DRW_DBG("Contrast: "); DRW_DBG(buf->getBitDouble()); DRW_DBG("\n");
// DRW_DBG("Ambient Cmc or Enc: "); DRW_DBG(buf->getCmColor(version)); DRW_DBG("\n");
DRW_DBG("Ambient (Cmc or Enc?), Enc: "); DRW_DBG(buf->getEnColor(version)); DRW_DBG("\n");
DRW_DBG("Ambient (Cmc or Enc?), Enc: "); DRW_DBG(buf->getEnColor(version, color24, transparency)); DRW_DBG("\n");
}
ret = DRW_Entity::parseDwgEntHandle(version, buf);

Expand Down
40 changes: 18 additions & 22 deletions src/intern/dwgbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -787,36 +787,32 @@ duint32 dwgBuffer::getCmColor(DRW::Version v) {
* For R2004+, can be CMC or ENC
* RGB value, first 4bits 0xC0 => ByLayer, 0xC1 => ByBlock, 0xC2 => RGB, 0xC3 => last 4 are ACIS
*/
duint32 dwgBuffer::getEnColor(DRW::Version v) {
duint32 dwgBuffer::getEnColor(DRW::Version v, int &rgb, int &transparency ) {
if (v < DRW::AC1018) //2000-
return getSBitShort();
duint32 rgb = 0;
duint32 cb = 0;
rgb = -1;
transparency = 0;
duint16 idx = getBitShort();
DRW_DBG("idx reads COLOR: "); DRW_DBGH(idx);
duint16 flags = idx>>8;
idx = idx & 0x1FF; //RLZ: warning this is correct?
DRW_DBG("\nflag COLOR: "); DRW_DBGH(flags);
DRW_DBG(", index COLOR: "); DRW_DBGH(idx);
// if (flags & 0x80) {
// rgb = getBitLong();
// DRW_DBG("\nRGB COLOR: "); DRW_DBGH(rgb);
// }
if (flags & 0x20) {
cb = getBitLong();
DRW_DBG("\nTransparency COLOR: "); DRW_DBGH(cb);
}
if (flags & 0x40)
DRW_DBG("\nacdbColor COLOR are present");
else {
if (flags & 0x80) {
rgb = getBitLong();
DRW_DBG("\nRGB COLOR: "); DRW_DBGH(rgb);
}
DRW_DBG( "flag COLOR:" ); DRW_DBGH( flags ); DRW_DBG( ", index COLOR:" ); DRW_DBGH( idx ); DRW_DBG( "\n" );
if ( flags & 0x80 )
{
// complex color (rgb)
rgb = getBitLong() & 0xffffff;

DRW_DBG( "RGB COLOR:" ); DRW_DBGH( rgb ); DRW_DBG( "\n" );
if ( flags & 0x40 )
{
DRW_DBG( "acdbColor COLOR are present\n" );
}
}

/* if (flags & 0x80)
return getBitLong();*/
if (flags & 0x20) {
transparency = getBitLong();
DRW_DBG( "Transparency COLOR:" ); DRW_DBGH( transparency ); DRW_DBG( "\n" );
}

return idx; //default return ByLayer
}
Expand Down
2 changes: 1 addition & 1 deletion src/intern/dwgbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class dwgBuffer {
double getThickness(bool b_R2000_style);//BT
//3DD
duint32 getCmColor(DRW::Version v); //CMC
duint32 getEnColor(DRW::Version v); //ENC
duint32 getEnColor( DRW::Version v, int &rgb, int &transparency ); //ENC
//TC

duint16 getBERawShort16(); //RS big-endian order
Expand Down