Skip to content

Commit

Permalink
* qrencode_inner.h:
Browse files Browse the repository at this point in the history
  - Now this header is called only by test programs.
* qrencode.c, qrencode_inner.h:
  - Some definitions and declares written in qrencode_inner.h have been
    moved into qrencode.c:
  - QRraw_*() have been declared as __STATIC.
* mask.[ch], qrencode.c, qrencode_inner.h:
  - Mask_makeMask() now requires QRecLevel.
  - QRencode_writeFormatInformation() has been renamed and moved to
    Mask_writeFormatInformation(), and become __STATIC.
  • Loading branch information
fukuchi committed Oct 10, 2008
1 parent d4b0347 commit ce7aa9b
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 64 deletions.
14 changes: 14 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
2008.10.11 Kentaro FUKUCHI <fukuchi@megaui.net>
* qrencode_inner.h:
- Now this header is called only by test programs.
* qrencode.c, qrencode_inner.h:
- Some definitions and declares written in qrencode_inner.h have been
moved into qrencode.c:
- QRraw_*() have been declared as __STATIC.
* mask.[ch], qrencode.c, qrencode_inner.h:
- Mask_makeMask() now requires QRecLevel.
- QRencode_writeFormatInformation() has been renamed and moved to
Mask_writeFormatInformation(), and become __STATIC.
* tests/*.c:
- Unneeded #include "qrencode_inner.h" have been removed.

2008.10.11 Kentaro FUKUCHI <fukuchi@megaui.net>
* autogen.sh:
- Darwin workaround.
Expand Down
52 changes: 48 additions & 4 deletions mask.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,54 @@

#include <stdlib.h>
#include <limits.h>
#include "config.h"
#include "qrencode.h"
#include "qrencode_inner.h"
#include "qrspec.h"
#include "mask.h"

__STATIC int Mask_writeFormatInformation(int width, unsigned char *frame, int mask, QRecLevel level)
{
unsigned int format;
unsigned char v;
int i;
int blacks = 0;

format = QRspec_getFormatInfo(mask, level);

for(i=0; i<8; i++) {
if(format & 1) {
blacks += 2;
v = 0x85;
} else {
v = 0x84;
}
frame[width * 8 + width - 1 - i] = v;
if(i < 6) {
frame[width * i + 8] = v;
} else {
frame[width * (i + 1) + 8] = v;
}
format= format >> 1;
}
for(i=0; i<7; i++) {
if(format & 1) {
blacks += 2;
v = 0x85;
} else {
v = 0x84;
}
frame[width * (width - 7 + i) + 8] = v;
if(i == 0) {
frame[width * 8 + 7] = v;
} else {
frame[width * 8 + 6 - i] = v;
}
format= format >> 1;
}

return blacks;
}

/**
* Demerit coefficients.
* See Section 8.8.2, pp.45, JIS X0510:2004.
Expand Down Expand Up @@ -98,13 +141,14 @@ static MaskMaker *maskMakers[] = {
Mask_mask4, Mask_mask5, Mask_mask6, Mask_mask7
};

unsigned char *Mask_makeMask(int width, unsigned char *frame, int mask)
unsigned char *Mask_makeMask(int width, unsigned char *frame, int mask, QRecLevel level)
{
unsigned char *masked;

masked = (unsigned char *)malloc(width * width);

maskMakers[mask](width, frame, masked);
Mask_writeFormatInformation(width, masked, mask, level);

return masked;
}
Expand Down Expand Up @@ -149,7 +193,7 @@ static int Mask_calcN1N3(int length, int *runLength)
return demerit;
}

int Mask_evaluateSymbol(int width, unsigned char *frame)
__STATIC int Mask_evaluateSymbol(int width, unsigned char *frame)
{
int x, y;
unsigned char *p;
Expand Down Expand Up @@ -227,7 +271,7 @@ unsigned char *Mask_mask(int width, unsigned char *frame, QRecLevel level)
demerit = 0;
mask = (unsigned char *)malloc(width * width);
blacks = maskMakers[i](width, frame, mask);
blacks += QRcode_writeFormatInformation(width, mask, i, level);
blacks += Mask_writeFormatInformation(width, mask, i, level);
blacks = 100 * blacks / (width * width);
demerit = (abs(blacks - 50) / 5) * N4;
// n4 = demerit;
Expand Down
3 changes: 1 addition & 2 deletions mask.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@

#include "qrinput.h"

extern unsigned char *Mask_makeMask(int width, unsigned char *frame, int mask);
extern int Mask_evaluateSymbol(int width, unsigned char *frame);
extern unsigned char *Mask_makeMask(int width, unsigned char *frame, int mask, QRecLevel level);
extern unsigned char *Mask_mask(int width, unsigned char *frame, QRecLevel level);

#endif /* __MASK_H__ */
86 changes: 33 additions & 53 deletions qrencode.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
#include <string.h>
#include <errno.h>

#include "config.h"
#include "qrencode.h"
#include "qrencode_inner.h"
#include "qrspec.h"
#include "mqrspec.h"
#include "bitstream.h"
Expand All @@ -37,6 +37,24 @@
* Raw code
*****************************************************************************/

