Skip to content

Commit

Permalink
Fix memory alignment issues on ARM
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Aug 22, 2014
1 parent ae08c3e commit b5e9547
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 58 deletions.
26 changes: 13 additions & 13 deletions src/core/qgsclipper.cpp
Expand Up @@ -17,6 +17,7 @@
***************************************************************************/

#include "qgsclipper.h"
#include "qgsgeometry.h"

// Where has all the code gone?

Expand All @@ -37,16 +38,13 @@ const double QgsClipper::SMALL_NUM = 1e-12;

const unsigned char* QgsClipper::clippedLineWKB( const unsigned char* wkb, const QgsRectangle& clipExtent, QPolygonF& line )
{
wkb++; // jump over endian info
unsigned int wkbType = *(( int* ) wkb );
wkb += sizeof( unsigned int );
unsigned int nPoints = *(( int* ) wkb );
wkb += sizeof( unsigned int );
QgsConstWkbPtr wkbPtr( wkb + 1 );

bool hasZValue = ( wkbType == QGis::WKBLineString25D );
unsigned int wkbType, nPoints;

wkbPtr >> wkbType >> nPoints;

int sizeOfDoubleX = sizeof( double );
int sizeOfDoubleY = hasZValue ? 2 * sizeof( double ) : sizeof( double );
bool hasZValue = ( wkbType == QGis::WKBLineString25D );

double p0x, p0y, p1x = 0.0, p1y = 0.0; //original coordinates
double p1x_c, p1y_c; //clipped end coordinates
Expand All @@ -59,8 +57,9 @@ const unsigned char* QgsClipper::clippedLineWKB( const unsigned char* wkb, const
{
if ( i == 0 )
{
memcpy( &p1x, wkb, sizeof( double ) ); wkb += sizeOfDoubleX;
memcpy( &p1y, wkb, sizeof( double ) ); wkb += sizeOfDoubleY;
wkbPtr >> p1x >> p1y;
if ( hasZValue )
wkbPtr += sizeof( double );

continue;
}
Expand All @@ -69,8 +68,9 @@ const unsigned char* QgsClipper::clippedLineWKB( const unsigned char* wkb, const
p0x = p1x;
p0y = p1y;

memcpy( &p1x, wkb, sizeof( double ) ); wkb += sizeOfDoubleX;
memcpy( &p1y, wkb, sizeof( double ) ); wkb += sizeOfDoubleY;
wkbPtr >> p1x >> p1y;
if ( hasZValue )
wkbPtr += sizeof( double );

p1x_c = p1x; p1y_c = p1y;
if ( clipLineSegment( clipExtent.xMinimum(), clipExtent.xMaximum(), clipExtent.yMinimum(), clipExtent.yMaximum(),
Expand All @@ -94,7 +94,7 @@ const unsigned char* QgsClipper::clippedLineWKB( const unsigned char* wkb, const
}
}
}
return wkb;
return wkbPtr;
}

void QgsClipper::connectSeparatedLines( double x0, double y0, double x1, double y1,
Expand Down
85 changes: 40 additions & 45 deletions src/core/symbology-ng/qgsrendererv2.cpp
Expand Up @@ -36,15 +36,15 @@

const unsigned char* QgsFeatureRendererV2::_getPoint( QPointF& pt, QgsRenderContext& context, const unsigned char* wkb )
{
wkb++; // jump over endian info
unsigned int wkbType = *(( int* ) wkb );
wkb += sizeof( unsigned int );
QgsConstWkbPtr wkbPtr( wkb + 1 );
unsigned int wkbType;
wkbPtr >> wkbType;

double x = *(( double * ) wkb ); wkb += sizeof( double );
double y = *(( double * ) wkb ); wkb += sizeof( double );
double x, y;
wkbPtr >> x >> y;

if ( wkbType == QGis::WKBPolygon25D )
wkb += sizeof( double );
wkbPtr += sizeof( double );

if ( context.coordinateTransform() )
{
Expand All @@ -55,22 +55,17 @@ const unsigned char* QgsFeatureRendererV2::_getPoint( QPointF& pt, QgsRenderCont
context.mapToPixel().transformInPlace( x, y );

pt = QPointF( x, y );
return wkb;
return wkbPtr;
}

const unsigned char* QgsFeatureRendererV2::_getLineString( QPolygonF& pts, QgsRenderContext& context, const unsigned char* wkb )
{
wkb++; // jump over endian info
unsigned int wkbType = *(( int* ) wkb );
wkb += sizeof( unsigned int );
unsigned int nPoints = *(( int* ) wkb );
wkb += sizeof( unsigned int );
QgsConstWkbPtr wkbPtr( wkb );
unsigned int wkbType, nPoints;
wkbPtr >> wkbType >> nPoints;

bool hasZValue = ( wkbType == QGis::WKBLineString25D );

int sizeOfDoubleX = sizeof( double );
int sizeOfDoubleY = hasZValue ? 2 * sizeof( double ) : sizeof( double );

double x, y;
const QgsCoordinateTransform* ct = context.coordinateTransform();
const QgsMapToPixel& mtp = context.mapToPixel();
Expand All @@ -81,7 +76,7 @@ const unsigned char* QgsFeatureRendererV2::_getLineString( QPolygonF& pts, QgsRe
const QgsRectangle& e = context.extent();
double cw = e.width() / 10; double ch = e.height() / 10;
QgsRectangle clipRect( e.xMinimum() - cw, e.yMinimum() - ch, e.xMaximum() + cw, e.yMaximum() + ch );
wkb = QgsClipper::clippedLineWKB( wkb - ( 2 * sizeof( unsigned int ) + 1 ), clipRect, pts );
wkbPtr = QgsConstWkbPtr( QgsClipper::clippedLineWKB( wkb, clipRect, pts ) );
}
else
{
Expand All @@ -90,8 +85,9 @@ const unsigned char* QgsFeatureRendererV2::_getLineString( QPolygonF& pts, QgsRe
QPointF* ptr = pts.data();
for ( unsigned int i = 0; i < nPoints; ++i, ++ptr )
{
memcpy( &x, wkb, sizeof( double ) ); wkb += sizeOfDoubleX;
memcpy( &y, wkb, sizeof( double ) ); wkb += sizeOfDoubleY;
wkbPtr >> x >> y;
if ( hasZValue )
wkbPtr += sizeof( double );

*ptr = QPointF( x, y );
}
Expand All @@ -109,26 +105,21 @@ const unsigned char* QgsFeatureRendererV2::_getLineString( QPolygonF& pts, QgsRe
mtp.transformInPlace( ptr->rx(), ptr->ry() );
}


return wkb;
return wkbPtr;
}

const unsigned char* QgsFeatureRendererV2::_getPolygon( QPolygonF& pts, QList<QPolygonF>& holes, QgsRenderContext& context, const unsigned char* wkb )
{
wkb++; // jump over endian info
unsigned int wkbType = *(( int* ) wkb );
wkb += sizeof( unsigned int ); // jump over wkb type
unsigned int numRings = *(( int* ) wkb );
wkb += sizeof( unsigned int );
QgsConstWkbPtr wkbPtr( wkb + 1 );

unsigned int wkbType, numRings;
wkbPtr >> wkbType >> numRings;

if ( numRings == 0 ) // sanity check for zero rings in polygon
return wkb;
return wkbPtr;

bool hasZValue = ( wkbType == QGis::WKBPolygon25D );

int sizeOfDoubleX = sizeof( double );
int sizeOfDoubleY = hasZValue ? 2 * sizeof( double ) : sizeof( double );

double x, y;
holes.clear();

Expand All @@ -140,17 +131,18 @@ const unsigned char* QgsFeatureRendererV2::_getPolygon( QPolygonF& pts, QList<QP

for ( unsigned int idx = 0; idx < numRings; idx++ )
{
unsigned int nPoints = *(( int* )wkb );
wkb += sizeof( unsigned int );
unsigned int nPoints;
wkbPtr >> nPoints;

QPolygonF poly( nPoints );

// Extract the points from the WKB and store in a pair of vectors.
QPointF* ptr = poly.data();
for ( unsigned int jdx = 0; jdx < nPoints; ++jdx, ++ptr )
{
memcpy( &x, wkb, sizeof( double ) ); wkb += sizeOfDoubleX;
memcpy( &y, wkb, sizeof( double ) ); wkb += sizeOfDoubleY;
wkbPtr >> x >> y;
if ( hasZValue )
wkbPtr += sizeof( double );

*ptr = QPointF( x, y );
}
Expand Down Expand Up @@ -181,7 +173,7 @@ const unsigned char* QgsFeatureRendererV2::_getPolygon( QPolygonF& pts, QList<QP
holes.append( poly );
}

return wkb;
return wkbPtr;
}

void QgsFeatureRendererV2::setScaleMethodToSymbol( QgsSymbolV2* symbol, int scaleMethod )
Expand Down Expand Up @@ -296,14 +288,15 @@ void QgsFeatureRendererV2::renderFeatureWithSymbol( QgsFeature& feature, QgsSymb
break;
}

const unsigned char* wkb = geom->asWkb();
unsigned int num = *(( int* )( wkb + 5 ) );
const unsigned char* ptr = wkb + 9;
QgsConstWkbPtr wkbPtr( geom->asWkb() + 5 );
unsigned int num;
wkbPtr >> num;
const unsigned char* ptr = wkbPtr;
QPointF pt;

for ( unsigned int i = 0; i < num; ++i )
{
ptr = _getPoint( pt, context, ptr );
ptr = QgsConstWkbPtr( _getPoint( pt, context, ptr ) );
(( QgsMarkerSymbolV2* )symbol )->renderPoint( pt, &feature, context, layer, selected );

//if ( drawVertexMarker )
Expand All @@ -321,14 +314,15 @@ void QgsFeatureRendererV2::renderFeatureWithSymbol( QgsFeature& feature, QgsSymb
break;
}

const unsigned char* wkb = geom->asWkb();
unsigned int num = *(( int* )( wkb + 5 ) );
const unsigned char* ptr = wkb + 9;
QgsConstWkbPtr wkbPtr( geom->asWkb() + 5 );
unsigned int num;
wkbPtr >> num;
const unsigned char* ptr = wkbPtr;
QPolygonF pts;

for ( unsigned int i = 0; i < num; ++i )
{
ptr = _getLineString( pts, context, ptr );
ptr = QgsConstWkbPtr( _getLineString( pts, context, ptr ) );
(( QgsLineSymbolV2* )symbol )->renderPolyline( pts, &feature, context, layer, selected );

if ( drawVertexMarker )
Expand All @@ -346,9 +340,10 @@ void QgsFeatureRendererV2::renderFeatureWithSymbol( QgsFeature& feature, QgsSymb
break;
}

const unsigned char* wkb = geom->asWkb();
unsigned int num = *(( int* )( wkb + 5 ) );
const unsigned char* ptr = wkb + 9;
QgsConstWkbPtr wkbPtr( geom->asWkb() + 5 );
unsigned int num;
wkbPtr >> num;
const unsigned char* ptr = wkbPtr;
QPolygonF pts;
QList<QPolygonF> holes;

Expand Down

0 comments on commit b5e9547

Please sign in to comment.