pikl 0.2.2-x86-mswin32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +8 -0
- data/License.txt +21 -0
- data/Manifest.txt +37 -0
- data/README.txt +66 -0
- data/Rakefile +4 -0
- data/config/hoe.rb +89 -0
- data/config/requirements.rb +15 -0
- data/ext/pikl/pikl.h +264 -0
- data/ext/pikl/pikl_bitmap.c +152 -0
- data/ext/pikl/pikl_bitmap.h +18 -0
- data/ext/pikl/pikl_effect.c +191 -0
- data/ext/pikl/pikl_effect.h +20 -0
- data/ext/pikl/pikl_io.c +137 -0
- data/ext/pikl/pikl_io.h +27 -0
- data/ext/pikl/pikl_jpeg.c +161 -0
- data/ext/pikl/pikl_jpeg.h +22 -0
- data/ext/pikl/pikl_png.c +188 -0
- data/ext/pikl/pikl_png.h +17 -0
- data/ext/pikl/pikl_private.h +24 -0
- data/ext/pikl/pikl_resize.c +338 -0
- data/ext/pikl/pikl_resize.h +12 -0
- data/ext/pikl/pikl_rotate.c +70 -0
- data/ext/pikl/pikl_rotate.h +12 -0
- data/ext/pikl/pikl_trim.c +28 -0
- data/ext/pikl/pikl_trim.h +11 -0
- data/lib/pikl/const.rb +54 -0
- data/lib/pikl/errors.rb +7 -0
- data/lib/pikl/ext.rb +35 -0
- data/lib/pikl/image.rb +230 -0
- data/lib/pikl/pikl.dll +0 -0
- data/lib/pikl/version.rb +9 -0
- data/lib/pikl.rb +14 -0
- data/setup.rb +1585 -0
- data/test/sample.jpg +0 -0
- data/test/test_helper.rb +2 -0
- data/test/test_pikl_image.rb +268 -0
- metadata +95 -0
@@ -0,0 +1,191 @@
|
|
1
|
+
#include "pikl_effect.h"
|
2
|
+
|
3
|
+
//=================================================================================
|
4
|
+
// pkl_unsharp
|
5
|
+
//=================================================================================
|
6
|
+
PKLExport int pkl_unsharp(PKLImage pkl, int threshold, double edge)
|
7
|
+
{
|
8
|
+
int i, j, p, q, k;
|
9
|
+
int cnt, value, stock[PKL_CHANNEL];
|
10
|
+
unsigned char *wrk;
|
11
|
+
|
12
|
+
wrk = malloc(pkl->height * pkl->width * pkl->channel);
|
13
|
+
if(!wrk) return(1);
|
14
|
+
memset(wrk, 0, pkl->height * pkl->width * pkl->channel);
|
15
|
+
|
16
|
+
for(i=0; i<pkl->height; i++){
|
17
|
+
for(j=0; j<pkl->width; j++){
|
18
|
+
cnt = 0;
|
19
|
+
memset(stock, 0, sizeof(stock));
|
20
|
+
|
21
|
+
for(p=-RADIUS; p<=RADIUS; p++){
|
22
|
+
for(q=-RADIUS; q<=RADIUS; q++){
|
23
|
+
if(j+q>=0 && j+q<pkl->width && i+p>=0 && i+p<pkl->height){
|
24
|
+
for(k=0; k<pkl->channel; k++) stock[k] += pkl->image[((i+p)*pkl->width+(j+q))*pkl->channel+k];
|
25
|
+
cnt++;
|
26
|
+
}
|
27
|
+
}
|
28
|
+
}
|
29
|
+
for(k=0; k<pkl->channel; k++){
|
30
|
+
wrk[(i * pkl->width + j) * pkl->channel+k] = stock[k] / cnt;
|
31
|
+
}
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
for(i=0; i<pkl->height*pkl->width*pkl->channel; i++){
|
36
|
+
value = abs(pkl->image[i]-wrk[i])<threshold ? pkl->image[i] : pkl->image[i]+(pkl->image[i]-wrk[i])*edge;
|
37
|
+
pkl->image[i] = PKL_RGB(value);
|
38
|
+
}
|
39
|
+
free(wrk);
|
40
|
+
return(0);
|
41
|
+
}
|
42
|
+
|
43
|
+
//=================================================================================
|
44
|
+
// pkl_contrast
|
45
|
+
//=================================================================================
|
46
|
+
PKLExport int pkl_contrast(PKLImage pkl, int rate)
|
47
|
+
{
|
48
|
+
unsigned char ct[PKL_COLOR];
|
49
|
+
int value, i;
|
50
|
+
|
51
|
+
if(rate < -127 || rate > 127) return(1);
|
52
|
+
|
53
|
+
if(rate < 0.0){
|
54
|
+
//�d�݂������̎��͒����I�ɕ��R��
|
55
|
+
for(i=0; i<PKL_COLOR; i++){
|
56
|
+
value = i + (i-127) * rate/127;
|
57
|
+
ct[i] = PKL_RGB(value);
|
58
|
+
}
|
59
|
+
}else{
|
60
|
+
//�d�݂������̎��͎��g��
|
61
|
+
for(i=0; i<PKL_COLOR; i++){
|
62
|
+
value = i - rate*rate/127 * sin(M_PI/2+M_PI*i/255);
|
63
|
+
ct[i] = PKL_RGB(value);
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
for(i=0; i<pkl->width*pkl->height*pkl->channel; i++) pkl->image[i] = ct[pkl->image[i]];
|
68
|
+
|
69
|
+
return(0);
|
70
|
+
}
|
71
|
+
|
72
|
+
//=================================================================================
|
73
|
+
// pkl_level def=0.0050
|
74
|
+
//=================================================================================
|
75
|
+
PKLExport int pkl_level(PKLImage pkl, double low, double high, double coeff)
|
76
|
+
{
|
77
|
+
PKL_HISTGRAM hst[PKL_CHANNEL];
|
78
|
+
int i, j, cnt, value;
|
79
|
+
|
80
|
+
if((low < 0.0 && low > 100.0) ||
|
81
|
+
(high < 0.0 && high > 100.0) ||
|
82
|
+
(coeff< 0.0 && coeff> 2.0)) return(1);
|
83
|
+
|
84
|
+
memset(&hst, 0, sizeof(hst));
|
85
|
+
for(i=0; i<pkl->height*pkl->width; i++){
|
86
|
+
for(j=0; j<pkl->channel; j++){
|
87
|
+
hst[j].data[ pkl->image[i*pkl->channel+j] ]++;
|
88
|
+
}
|
89
|
+
}
|
90
|
+
|
91
|
+
for(i=0; i<pkl->channel; i++){
|
92
|
+
cnt=0;
|
93
|
+
for(j=0; j<PKL_COLOR; j++){
|
94
|
+
cnt += hst[i].data[j];
|
95
|
+
if(cnt > low/100*pkl->height*pkl->width){
|
96
|
+
hst[i].min = j;
|
97
|
+
break;
|
98
|
+
}
|
99
|
+
}
|
100
|
+
cnt=0;
|
101
|
+
for(j=PKL_COLOR-1; j>=0; j--){
|
102
|
+
cnt += hst[i].data[j];
|
103
|
+
if(cnt > high/100*pkl->height*pkl->width){
|
104
|
+
hst[i].max = j;
|
105
|
+
break;
|
106
|
+
}
|
107
|
+
}
|
108
|
+
}
|
109
|
+
|
110
|
+
for(i=0; i<pkl->width*pkl->height; i++){
|
111
|
+
for(j=0; j<pkl->channel; j++){
|
112
|
+
value = ((coeff * pkl->image[i*pkl->channel+j])-hst[j].min)/(hst[j].max-hst[j].min) * 255;
|
113
|
+
pkl->image[i*pkl->channel+j] = PKL_RGB(value);
|
114
|
+
}
|
115
|
+
}
|
116
|
+
|
117
|
+
return(0);
|
118
|
+
}
|
119
|
+
|
120
|
+
//=============================================================================
|
121
|
+
// pkl_brightness
|
122
|
+
//=============================================================================
|
123
|
+
PKLExport int pkl_brightness(PKLImage pkl, int color)
|
124
|
+
{
|
125
|
+
int i;
|
126
|
+
for(i=0; i<pkl->width*pkl->height*pkl->channel; i++){
|
127
|
+
pkl->image[i] = PKL_RGB(pkl->image[i] + color);
|
128
|
+
}
|
129
|
+
return(0);
|
130
|
+
}
|
131
|
+
|
132
|
+
//=============================================================================
|
133
|
+
// pkl_hls
|
134
|
+
//=============================================================================
|
135
|
+
PKLExport int pkl_hls(PKLImage pkl, double ym, double sm, double hd)
|
136
|
+
{
|
137
|
+
int i;
|
138
|
+
double c1, c2; //�F�M��
|
139
|
+
double y, s, h; //y=�P�x, s=�ʓx, h=�F��
|
140
|
+
|
141
|
+
if(pkl->color != PKL_RGB) return(1);
|
142
|
+
|
143
|
+
for(i=0; i<pkl->width*pkl->height; i++){
|
144
|
+
/* �P�x,�F�M��1,2 */
|
145
|
+
y = 0.299 * pkl->image[i*pkl->channel] +
|
146
|
+
0.587 * pkl->image[i*pkl->channel+1] +
|
147
|
+
0.114 * pkl->image[i*pkl->channel+2];
|
148
|
+
c1 = pkl->image[i*pkl->channel] - y;
|
149
|
+
c2 = pkl->image[i*pkl->channel+2] - y;
|
150
|
+
|
151
|
+
/* �ʓx */
|
152
|
+
s = sqrt(c1*c1 + c2*c2);
|
153
|
+
|
154
|
+
/* �F�� */
|
155
|
+
if(s < 0.0) h = 0.0;
|
156
|
+
else h = atan2(c1, c2) * 180.0 / M_PI;
|
157
|
+
|
158
|
+
/* ������������ */
|
159
|
+
y *= (1 + ym);
|
160
|
+
s *= (1 + sm);
|
161
|
+
h += hd;
|
162
|
+
|
163
|
+
/* �����l����RGB�ɖ߂� */
|
164
|
+
c1 = s * sin(M_PI * h / 180.0);
|
165
|
+
c2 = s * cos(M_PI * h / 180.0);
|
166
|
+
|
167
|
+
pkl->image[i*pkl->channel] = PKL_RGB(c1 + y);
|
168
|
+
pkl->image[i*pkl->channel+1] = PKL_RGB(y - (0.299*c1 + 0.114*c2)/0.587);
|
169
|
+
pkl->image[i*pkl->channel+2] = PKL_RGB(c2 + y);
|
170
|
+
}
|
171
|
+
return(0);
|
172
|
+
}
|
173
|
+
|
174
|
+
//=================================================================================
|
175
|
+
// pkl_gamma
|
176
|
+
//=================================================================================
|
177
|
+
PKLExport int pkl_gamma(PKLImage pkl, double gm)
|
178
|
+
{
|
179
|
+
unsigned char gt[PKL_COLOR];
|
180
|
+
int i;
|
181
|
+
|
182
|
+
if(gm < 0.0) return(1);
|
183
|
+
|
184
|
+
for(i=0; i<PKL_COLOR; i++)
|
185
|
+
gt[i] = PKL_RGB(255.0 * pow(i/255.0, 1.0/gm));
|
186
|
+
|
187
|
+
for(i=0; i<pkl->width*pkl->height*pkl->channel; i++)
|
188
|
+
pkl->image[i] = gt[pkl->image[i]];
|
189
|
+
|
190
|
+
return(0);
|
191
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#ifndef _LIB_PIKL_EFFECT_
|
2
|
+
#define _LIB_PIKL_EFFECT_
|
3
|
+
|
4
|
+
#include <stdio.h>
|
5
|
+
#include <stdlib.h>
|
6
|
+
#include <string.h>
|
7
|
+
#include <math.h>
|
8
|
+
|
9
|
+
#include "pikl.h"
|
10
|
+
#include "pikl_private.h"
|
11
|
+
|
12
|
+
//unsharp target pixel
|
13
|
+
#define RADIUS 1
|
14
|
+
|
15
|
+
typedef struct {
|
16
|
+
int max, min;
|
17
|
+
long data[PKL_COLOR];
|
18
|
+
} PKL_HISTGRAM;
|
19
|
+
|
20
|
+
#endif
|
data/ext/pikl/pikl_io.c
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
#include "pikl_io.h"
|
2
|
+
|
3
|
+
static int format_type(PKLImage pkl, FILE *image);
|
4
|
+
//=============================================================================
|
5
|
+
// pkl_open
|
6
|
+
//=============================================================================
|
7
|
+
PKLExport PKLImage pkl_open(const char *in)
|
8
|
+
{
|
9
|
+
PKLImage pkl;
|
10
|
+
FILE *image;
|
11
|
+
int result=0;
|
12
|
+
|
13
|
+
pkl = malloc( sizeof(struct _PKLImage) );
|
14
|
+
if(!pkl) return(NULL);
|
15
|
+
memset(pkl, 0, sizeof(struct _PKLImage));
|
16
|
+
|
17
|
+
pkl->compress = -1;
|
18
|
+
|
19
|
+
image = fopen(in, "rb");
|
20
|
+
if(!image) return(NULL);
|
21
|
+
|
22
|
+
format_type(pkl, image);
|
23
|
+
|
24
|
+
switch(pkl->format){
|
25
|
+
case PKL_FORMAT_JPEG:
|
26
|
+
result = load_jpeg(pkl, image);
|
27
|
+
break;
|
28
|
+
case PKL_FORMAT_PNG:
|
29
|
+
result = load_png(pkl, image);
|
30
|
+
break;
|
31
|
+
case PKL_FORMAT_BITMAP:
|
32
|
+
result = load_bitmap(pkl, image);
|
33
|
+
break;
|
34
|
+
default:
|
35
|
+
result = 1;
|
36
|
+
}
|
37
|
+
fclose(image);
|
38
|
+
|
39
|
+
if(result){
|
40
|
+
free(pkl);
|
41
|
+
pkl = NULL;
|
42
|
+
}
|
43
|
+
|
44
|
+
return(pkl);
|
45
|
+
}
|
46
|
+
|
47
|
+
//=============================================================================
|
48
|
+
// pkl_close
|
49
|
+
//=============================================================================
|
50
|
+
PKLExport void pkl_close(PKLImage pkl)
|
51
|
+
{
|
52
|
+
if(pkl->image) free(pkl->image);
|
53
|
+
free(pkl);
|
54
|
+
}
|
55
|
+
|
56
|
+
//=============================================================================
|
57
|
+
// format_type
|
58
|
+
//=============================================================================
|
59
|
+
static int format_type(PKLImage pkl, FILE *image)
|
60
|
+
{
|
61
|
+
unsigned char mark[PKL_HEADER_SIZE];
|
62
|
+
int count, i;
|
63
|
+
|
64
|
+
if( fread(mark, 1, PKL_HEADER_SIZE, image) < PKL_HEADER_SIZE ) return(1);
|
65
|
+
|
66
|
+
count = sizeof(pklheader) /sizeof(struct PKL_HEADER);
|
67
|
+
for(i=0; i<count; i++){
|
68
|
+
if( !memcmp(mark, pklheader[i].mark, pklheader[i].size) ){
|
69
|
+
pkl->format = pklheader[i].format;
|
70
|
+
fseek(image, 0, SEEK_SET);
|
71
|
+
return(0);
|
72
|
+
}
|
73
|
+
}
|
74
|
+
return(1);
|
75
|
+
}
|
76
|
+
|
77
|
+
//=============================================================================
|
78
|
+
// pkl_format
|
79
|
+
//=============================================================================
|
80
|
+
PKLExport PKL_FORMAT pkl_format(PKLImage pkl)
|
81
|
+
{
|
82
|
+
return(pkl->format);
|
83
|
+
}
|
84
|
+
|
85
|
+
//=================================================================================
|
86
|
+
// pkl_width
|
87
|
+
//=================================================================================
|
88
|
+
PKLExport int pkl_width(PKLImage pkl)
|
89
|
+
{
|
90
|
+
return(pkl->width);
|
91
|
+
}
|
92
|
+
|
93
|
+
//=================================================================================
|
94
|
+
// pkl_height
|
95
|
+
//=================================================================================
|
96
|
+
PKLExport int pkl_height(PKLImage pkl)
|
97
|
+
{
|
98
|
+
return(pkl->height);
|
99
|
+
}
|
100
|
+
|
101
|
+
//=============================================================================
|
102
|
+
// pkl_compress
|
103
|
+
//=============================================================================
|
104
|
+
PKLExport int pkl_compress(PKLImage pkl, int level)
|
105
|
+
{
|
106
|
+
if(level < 0 || level > 10) return(pkl->compress);
|
107
|
+
pkl->compress = level;
|
108
|
+
return(pkl->compress);
|
109
|
+
}
|
110
|
+
|
111
|
+
//=================================================================================
|
112
|
+
// pkl_save
|
113
|
+
//=================================================================================
|
114
|
+
PKLExport int pkl_save(PKLImage pkl, const char *out, PKL_FORMAT format)
|
115
|
+
{
|
116
|
+
FILE *image;
|
117
|
+
int result=0;
|
118
|
+
|
119
|
+
image = fopen(out, "wb");
|
120
|
+
if(!image) return(1);
|
121
|
+
|
122
|
+
switch(format){
|
123
|
+
case PKL_FORMAT_JPEG:
|
124
|
+
result = save_jpeg(pkl, image);
|
125
|
+
break;
|
126
|
+
case PKL_FORMAT_PNG:
|
127
|
+
result = save_png(pkl, image);
|
128
|
+
break;
|
129
|
+
case PKL_FORMAT_BITMAP:
|
130
|
+
result = save_bitmap(pkl, image);
|
131
|
+
break;
|
132
|
+
default:
|
133
|
+
result=1;
|
134
|
+
}
|
135
|
+
fclose(image);
|
136
|
+
return(result);
|
137
|
+
}
|
data/ext/pikl/pikl_io.h
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#ifndef _LIB_PIKL_IO_
|
2
|
+
#define _LIB_PIKL_IO_
|
3
|
+
|
4
|
+
#include <stdio.h>
|
5
|
+
#include <stdlib.h>
|
6
|
+
#include <string.h>
|
7
|
+
|
8
|
+
#include "pikl.h"
|
9
|
+
#include "pikl_private.h"
|
10
|
+
#include "pikl_jpeg.h"
|
11
|
+
#include "pikl_bitmap.h"
|
12
|
+
#include "pikl_png.h"
|
13
|
+
|
14
|
+
#define PKL_HEADER_SIZE 8
|
15
|
+
struct PKL_HEADER {
|
16
|
+
PKL_FORMAT format;
|
17
|
+
int size;
|
18
|
+
unsigned char mark[PKL_HEADER_SIZE];
|
19
|
+
};
|
20
|
+
|
21
|
+
static struct PKL_HEADER pklheader[] = {
|
22
|
+
{ PKL_FORMAT_JPEG, 2, {0xFF, 0xD8} },
|
23
|
+
{ PKL_FORMAT_PNG, 8, {0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A} },
|
24
|
+
{ PKL_FORMAT_BITMAP, 2, {0x42, 0x4D} },
|
25
|
+
};
|
26
|
+
|
27
|
+
#endif
|
@@ -0,0 +1,161 @@
|
|
1
|
+
#include "pikl_jpeg.h"
|
2
|
+
|
3
|
+
static void pkljpeg_error_exit(j_common_ptr cinfo);
|
4
|
+
static int color_p2j(int color);
|
5
|
+
static int color_j2p(int color);
|
6
|
+
static int compress_p2j(int level);
|
7
|
+
|
8
|
+
//=============================================================================
|
9
|
+
// pkljpeg_error_exit
|
10
|
+
//=============================================================================
|
11
|
+
static void pkljpeg_error_exit(j_common_ptr cinfo)
|
12
|
+
{
|
13
|
+
struct err_mgr *jp_err = (struct err_mgr *)cinfo->err;
|
14
|
+
longjmp(jp_err->setjmp_buffer, 1);
|
15
|
+
}
|
16
|
+
|
17
|
+
//=============================================================================
|
18
|
+
// load_jpeg
|
19
|
+
//=============================================================================
|
20
|
+
int load_jpeg(PKLImage pkl, FILE *image)
|
21
|
+
{
|
22
|
+
struct jpeg_decompress_struct cinfo;
|
23
|
+
struct err_mgr jerr;
|
24
|
+
unsigned char *p;
|
25
|
+
|
26
|
+
cinfo.err = jpeg_std_error(&jerr.pub);
|
27
|
+
jerr.pub.error_exit = pkljpeg_error_exit;
|
28
|
+
|
29
|
+
if( setjmp(jerr.setjmp_buffer) ){
|
30
|
+
jpeg_destroy_decompress(&cinfo);
|
31
|
+
return(1);
|
32
|
+
}
|
33
|
+
|
34
|
+
jpeg_create_decompress(&cinfo);
|
35
|
+
jpeg_stdio_src(&cinfo, image);
|
36
|
+
jpeg_read_header(&cinfo, TRUE);
|
37
|
+
jpeg_start_decompress(&cinfo);
|
38
|
+
|
39
|
+
pkl->width = cinfo.output_width;
|
40
|
+
pkl->height = cinfo.output_height;
|
41
|
+
pkl->color = color_j2p(cinfo.out_color_space);
|
42
|
+
pkl->channel = cinfo.output_components;
|
43
|
+
if(pkl->color == PKL_UNKNOWN) return(1);
|
44
|
+
|
45
|
+
pkl->image = malloc(cinfo.output_height * cinfo.output_width * cinfo.output_components);
|
46
|
+
if(!pkl->image) return(1);
|
47
|
+
|
48
|
+
p = pkl->image;
|
49
|
+
while(cinfo.output_scanline < cinfo.output_height){
|
50
|
+
jpeg_read_scanlines(&cinfo, &p, 1);
|
51
|
+
p += (cinfo.output_width * cinfo.output_components);
|
52
|
+
}
|
53
|
+
jpeg_finish_decompress(&cinfo);
|
54
|
+
jpeg_destroy_decompress(&cinfo);
|
55
|
+
|
56
|
+
return(0);
|
57
|
+
}
|
58
|
+
|
59
|
+
//=============================================================================
|
60
|
+
// save_jpg
|
61
|
+
//=============================================================================
|
62
|
+
int save_jpeg(PKLImage pkl, FILE *image)
|
63
|
+
{
|
64
|
+
struct jpeg_compress_struct oinfo;
|
65
|
+
struct err_mgr jerr;
|
66
|
+
JSAMPROW row_pointer[1];
|
67
|
+
int i;
|
68
|
+
|
69
|
+
if(pkl->color == PKL_UNKNOWN) return(1);
|
70
|
+
|
71
|
+
oinfo.err = jpeg_std_error(&jerr.pub);
|
72
|
+
jerr.pub.error_exit = pkljpeg_error_exit;
|
73
|
+
|
74
|
+
if( setjmp(jerr.setjmp_buffer) ){
|
75
|
+
jpeg_destroy_compress(&oinfo);
|
76
|
+
return(1);
|
77
|
+
}
|
78
|
+
|
79
|
+
jpeg_create_compress(&oinfo);
|
80
|
+
jpeg_stdio_dest(&oinfo, image);
|
81
|
+
|
82
|
+
oinfo.image_width = pkl->width;
|
83
|
+
oinfo.image_height = pkl->height;
|
84
|
+
oinfo.in_color_space = color_p2j(pkl->color);
|
85
|
+
oinfo.input_components = pkl->channel;
|
86
|
+
jpeg_set_defaults(&oinfo);
|
87
|
+
jpeg_set_quality(&oinfo, compress_p2j(pkl->compress), TRUE);
|
88
|
+
oinfo.write_JFIF_header= TRUE;
|
89
|
+
oinfo.density_unit = 1; //(1)dots/inch, (2)dots/cm
|
90
|
+
|
91
|
+
jpeg_start_compress(&oinfo, TRUE);
|
92
|
+
|
93
|
+
for(i=0; i<pkl->height ; i++){
|
94
|
+
row_pointer[0] = &pkl->image[i*pkl->width*pkl->channel];
|
95
|
+
jpeg_write_scanlines(&oinfo, row_pointer, 1);
|
96
|
+
}
|
97
|
+
|
98
|
+
jpeg_finish_compress(&oinfo);
|
99
|
+
jpeg_destroy_compress(&oinfo);
|
100
|
+
|
101
|
+
|
102
|
+
return(0);
|
103
|
+
}
|
104
|
+
|
105
|
+
//=============================================================================
|
106
|
+
// color_p2j
|
107
|
+
//=============================================================================
|
108
|
+
static int color_p2j(int color)
|
109
|
+
{
|
110
|
+
switch(color){
|
111
|
+
case PKL_GRAYSCALE:
|
112
|
+
return JCS_GRAYSCALE;
|
113
|
+
case PKL_RGB:
|
114
|
+
return JCS_RGB;
|
115
|
+
//case PKL_YCbCr:
|
116
|
+
// return JCS_YCbCr;
|
117
|
+
case PKL_CMYK:
|
118
|
+
return JCS_CMYK;
|
119
|
+
//case PKL_YCCK:
|
120
|
+
// return JCS_YCCK;
|
121
|
+
//case PKL_RGBA:
|
122
|
+
default:
|
123
|
+
return JCS_UNKNOWN;
|
124
|
+
}
|
125
|
+
return JCS_UNKNOWN;
|
126
|
+
}
|
127
|
+
|
128
|
+
//=============================================================================
|
129
|
+
// color_j2p
|
130
|
+
//=============================================================================
|
131
|
+
static int color_j2p(int color)
|
132
|
+
{
|
133
|
+
switch(color){
|
134
|
+
case JCS_GRAYSCALE:
|
135
|
+
return PKL_GRAYSCALE;
|
136
|
+
case JCS_RGB:
|
137
|
+
return PKL_RGB;
|
138
|
+
//case JCS_YCbCr:
|
139
|
+
// return PKL_CMYK;
|
140
|
+
case JCS_CMYK:
|
141
|
+
return PKL_CMYK;
|
142
|
+
//case JCS_YCCK:
|
143
|
+
// return PKL_YCCK;
|
144
|
+
default:
|
145
|
+
return PKL_UNKNOWN;
|
146
|
+
}
|
147
|
+
return PKL_UNKNOWN;
|
148
|
+
}
|
149
|
+
|
150
|
+
//=============================================================================
|
151
|
+
// compress_p2j
|
152
|
+
//=============================================================================
|
153
|
+
static int compress_p2j(int level)
|
154
|
+
{
|
155
|
+
int comp;
|
156
|
+
|
157
|
+
if(level < 0) return(90);
|
158
|
+
comp = 100 - (level*10);
|
159
|
+
if(comp <= 0) return(1);
|
160
|
+
return(comp);
|
161
|
+
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#ifndef _LIB_PIKL_JPEG_
|
2
|
+
#define _LIB_PIKL_JPEG_
|
3
|
+
|
4
|
+
#include <stdio.h>
|
5
|
+
#include <stdlib.h>
|
6
|
+
#include <string.h>
|
7
|
+
#include <setjmp.h>
|
8
|
+
#include <jpeglib.h>
|
9
|
+
|
10
|
+
#include "pikl.h"
|
11
|
+
#include "pikl_private.h"
|
12
|
+
|
13
|
+
/* libjpeg error handler */
|
14
|
+
struct err_mgr {
|
15
|
+
struct jpeg_error_mgr pub;
|
16
|
+
jmp_buf setjmp_buffer;
|
17
|
+
};
|
18
|
+
|
19
|
+
int load_jpeg(PKLImage pkl, FILE *image);
|
20
|
+
int save_jpeg(PKLImage pkl, FILE *image);
|
21
|
+
|
22
|
+
#endif
|