typedef struct {
int dataLength;
unsigned char *data;
int eccLength;
unsigned char *ecc;
} RSblock;

typedef struct {
int version;
unsigned char *datacode;
int blocks;
RSblock *rsblock;
int count;
int dataLength;
int eccLength;
int b1;
} QRRawCode;

static void RSblock_init(RSblock *block, int dl, unsigned char *data, int el)
{
RS *rs;
Expand All @@ -50,7 +68,7 @@ static void RSblock_init(RSblock *block, int dl, unsigned char *data, int el)
encode_rs_char(rs, data, block->ecc);
}

QRRawCode *QRraw_new(QRinput *input)
__STATIC QRRawCode *QRraw_new(QRinput *input)
{
QRRawCode *raw;
int *spec;
Expand Down Expand Up @@ -106,7 +124,7 @@ QRRawCode *QRraw_new(QRinput *input)
* @param raw raw code.
* @return code
*/
unsigned char QRraw_getCode(QRRawCode *raw)
__STATIC unsigned char QRraw_getCode(QRRawCode *raw)
{
int col, row;
unsigned char ret;
Expand All @@ -129,7 +147,7 @@ unsigned char QRraw_getCode(QRRawCode *raw)
return ret;
}

void QRraw_free(QRRawCode *raw)
__STATIC void QRraw_free(QRRawCode *raw)
{
int i;

Expand All @@ -146,6 +164,15 @@ void QRraw_free(QRRawCode *raw)
*****************************************************************************/

#if 0
typedef struct {
int version;
unsigned char *datacode;
RSblock *rsblock;
int count;
int dataLength;
int eccLength;
} MQRRawCode;

MQRRawCode *MQRraw_new(QRinput *input)
{
MQRRawCode *raw;
Expand Down Expand Up @@ -300,52 +327,6 @@ unsigned char *FrameFiller_fillerTest(int version)
}
#endif

/******************************************************************************
* Format information
*****************************************************************************/

int QRcode_writeFormatInformation(int width, unsigned char *frame, int mask, QRecLevel level)
{
unsigned int format;
unsigned char v;
int i;
int blacks = 0;

format = QRspec_getFormatInfo(mask, level);

for(i=0; i<8; i++) {
if(format & 1) {
blacks += 2;
v = 0x85;
} else {
v = 0x84;
}
frame[width * 8 + width - 1 - i] = v;
if(i < 6) {
frame[width * i + 8] = v;
} else {
frame[width * (i + 1) + 8] = v;
}
format= format >> 1;
}
for(i=0; i<7; i++) {
if(format & 1) {
blacks += 2;
v = 0x85;
} else {
v = 0x84;
}
frame[width * (width - 7 + i) + 8] = v;
if(i == 0) {
frame[width * 8 + 7] = v;
} else {
frame[width * 8 + 6 - i] = v;
}
format= format >> 1;
}

return blacks;
}

/******************************************************************************
* QR-code encoding
Expand Down Expand Up @@ -373,7 +354,7 @@ void QRcode_free(QRcode *qrcode)
free(qrcode);
}

QRcode *QRcode_encodeMask(QRinput *input, int mask)
__STATIC QRcode *QRcode_encodeMask(QRinput *input, int mask)
{
int width, version;
QRRawCode *raw;
Expand Down Expand Up @@ -421,8 +402,7 @@ QRcode *QRcode_encodeMask(QRinput *input, int mask)
if(mask < 0) {
masked = Mask_mask(width, frame, input->level);
} else {
masked = Mask_makeMask(width, frame, mask);
QRcode_writeFormatInformation(width, masked, mask, input->level);
masked = Mask_makeMask(width, frame, mask, input->level);
}
qrcode = QRcode_new(version, width, masked);

Expand Down
16 changes: 11 additions & 5 deletions qrencode_inner.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* qrencode - QR Code encoder
*
* Header for internal use
* Header for test use
* Copyright (C) 2006, 2007, 2008 Kentaro Fukuchi <fukuchi@megaui.net>
*
* This library is free software; you can redistribute it and/or
Expand All @@ -23,7 +23,7 @@
#define __QRENCODE_INNER_H__

/**
* This header file includes definitions for inner use.
* This header file includes definitions for test use.
*/

/******************************************************************************
Expand Down Expand Up @@ -75,9 +75,15 @@ extern void MQRraw_free(MQRRawCode *raw);
extern unsigned char *FrameFiller_fillerTest(int version);

/******************************************************************************
* Format information
* QR-code encoding
*****************************************************************************/
extern int QRcode_writeFormatInformation(int width, unsigned char *frame, int mask, QRecLevel level);

extern QRcode *QRcode_encodeMask(QRinput *input, int mask);

/******************************************************************************
* Mask
*****************************************************************************/

extern int Mask_evaluateSymbol(int width, unsigned char *frame);
extern int Mask_writeFormatInformation(int width, unsigned char *frame, int mask, QRecLevel level);

#endif /* __QRENCODE_INNER_H__ */

0 comments on commit ce7aa9b

Please sign in to comment.