Skip to content

Commit

Permalink
SVG: use relative path motion in scanlines
Browse files Browse the repository at this point in the history
Most scanlines are built from alternating small strides of black and
white pixels, therefore using relative motions results in smaller
numbers passed to the `m` command. On the larger QR Codes this can lead
to savings of as much as 30% of the previous output file size in RLE
mode.
  • Loading branch information
Oblomov committed Feb 15, 2014
1 parent 9b487fc commit 3d9c6a5
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions qrenc.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ static int writeSVG( QRcode *qrcode, const char *outfile )
{
FILE *fp;
unsigned char *row, *p;
int x, y, x0, pen;
int x, y, x0, x1, pen, abs;
int symwidth, realwidth;
float scale;
char fg[7], bg[7];
Expand Down Expand Up @@ -526,19 +526,26 @@ static int writeSVG( QRcode *qrcode, const char *outfile )
/* simple RLE */
pen = 0;
x0 = 0;
x1 = 0;
for(x=0; x<qrcode->width; x++) {
if( !pen ) {
pen = *(row+x)&0x1;
x0 = x;
} else {
if(!(*(row+x)&0x1)) {
fprintf(fp, "M%d,%dh%d", x0, y, x - x0);
/* motion is initially absolute */
abs = (x1 == 0);
fprintf(fp, "%c%d,%dh%d", abs ? 'M' : 'm',
(x0 - x1), abs ? y : 0, x - x0);
x1 = x;
pen = 0;
}
}
}
if( pen ) {
fprintf(fp, "M%d,%dh%d", x0, y, qrcode->width - x0);
abs = (x1 == 0);
fprintf(fp, "%c%d,%dh%d", abs ? 'M' : 'm',
(x0 - x1), abs ? y : 0, qrcode->width - x0);
}
if (y < qrcode->width - 1) {
fprintf( fp, "\n\t\t\t\t" );
Expand Down

0 comments on commit 3d9c6a5

Please sign in to comment.