rqr 0.2.0-x86-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +13 -0
- data/License.txt +23 -0
- data/Manifest.txt +30 -0
- data/README.txt +83 -0
- data/Rakefile +5 -0
- data/config/hoe.rb +87 -0
- data/config/requirements.rb +15 -0
- data/ext/rqr/QR_Encode.cpp +1949 -0
- data/ext/rqr/QR_Encode.h +152 -0
- data/ext/rqr/qr.i +17 -0
- data/ext/rqr/qr_draw.h +48 -0
- data/ext/rqr/qr_draw_jpeg.cpp +104 -0
- data/ext/rqr/qr_draw_jpeg.h +29 -0
- data/ext/rqr/qr_draw_png.cpp +119 -0
- data/ext/rqr/qr_draw_png.h +28 -0
- data/ext/rqr/qr_draw_ps.cpp +233 -0
- data/ext/rqr/qr_draw_ps.h +37 -0
- data/ext/rqr/qr_draw_tiff.cpp +108 -0
- data/ext/rqr/qr_draw_tiff.h +29 -0
- data/ext/rqr/qr_wrap.cxx +3973 -0
- data/ext/rqr/win2ansi.h +20 -0
- data/lib/rqr.rb +9 -0
- data/lib/rqr/QR.so +0 -0
- data/lib/rqr/errors.rb +9 -0
- data/lib/rqr/qrcode.rb +88 -0
- data/lib/rqr/version.rb +9 -0
- data/setup.rb +1585 -0
- data/test/test_helper.rb +2 -0
- data/test/test_rqr.rb +66 -0
- metadata +88 -0
data/ext/rqr/QR_Encode.h
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
//---(1)��������-------------------------
|
2
|
+
//// QR_Encode.h : CQR_Encode �N���X�錾����уC���^�[�t�F�C�X��`
|
3
|
+
//// Date 2006/05/17 Ver. 1.12 [Class Ver.1.22] Psytec Inc.
|
4
|
+
//
|
5
|
+
//#if !defined(AFX_QR_ENCODE_H__AC886DF7_C0AE_4C9F_AC7A_FCDA8CB1DD37__INCLUDED_)
|
6
|
+
//#define AFX_QR_ENCODE_H__AC886DF7_C0AE_4C9F_AC7A_FCDA8CB1DD37__INCLUDED_
|
7
|
+
//
|
8
|
+
//#if _MSC_VER > 1000
|
9
|
+
//#pragma once
|
10
|
+
//#endif // _MSC_VER > 1000
|
11
|
+
//---(1)�����܂ł��R�����g�A�E�g-----------
|
12
|
+
|
13
|
+
//---(2)��������-----------
|
14
|
+
#ifndef __QR_ENCODER__
|
15
|
+
#define __QR_ENCODER__
|
16
|
+
#include "win2ansi.h"
|
17
|
+
//---(2)�����܂ł�lj�-----------
|
18
|
+
|
19
|
+
/////////////////////////////////////////////////////////////////////////////
|
20
|
+
// �萔
|
21
|
+
|
22
|
+
// ���������x��
|
23
|
+
#define QR_LEVEL_L 0
|
24
|
+
#define QR_LEVEL_M 1
|
25
|
+
#define QR_LEVEL_Q 2
|
26
|
+
#define QR_LEVEL_H 3
|
27
|
+
|
28
|
+
// �f�[�^���[�h
|
29
|
+
#define QR_MODE_NUMERAL 0
|
30
|
+
#define QR_MODE_ALPHABET 1
|
31
|
+
#define QR_MODE_8BIT 2
|
32
|
+
#define QR_MODE_KANJI 3
|
33
|
+
|
34
|
+
// �o�[�W����(�^��)�O���[�v
|
35
|
+
#define QR_VRESION_S 0 // 1 �` 9
|
36
|
+
#define QR_VRESION_M 1 // 10 �` 26
|
37
|
+
#define QR_VRESION_L 2 // 27 �` 40
|
38
|
+
|
39
|
+
#define MAX_ALLCODEWORD 3706 // ���R�[�h���[�h���ő�l
|
40
|
+
#define MAX_DATACODEWORD 2956 // �f�[�^�R�[�h���[�h�ő�l(�o�[�W����40-L)
|
41
|
+
#define MAX_CODEBLOCK 153 // �u���b�N�f�[�^�R�[�h���[�h���ő�l(�q�r�R�[�h���[�h���܂�)
|
42
|
+
#define MAX_MODULESIZE 177 // ��Ӄ��W���[�����ő�l
|
43
|
+
|
44
|
+
// �r�b�g�}�b�v�`�掞�}�[�W��
|
45
|
+
#define QR_MARGIN 4
|
46
|
+
|
47
|
+
|
48
|
+
/////////////////////////////////////////////////////////////////////////////
|
49
|
+
typedef struct tagRS_BLOCKINFO
|
50
|
+
{
|
51
|
+
int ncRSBlock; // �q�r�u���b�N��
|
52
|
+
int ncAllCodeWord; // �u���b�N���R�[�h���[�h��
|
53
|
+
int ncDataCodeWord; // �f�[�^�R�[�h���[�h��(�R�[�h���[�h�� - �q�r�R�[�h���[�h��)
|
54
|
+
|
55
|
+
} RS_BLOCKINFO, *LPRS_BLOCKINFO;
|
56
|
+
|
57
|
+
|
58
|
+
/////////////////////////////////////////////////////////////////////////////
|
59
|
+
// QR�R�[�h�o�[�W����(�^��)�֘A���
|
60
|
+
|
61
|
+
typedef struct tagQR_VERSIONINFO
|
62
|
+
{
|
63
|
+
int nVersionNo; // �o�[�W����(�^��)�ԍ�(1�`40)
|
64
|
+
int ncAllCodeWord; // ���R�[�h���[�h��
|
65
|
+
|
66
|
+
// �ȉ��z��Y���͌�������(0 = L, 1 = M, 2 = Q, 3 = H)
|
67
|
+
int ncDataCodeWord[4]; // �f�[�^�R�[�h���[�h��(���R�[�h���[�h�� - �q�r�R�[�h���[�h��)
|
68
|
+
|
69
|
+
int ncAlignPoint; // �A���C�����g�p�^�[�����W��
|
70
|
+
int nAlignPoint[6]; // �A���C�����g�p�^�[�����S���W
|
71
|
+
|
72
|
+
RS_BLOCKINFO RS_BlockInfo1[4]; // �q�r�u���b�N���(1)
|
73
|
+
RS_BLOCKINFO RS_BlockInfo2[4]; // �q�r�u���b�N���(2)
|
74
|
+
|
75
|
+
} QR_VERSIONINFO, *LPQR_VERSIONINFO;
|
76
|
+
|
77
|
+
|
78
|
+
/////////////////////////////////////////////////////////////////////////////
|
79
|
+
// CQR_Encode �N���X
|
80
|
+
|
81
|
+
class CQR_Encode
|
82
|
+
{
|
83
|
+
// �\�z/����
|
84
|
+
public:
|
85
|
+
CQR_Encode();
|
86
|
+
~CQR_Encode();
|
87
|
+
|
88
|
+
public:
|
89
|
+
int m_nLevel; // ���������x��
|
90
|
+
int m_nVersion; // �o�[�W����(�^��)
|
91
|
+
BOOL m_bAutoExtent; // �o�[�W����(�^��)�����g���w��t���O
|
92
|
+
int m_nMaskingNo; // �}�X�L���O�p�^�[���ԍ�
|
93
|
+
|
94
|
+
public:
|
95
|
+
int m_nSymbleSize;
|
96
|
+
BYTE m_byModuleData[MAX_MODULESIZE][MAX_MODULESIZE]; // [x][y]
|
97
|
+
// bit5:�@�\���W���[���i�}�X�L���O�ΏۊO�j�t���O
|
98
|
+
// bit4:�@�\���W���[���`��f�[�^
|
99
|
+
// bit1:�G���R�[�h�f�[�^
|
100
|
+
// bit0:�}�X�N��G���R�[�h�`��f�[�^
|
101
|
+
// 20h�Ƃ̘_���a�ɂ��@�\���W���[������A11h�Ƃ̘_���a�ɂ��`��i�ŏI�I�ɂ�BOOL�l���j
|
102
|
+
|
103
|
+
private:
|
104
|
+
int m_ncDataCodeWordBit; // �f�[�^�R�[�h���[�h�r�b�g��
|
105
|
+
BYTE m_byDataCodeWord[MAX_DATACODEWORD]; // ���̓f�[�^�G���R�[�h�G���A
|
106
|
+
|
107
|
+
int m_ncDataBlock;
|
108
|
+
BYTE m_byBlockMode[MAX_DATACODEWORD];
|
109
|
+
int m_nBlockLength[MAX_DATACODEWORD];
|
110
|
+
|
111
|
+
int m_ncAllCodeWord; // ���R�[�h���[�h��(�q�r�������f�[�^���܂�)
|
112
|
+
BYTE m_byAllCodeWord[MAX_ALLCODEWORD]; // ���R�[�h���[�h�Z�o�G���A
|
113
|
+
BYTE m_byRSWork[MAX_CODEBLOCK]; // �q�r�R�[�h���[�h�Z�o���[�N
|
114
|
+
|
115
|
+
// �f�[�^�G���R�[�h�֘A�t�@���N�V����
|
116
|
+
public:
|
117
|
+
BOOL EncodeData(int nLevel, int nVersion, BOOL bAutoExtent, int nMaskingNo, LPCSTR lpsSource, int ncSource = 0);
|
118
|
+
|
119
|
+
private:
|
120
|
+
int GetEncodeVersion(int nVersion, LPCSTR lpsSource, int ncLength);
|
121
|
+
BOOL EncodeSourceData(LPCSTR lpsSource, int ncLength, int nVerGroup);
|
122
|
+
|
123
|
+
int GetBitLength(BYTE nMode, int ncData, int nVerGroup);
|
124
|
+
|
125
|
+
int SetBitStream(int nIndex, WORD wData, int ncData);
|
126
|
+
|
127
|
+
BOOL IsNumeralData(unsigned char c);
|
128
|
+
BOOL IsAlphabetData(unsigned char c);
|
129
|
+
BOOL IsKanjiData(unsigned char c1, unsigned char c2);
|
130
|
+
|
131
|
+
BYTE AlphabetToBinaly(unsigned char c);
|
132
|
+
WORD KanjiToBinaly(WORD wc);
|
133
|
+
|
134
|
+
void GetRSCodeWord(LPBYTE lpbyRSWork, int ncDataCodeWord, int ncRSCodeWord);
|
135
|
+
|
136
|
+
// ���W���[���z�u�֘A�t�@���N�V����
|
137
|
+
private:
|
138
|
+
void FormatModule();
|
139
|
+
|
140
|
+
void SetFunctionModule();
|
141
|
+
void SetFinderPattern(int x, int y);
|
142
|
+
void SetAlignmentPattern(int x, int y);
|
143
|
+
void SetVersionPattern();
|
144
|
+
void SetCodeWordPattern();
|
145
|
+
void SetMaskingPattern(int nPatternNo);
|
146
|
+
void SetFormatInfoPattern(int nPatternNo);
|
147
|
+
int CountPenalty();
|
148
|
+
};
|
149
|
+
|
150
|
+
/////////////////////////////////////////////////////////////////////////////
|
151
|
+
|
152
|
+
#endif // !defined(AFX_QR_ENCODE_H__AC886DF7_C0AE_4C9F_AC7A_FCDA8CB1DD37__INCLUDED_)
|
data/ext/rqr/qr.i
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
%module QR
|
2
|
+
%{
|
3
|
+
#include "win2ansi.h"
|
4
|
+
#include "QR_Encode.h"
|
5
|
+
#include "qr_draw.h"
|
6
|
+
#include "qr_draw_jpeg.h"
|
7
|
+
#include "qr_draw_png.h"
|
8
|
+
#include "qr_draw_ps.h"
|
9
|
+
#include "qr_draw_tiff.h"
|
10
|
+
%}
|
11
|
+
%include win2ansi.h
|
12
|
+
%include qr_draw.h
|
13
|
+
%include qr_draw_jpeg.h
|
14
|
+
%include qr_draw_png.h
|
15
|
+
%include qr_draw_ps.h
|
16
|
+
%include qr_draw_tiff.h
|
17
|
+
%include QR_Encode.h
|
data/ext/rqr/qr_draw.h
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
#ifndef _QR_DRAW_
|
2
|
+
#define _QR_DRAW_
|
3
|
+
|
4
|
+
#define MARGIN_SIZE 4 /* �}�[�W���T�C�Y */
|
5
|
+
#define MAX_MODULESIZE 177 /* �f�[�^�o�C�g��̗̈�T�C�Y */
|
6
|
+
|
7
|
+
//=============================================================================
|
8
|
+
// QRDraw �N���X
|
9
|
+
//=============================================================================
|
10
|
+
class QRDraw
|
11
|
+
{
|
12
|
+
public:
|
13
|
+
QRDraw(){
|
14
|
+
this->bit_image=NULL;
|
15
|
+
}
|
16
|
+
|
17
|
+
virtual ~QRDraw(){
|
18
|
+
this->close();
|
19
|
+
}
|
20
|
+
|
21
|
+
void setup(char *filename, int modulesize, int symbolsize){
|
22
|
+
this->msize = modulesize;
|
23
|
+
this->ssize = symbolsize;
|
24
|
+
this->rsize = (this->ssize + MARGIN_SIZE * 2) * this->msize;
|
25
|
+
this->filename = filename;
|
26
|
+
}
|
27
|
+
|
28
|
+
protected:
|
29
|
+
unsigned char **bit_image; //�s�N�Z���C���[�W���i�[����
|
30
|
+
int msize; // 1�h�b�g��\������s�N�Z����(=modulesize)
|
31
|
+
int rsize; // �}�[�W�����܂߂����ۂ̃C���[�W�̈��
|
32
|
+
int ssize; // �V���{���T�C�Y(�}�[�W�����܂߂Ȃ��A�h�b�g�̌�)
|
33
|
+
char *filename; // �ۑ�����t�@�C����
|
34
|
+
|
35
|
+
public:
|
36
|
+
virtual int draw(char *filename, int modulesize, int symbolsize,
|
37
|
+
unsigned char data[MAX_MODULESIZE][MAX_MODULESIZE], void *opt) = 0;
|
38
|
+
void close(){
|
39
|
+
int i;
|
40
|
+
if(this->bit_image){
|
41
|
+
for(i=0; i<this->rsize; i++) free(this->bit_image[i]);
|
42
|
+
free(this->bit_image);
|
43
|
+
}
|
44
|
+
this->bit_image=NULL;
|
45
|
+
}
|
46
|
+
};
|
47
|
+
|
48
|
+
#endif
|
@@ -0,0 +1,104 @@
|
|
1
|
+
#include "qr_draw_jpeg.h"
|
2
|
+
|
3
|
+
//=============================================================================
|
4
|
+
// QRDrawJPEG::draw
|
5
|
+
//=============================================================================
|
6
|
+
int QRDrawJPEG::draw(char *filename, int modulesize, int symbolsize,
|
7
|
+
unsigned char data[MAX_MODULESIZE][MAX_MODULESIZE], void *opt)
|
8
|
+
{
|
9
|
+
#ifdef USE_JPG
|
10
|
+
setup(filename, modulesize, symbolsize);
|
11
|
+
|
12
|
+
/* �O���[�X�P�[���C���[�W�̍\�z */
|
13
|
+
if( this->raster(data) ) return(1);
|
14
|
+
|
15
|
+
/* JPEG�����o�� */
|
16
|
+
if( this->write() ) return(1);
|
17
|
+
|
18
|
+
return(0);
|
19
|
+
#else
|
20
|
+
return(1);
|
21
|
+
#endif
|
22
|
+
}
|
23
|
+
|
24
|
+
//=================================================================================
|
25
|
+
// QRDrawJPEG::raster
|
26
|
+
//=================================================================================
|
27
|
+
int QRDrawJPEG::raster(unsigned char data[MAX_MODULESIZE][MAX_MODULESIZE])
|
28
|
+
{
|
29
|
+
#ifdef USE_JPG
|
30
|
+
int i, j, k;
|
31
|
+
|
32
|
+
/* ���ۂɃf�[�^��u���̈���m�� */
|
33
|
+
bit_image = (unsigned char **)malloc(sizeof(unsigned char *) * this->rsize);
|
34
|
+
for(i=0; i<this->rsize; i++){
|
35
|
+
bit_image[i] = (unsigned char *)malloc(this->rsize);
|
36
|
+
memset(bit_image[i], 0xFF, this->rsize);
|
37
|
+
}
|
38
|
+
|
39
|
+
for(i=0; i<this->ssize; i++){
|
40
|
+
for(j=0; j<this->ssize; j++){
|
41
|
+
/* 1�s������ */
|
42
|
+
for(k=0; k<this->msize; k++){
|
43
|
+
bit_image[(i+MARGIN_SIZE)*this->msize][ (j+MARGIN_SIZE)*this->msize + k ] = data[j][i] ? 0 : 255;
|
44
|
+
}
|
45
|
+
}
|
46
|
+
/* ���W���[���T�C�Y���c�����ɑ��₷ */
|
47
|
+
for(k=1; k<this->msize; k++){
|
48
|
+
memcpy(bit_image[(i+MARGIN_SIZE)*this->msize+k], bit_image[(i+MARGIN_SIZE)*this->msize], this->rsize);
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
return(0);
|
53
|
+
#else
|
54
|
+
return(1);
|
55
|
+
#endif
|
56
|
+
}
|
57
|
+
|
58
|
+
//=================================================================================
|
59
|
+
// QRDrawJPEG::write
|
60
|
+
//=================================================================================
|
61
|
+
int QRDrawJPEG::write()
|
62
|
+
{
|
63
|
+
#ifdef USE_JPG
|
64
|
+
struct jpeg_compress_struct oinfo;
|
65
|
+
struct jpeg_error_mgr jerr;
|
66
|
+
JSAMPROW row_pointer[1];
|
67
|
+
FILE *stream;
|
68
|
+
int i;
|
69
|
+
|
70
|
+
/* �o�͐�ݒ� */
|
71
|
+
if(!this->filename){
|
72
|
+
stream = stdout;
|
73
|
+
}else{
|
74
|
+
if( (stream=fopen(this->filename, "wb")) == NULL ) return(1);
|
75
|
+
}
|
76
|
+
|
77
|
+
oinfo.err = jpeg_std_error(&jerr);
|
78
|
+
jpeg_create_compress(&oinfo);
|
79
|
+
jpeg_stdio_dest(&oinfo, stream);
|
80
|
+
|
81
|
+
oinfo.image_width = this->rsize;
|
82
|
+
oinfo.image_height = this->rsize;
|
83
|
+
oinfo.in_color_space = JCS_GRAYSCALE;
|
84
|
+
oinfo.input_components = 1;
|
85
|
+
jpeg_set_defaults(&oinfo);
|
86
|
+
jpeg_set_quality(&oinfo, 100, TRUE);
|
87
|
+
oinfo.dct_method = JDCT_ISLOW;
|
88
|
+
oinfo.write_JFIF_header = TRUE;
|
89
|
+
|
90
|
+
jpeg_start_compress(&oinfo, TRUE);
|
91
|
+
for(i=0; i<this->rsize; i++){
|
92
|
+
row_pointer[0] = bit_image[i];
|
93
|
+
jpeg_write_scanlines(&oinfo, row_pointer, 1);
|
94
|
+
}
|
95
|
+
|
96
|
+
jpeg_finish_compress(&oinfo);
|
97
|
+
jpeg_destroy_compress(&oinfo);
|
98
|
+
|
99
|
+
fclose(stream);
|
100
|
+
return(0);
|
101
|
+
#else
|
102
|
+
return(1);
|
103
|
+
#endif
|
104
|
+
}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#ifndef _QR_DRAW_JPEG_
|
2
|
+
#define _QR_DRAW_JPEG_
|
3
|
+
|
4
|
+
#include <stdlib.h>
|
5
|
+
#include <stdio.h>
|
6
|
+
#include <string.h>
|
7
|
+
#include "qr_draw.h"
|
8
|
+
|
9
|
+
#ifdef USE_JPG
|
10
|
+
#include <jpeglib.h>
|
11
|
+
#endif
|
12
|
+
|
13
|
+
//=============================================================================
|
14
|
+
// QRDrawJPEG �N���X
|
15
|
+
//=============================================================================
|
16
|
+
class QRDrawJPEG : public QRDraw
|
17
|
+
{
|
18
|
+
private:
|
19
|
+
int raster(unsigned char data[MAX_MODULESIZE][MAX_MODULESIZE]);
|
20
|
+
int write();
|
21
|
+
|
22
|
+
public:
|
23
|
+
QRDrawJPEG(){}
|
24
|
+
~QRDrawJPEG(){}
|
25
|
+
int draw(char *filename, int modulesize, int symbolsize,
|
26
|
+
unsigned char data[MAX_MODULESIZE][MAX_MODULESIZE], void *opt);
|
27
|
+
};
|
28
|
+
|
29
|
+
#endif
|
@@ -0,0 +1,119 @@
|
|
1
|
+
#include "qr_draw_png.h"
|
2
|
+
|
3
|
+
//=============================================================================
|
4
|
+
// QRDrawPNG::draw
|
5
|
+
//=============================================================================
|
6
|
+
int QRDrawPNG::draw(char *filename, int modulesize, int symbolsize,
|
7
|
+
unsigned char data[MAX_MODULESIZE][MAX_MODULESIZE], void *opt)
|
8
|
+
{
|
9
|
+
#ifdef USE_PNG
|
10
|
+
setup(filename, modulesize, symbolsize);
|
11
|
+
|
12
|
+
/* �j�l�C���[�W�̍\�z */
|
13
|
+
if( this->raster(data) ) return(1);
|
14
|
+
|
15
|
+
/* PNG�����o�� */
|
16
|
+
if( this->write() ) return(1);
|
17
|
+
|
18
|
+
return(0);
|
19
|
+
#else
|
20
|
+
return(1);
|
21
|
+
#endif
|
22
|
+
}
|
23
|
+
|
24
|
+
//=================================================================================
|
25
|
+
// QRDrawPNG::create_image
|
26
|
+
//=================================================================================
|
27
|
+
int QRDrawPNG::raster(unsigned char data[MAX_MODULESIZE][MAX_MODULESIZE])
|
28
|
+
{
|
29
|
+
#ifdef USE_PNG
|
30
|
+
int bitw = (int)ceil(this->rsize/8) + 1;
|
31
|
+
|
32
|
+
/* ���ۂɃf�[�^��u���̈���m�� */
|
33
|
+
bit_image = (unsigned char **)malloc(sizeof(unsigned char *) * this->rsize);
|
34
|
+
for(int i=0; i<this->rsize; i++){
|
35
|
+
bit_image[i] = (unsigned char *)malloc(bitw);
|
36
|
+
memset(bit_image[i], 0, bitw);
|
37
|
+
}
|
38
|
+
|
39
|
+
for(int i=0; i<this->ssize; i++){
|
40
|
+
int dp = MARGIN_SIZE*this->msize / 8; //�������̃o�C�g�ʒu
|
41
|
+
int sht =(MARGIN_SIZE*this->msize % 8) ? 3 : 7; //�r�b�g�V�t�g
|
42
|
+
unsigned char c = 0; //1�o�C�g�̍\����ۑ�
|
43
|
+
|
44
|
+
for(int j=0; j<this->ssize; j++){
|
45
|
+
/* 1�s������ */
|
46
|
+
for(int k=0; k<this->msize; k++){
|
47
|
+
c += (data[j][i] << sht);
|
48
|
+
sht--;
|
49
|
+
|
50
|
+
bit_image[(i+MARGIN_SIZE)*this->msize][ dp ] = c;
|
51
|
+
|
52
|
+
if(sht < 0){
|
53
|
+
sht = 7;
|
54
|
+
c = 0;
|
55
|
+
dp++;
|
56
|
+
}
|
57
|
+
}
|
58
|
+
}
|
59
|
+
/* ���W���[���T�C�Y���c�����ɑ��₷ */
|
60
|
+
for(int k=1; k<this->msize; k++){
|
61
|
+
memcpy(bit_image[(i+MARGIN_SIZE)*this->msize+k], bit_image[(i+MARGIN_SIZE)*this->msize], bitw);
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
return(0);
|
66
|
+
#else
|
67
|
+
return(1);
|
68
|
+
#endif
|
69
|
+
}
|
70
|
+
|
71
|
+
//=================================================================================
|
72
|
+
// QRDrawPNG::write
|
73
|
+
//=================================================================================
|
74
|
+
int QRDrawPNG::write()
|
75
|
+
{
|
76
|
+
#ifdef USE_PNG
|
77
|
+
png_structp png_ptr;
|
78
|
+
png_infop info_ptr;
|
79
|
+
FILE *stream;
|
80
|
+
|
81
|
+
/* �o�͐�ݒ� */
|
82
|
+
if(!this->filename){
|
83
|
+
stream = stdout;
|
84
|
+
}else{
|
85
|
+
if( (stream=fopen(this->filename, "wb")) == NULL ) return(1);
|
86
|
+
}
|
87
|
+
|
88
|
+
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
89
|
+
info_ptr = png_create_info_struct(png_ptr);
|
90
|
+
|
91
|
+
png_init_io(png_ptr, stream);
|
92
|
+
png_set_filter(png_ptr, 0, PNG_ALL_FILTERS);
|
93
|
+
png_set_compression_level(png_ptr, Z_BEST_COMPRESSION);
|
94
|
+
png_set_invert_mono(png_ptr); //�������]
|
95
|
+
|
96
|
+
/* IHDR�`�����N����ݒ� */
|
97
|
+
png_set_IHDR(png_ptr, //png_structp
|
98
|
+
info_ptr, //png_infop
|
99
|
+
this->rsize, //width
|
100
|
+
this->rsize, //height
|
101
|
+
1, //bit_depth(�j�l)
|
102
|
+
PNG_COLOR_TYPE_GRAY, //Color�^�C�v(�j�l)
|
103
|
+
PNG_INTERLACE_NONE, //interlace_method
|
104
|
+
PNG_COMPRESSION_TYPE_DEFAULT, //compression_method
|
105
|
+
PNG_FILTER_TYPE_DEFAULT); //filter_method
|
106
|
+
|
107
|
+
png_write_info(png_ptr, info_ptr);
|
108
|
+
png_write_image(png_ptr, bit_image);
|
109
|
+
png_write_end(png_ptr, info_ptr);
|
110
|
+
|
111
|
+
png_destroy_info_struct(png_ptr, &info_ptr);
|
112
|
+
png_destroy_write_struct(&png_ptr, &info_ptr);
|
113
|
+
|
114
|
+
fclose(stream);
|
115
|
+
return(0);
|
116
|
+
#else
|
117
|
+
return(1);
|
118
|
+
#endif
|
119
|
+
}
|