Skip to content
Permalink
Browse files

Prepare color palette matching for dxf

  • Loading branch information
mhugent committed Sep 16, 2013
1 parent dc62376 commit 93122767e4e55e2dd3d943cbad7c07ed853e989a
Showing with 44 additions and 1 deletion.
  1. +38 −1 src/core/qgsdxfexport.cpp
  2. +6 −0 src/core/qgsdxfexport.h
@@ -23,7 +23,7 @@
#include <QIODevice>
#include <QTextStream>

QgsDxfExport::QgsDxfExport()
QgsDxfExport::QgsDxfExport(): mSymbologyScaleDenominator( 1.0 ), mSymbologyExport( NoSymbology )
{
}

@@ -351,10 +351,47 @@ double QgsDxfExport::scaleToMapUnits( double value, QgsSymbolV2::OutputUnit symb

int QgsDxfExport::colorFromSymbolLayer( const QgsSymbolLayerV2* symbolLayer )
{
if ( !symbolLayer )
{
return 0;
}


return 5; //todo...
}

double QgsDxfExport::widthFromSymbolLayer( const QgsSymbolLayerV2* symbolLayer )
{
return 50; //todo...
}

int QgsDxfExport::closestMatch( QRgb pixel, const QVector<QRgb>& palette )
{
int idx = 0;
int current_distance = INT_MAX;
for ( int i = 0; i < palette.size(); ++i )
{
int dist = pixel_distance( pixel, palette.at( i ) );
if ( dist < current_distance )
{
current_distance = dist;
idx = i;
}
}
return idx;
}

int QgsDxfExport::pixel_distance( QRgb p1, QRgb p2 )
{
int r1 = qRed( p1 );
int g1 = qGreen( p1 );
int b1 = qBlue( p1 );
int a1 = qAlpha( p1 );

int r2 = qRed( p2 );
int g2 = qGreen( p2 );
int b2 = qBlue( p2 );
int a2 = qAlpha( p2 );

return abs( r1 - r2 ) + abs( g1 - g2 ) + abs( b1 - b2 ) + abs( a1 - a2 );
}
@@ -20,6 +20,7 @@

#include "qgsgeometry.h"
#include "qgssymbolv2.h"
#include <QColor>
#include <QList>

class QgsMapLayer;
@@ -78,6 +79,11 @@ class QgsDxfExport
//returns dxf palette index from symbol layer color
int colorFromSymbolLayer( const QgsSymbolLayerV2* symbolLayer );
double widthFromSymbolLayer( const QgsSymbolLayerV2* symbolLayer );

//functions for dxf palette
static int closestMatch( QRgb pixel, const QVector<QRgb>& palette );
static int pixel_distance( QRgb p1, QRgb p2 );

};

#endif // QGSDXFEXPORT_H

0 comments on commit 9312276

Please sign in to comment.