Skip to content

Commit

Permalink
libdxfrw: add support for rgb colors and transparency
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Dec 14, 2016
1 parent b351ff2 commit 4124ab8
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 67 deletions.
24 changes: 14 additions & 10 deletions src/app/dwg/libdxfrw/drw_entities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,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 @@ -279,7 +282,7 @@ bool DRW_Entity::parseDwg( DRW::Version version, dwgBuffer *buf, dwgBuffer* strB
{
/* RLZ: TODO */
dwgHandle ah = buf->getHandle();
DRW_DBG( "App Handle: " );
DRW_DBG( "\n App Handle: " );
DRW_DBGHL( ah.code, ah.size, ah.ref );
duint8 *tmpExtData = new duint8[extDataSize];
buf->getBytes( tmpExtData, extDataSize );
Expand Down Expand Up @@ -316,7 +319,7 @@ bool DRW_Entity::parseDwg( DRW::Version version, dwgBuffer *buf, dwgBuffer* strB
DRW_DBG( extDataSize );
} //end parsing extData (EED)
duint8 graphFlag = buf->getBit(); //B
DRW_DBG( " graphFlag: " );
DRW_DBG( "\n graphFlag: " );
DRW_DBG( graphFlag );
DRW_DBG( "\n" );
if ( graphFlag )
Expand Down Expand Up @@ -396,7 +399,7 @@ bool DRW_Entity::parseDwg( DRW::Version version, dwgBuffer *buf, dwgBuffer* strB
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 );
Expand All @@ -421,7 +424,7 @@ bool DRW_Entity::parseDwg( DRW::Version version, dwgBuffer *buf, dwgBuffer* strB
{
ltFlags = plotFlags;
lineType = plotStyleName; //RLZ: howto solve? if needed plotStyleName;
DRW_DBG( "ltFlags: " );
DRW_DBG( " ltFlags: " );
DRW_DBG( ltFlags );
DRW_DBG( " lineType: " );
DRW_DBG( lineType.c_str() );
Expand All @@ -436,21 +439,21 @@ bool DRW_Entity::parseDwg( DRW::Version version, dwgBuffer *buf, dwgBuffer* strB
if ( version > DRW::AC1018 ) //2007+
{
materialFlag = buf->get2Bits(); //BB
DRW_DBG( "materialFlag: " );
DRW_DBG( " materialFlag: " );
DRW_DBG( materialFlag );
shadowFlag = buf->getRawChar8(); //RC
DRW_DBG( "shadowFlag: " );
DRW_DBG( " shadowFlag: " );
DRW_DBG( shadowFlag );
DRW_DBG( "\n" );
}
if ( version > DRW::AC1021 ) //2010+
{
duint8 visualFlags = buf->get2Bits(); //full & face visual style
DRW_DBG( "shadowFlag 2: " );
DRW_DBG( " shadowFlag 2: " );
DRW_DBG( visualFlags );
DRW_DBG( "\n" );
duint8 unk = buf->getBit(); //edge visual style
DRW_DBG( "unknown bit: " );
DRW_DBG( " unknown bit: " );
DRW_DBG( unk );
DRW_DBG( "\n" );
}
Expand Down Expand Up @@ -1910,7 +1913,7 @@ bool DRW_MText::parseDwg( DRW::Version version, dwgBuffer *buf, duint32 bs )
if ( version > DRW::AC1014 ) //2000+
{
buf->getBitShort();/* Linespacing Style BS 73 */
buf->getBitDouble();/* Linespacing Factor BD 44 */
interlin = buf->getBitDouble();/* Linespacing Factor BD 44 */
buf->getBit();/* Unknown bit B */
}
if ( version > DRW::AC1015 ) //2004+
Expand Down Expand Up @@ -3842,7 +3845,7 @@ bool DRW_Viewport::parseDwg( DRW::Version version, dwgBuffer *buf, duint32 bs )
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( buf->getEnColor( version, color24, transparency ) );
DRW_DBG( "\n" );
}
ret = DRW_Entity::parseDwgEntHandle( version, buf );
Expand Down Expand Up @@ -3920,5 +3923,6 @@ bool DRW_Viewport::parseDwg( DRW::Version version, dwgBuffer *buf, duint32 bs )

if ( !ret )
return ret;

return buf->isGood();
}
44 changes: 22 additions & 22 deletions src/app/dwg/libdxfrw/drw_entities.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ namespace DRW
enum ETYPE
{
E3DFACE,
// E3DSOLID, // encrypted proprietary data
// ACAD_PROXY_ENTITY,
E3DSOLID, // encrypted proprietary data
ACAD_PROXY_ENTITY,
ARC,
// ATTDEF,
// ATTRIB,
ATTDEF,
ATTRIB,
BLOCK, // and ENDBLK
// BODY, // encrypted proprietary data
BODY, // encrypted proprietary data
CIRCLE,
DIMENSION,
DIMALIGNED,
Expand All @@ -48,39 +48,39 @@ namespace DRW
DIMORDINATE,
ELLIPSE,
HATCH,
// HELIX,
HELIX,
IMAGE,
INSERT,
LEADER,
// LIGHT,
LIGHT,
LINE,
LWPOLYLINE,
// MESH,
// MLINE,
// MLEADERSTYLE,
// MLEADER,
MESH,
MLINE,
MLEADERSTYLE,
MLEADER,
MTEXT,
// OLEFRAME,
// OLE2FRAME,
OLEFRAME,
OLE2FRAME,
POINT,
POLYLINE,
RAY,
// REGION, // encrypted proprietary data
// SECTION,
// SEQEND, // not needed?? used in polyline and insert/attrib and dwg
// SHAPE,
REGION, // encrypted proprietary data
SECTION,
SEQEND, // not needed?? used in polyline and insert/attrib and dwg
SHAPE,
SOLID,
SPLINE,
// SUN,
// SURFACE, // encrypted proprietary data can be four types
// TABLE,
SUN,
SURFACE, // encrypted proprietary data can be four types
TABLE,
TEXT,
// TOLERANCE,
TOLERANCE,
TRACE,
UNDERLAY,
VERTEX,
VIEWPORT,
// WIPEOUT, // WIPEOUTVARIABLE
WIPEOUT, // WIPEOUTVARIABLE
XLINE,
UNKNOWN
};
Expand Down
3 changes: 3 additions & 0 deletions src/app/dwg/libdxfrw/drw_objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,9 @@ void DRW_Layer::parseCode( int code, dxfReader *reader )
case 420:
color24 = reader->getInt32();
break;
case 440:
transparency = reader->getInt32();
break;
default:
DRW_TableEntry::parseCode( code, reader );
break;
Expand Down
1 change: 1 addition & 0 deletions src/app/dwg/libdxfrw/drw_objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ class DRW_Layer : public DRW_TableEntry
UTF8STRING lineType; /*!< line type, code 6 */
int color; /*!< layer color, code 62 */
int color24; /*!< 24-bit color, code 420 */
int transparency; /*!< Transparency, code 440 */
bool plotF; /*!< Plot flag, code 290 */
enum DRW_LW_Conv::lineWidth lWeight; /*!< layer lineweight, code 370 */
std::string handlePlotS; /*!< Hard-pointer ID/handle of plotstyle, code 390 */
Expand Down
53 changes: 39 additions & 14 deletions src/app/dwg/libdxfrw/intern/drw_dbg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@
** along with this program. If not, see <http://www.gnu.org/licenses/>. **
******************************************************************************/

#include <iostream>
#include <iomanip>
#include "drw_dbg.h"
#include <QDebug>

#include "../../../../core/qgslogger.h"


#include <QTextStream>
#include <QStringList>

DRW_dbg *DRW_dbg::instance = nullptr;

/*********private clases*************/
/*********private classes*************/
class print_none
{
public:
Expand Down Expand Up @@ -45,7 +48,11 @@ class print_debug : public print_none
virtual void printHL( int c, int s, int h );
virtual void printPT( double x, double y, double z );
print_debug();
virtual ~print_debug() {}
virtual ~print_debug() { QgsDebugMsgLevel( mBuf, 4 ); }
private:
QString mBuf;
QTextStream mTS;
void flush();
};

/********* debug class *************/
Expand Down Expand Up @@ -137,46 +144,64 @@ void DRW_dbg::printPT( double x, double y, double z )
prClass->printPT( x, y, z );
}

print_debug::print_debug()
print_debug::print_debug() : mTS( &mBuf )
{
}

void print_debug::flush()
{
QStringList lines = mBuf.split( '\n' );
for ( int i = 0; i < lines.size() - 1; i++ )
{
QgsDebugMsgLevel( lines[i], 4 );
}
mBuf = lines.last();
}

void print_debug::printS( std::string s )
{
qDebug() << QString::fromStdString( s );
mTS << QString::fromStdString( s );
flush();
}

void print_debug::printI( long long int i )
{
qDebug() << i;
mTS << i;
flush();
}

void print_debug::printUI( long long unsigned int i )
{
qDebug() << i;
mTS << i;
flush();
}

void print_debug::printD( double d )
{
qDebug() << QString( "%1 " ).arg( d, 0, 'g' );
mTS << QString( "%1 " ).arg( d, 0, 'g' );
flush();
}

void print_debug::printH( long long i )
{
qDebug() << QString( "0x%1" ).arg( i, 0, 16 );
mTS << QString( "0x%1" ).arg( i, 0, 16 );
flush();
}

void print_debug::printB( int i )
{
qDebug() << QString( "0%1" ).arg( i, 0, 8 );
mTS << QString( "0%1" ).arg( i, 0, 8 );
flush();
}

void print_debug::printHL( int c, int s, int h )
{
qDebug() << QString( "%1.%2 0x%3" ).arg( c ).arg( s ).arg( h, 0, 16 );
mTS << QString( "%1.%2 0x%3" ).arg( c ).arg( s ).arg( h, 0, 16 );
flush();
}

void print_debug::printPT( double x, double y, double z )
{
qDebug() << QString( "x:%1 y:%2 z:%3" ).arg( x, 0, 'g' ).arg( y, 0, 'g' ).arg( z, 0, 'g' );
mTS << QString( "x:%1 y:%2 z:%3" ).arg( x, 0, 'g' ).arg( y, 0, 'g' ).arg( z, 0, 'g' );
flush();
}
42 changes: 22 additions & 20 deletions src/app/dwg/libdxfrw/intern/dwgbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -904,45 +904,47 @@ 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;

rgb = -1;
transparency = 0;

duint32 cb = 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 )
{
// complex color (rgb)
rgb = getBitLong() & 0xffffff;

DRW_DBG( "\nRGB COLOR: " );
DRW_DBGH( rgb );

if ( flags & 0x80 )
{
rgb = getBitLong();
DRW_DBG( "\nRGB COLOR: " );
DRW_DBGH( rgb );
DRW_DBG( "\nacdbColor COLOR are present" );
}
}

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

return idx; //default return ByLayer
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/dwg/libdxfrw/intern/dwgbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,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

0 comments on commit 4124ab8

Please sign in to comment.