image_pack 0.2.2 → 0.2.3
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -0
- data/README.md +23 -4
- data/ext/image_pack/extconf.rb +35 -124
- data/ext/image_pack/image_pack.c +638 -595
- data/ext/image_pack/mozjpeg_sources.rb +178 -0
- data/ext/image_pack/vendor/mozjpeg/BUILDING.md +744 -0
- data/ext/image_pack/vendor/mozjpeg/CODE_OF_CONDUCT.md +15 -0
- data/ext/image_pack/vendor/mozjpeg/ChangeLog.md +1996 -0
- data/lib/image_pack/configuration.rb +54 -8
- data/lib/image_pack/version.rb +1 -1
- data/lib/image_pack.rb +65 -18
- metadata +13 -78
- data/ext/image_pack/vendor/mozjpeg/README.ijg +0 -258
- data/ext/image_pack/vendor/mozjpeg/cdjpeg.c +0 -156
- data/ext/image_pack/vendor/mozjpeg/cjpeg.c +0 -961
- data/ext/image_pack/vendor/mozjpeg/djpeg.c +0 -855
- data/ext/image_pack/vendor/mozjpeg/jaricom.c +0 -157
- data/ext/image_pack/vendor/mozjpeg/jcarith.c +0 -972
- data/ext/image_pack/vendor/mozjpeg/jcstest.c +0 -126
- data/ext/image_pack/vendor/mozjpeg/jdarith.c +0 -782
- data/ext/image_pack/vendor/mozjpeg/jdatadst-tj.c +0 -198
- data/ext/image_pack/vendor/mozjpeg/jdatasrc-tj.c +0 -194
- data/ext/image_pack/vendor/mozjpeg/jpegtran.c +0 -827
- data/ext/image_pack/vendor/mozjpeg/jpegyuv.c +0 -172
- data/ext/image_pack/vendor/mozjpeg/rdbmp.c +0 -690
- data/ext/image_pack/vendor/mozjpeg/rdcolmap.c +0 -253
- data/ext/image_pack/vendor/mozjpeg/rdgif.c +0 -720
- data/ext/image_pack/vendor/mozjpeg/rdjpeg.c +0 -160
- data/ext/image_pack/vendor/mozjpeg/rdjpgcom.c +0 -494
- data/ext/image_pack/vendor/mozjpeg/rdpng.c +0 -194
- data/ext/image_pack/vendor/mozjpeg/rdppm.c +0 -781
- data/ext/image_pack/vendor/mozjpeg/rdswitch.c +0 -642
- data/ext/image_pack/vendor/mozjpeg/rdtarga.c +0 -508
- data/ext/image_pack/vendor/mozjpeg/simd/arm/aarch32/jccolext-neon.c +0 -148
- data/ext/image_pack/vendor/mozjpeg/simd/arm/aarch32/jchuff-neon.c +0 -334
- data/ext/image_pack/vendor/mozjpeg/simd/arm/aarch32/jsimd.c +0 -976
- data/ext/image_pack/vendor/mozjpeg/simd/i386/jsimd.c +0 -1312
- data/ext/image_pack/vendor/mozjpeg/simd/mips/jsimd.c +0 -1143
- data/ext/image_pack/vendor/mozjpeg/simd/mips64/jccolext-mmi.c +0 -455
- data/ext/image_pack/vendor/mozjpeg/simd/mips64/jccolor-mmi.c +0 -148
- data/ext/image_pack/vendor/mozjpeg/simd/mips64/jcgray-mmi.c +0 -132
- data/ext/image_pack/vendor/mozjpeg/simd/mips64/jcgryext-mmi.c +0 -374
- data/ext/image_pack/vendor/mozjpeg/simd/mips64/jcsample-mmi.c +0 -98
- data/ext/image_pack/vendor/mozjpeg/simd/mips64/jdcolext-mmi.c +0 -415
- data/ext/image_pack/vendor/mozjpeg/simd/mips64/jdcolor-mmi.c +0 -139
- data/ext/image_pack/vendor/mozjpeg/simd/mips64/jdmerge-mmi.c +0 -149
- data/ext/image_pack/vendor/mozjpeg/simd/mips64/jdmrgext-mmi.c +0 -615
- data/ext/image_pack/vendor/mozjpeg/simd/mips64/jdsample-mmi.c +0 -304
- data/ext/image_pack/vendor/mozjpeg/simd/mips64/jfdctfst-mmi.c +0 -255
- data/ext/image_pack/vendor/mozjpeg/simd/mips64/jfdctint-mmi.c +0 -398
- data/ext/image_pack/vendor/mozjpeg/simd/mips64/jidctfst-mmi.c +0 -395
- data/ext/image_pack/vendor/mozjpeg/simd/mips64/jidctint-mmi.c +0 -571
- data/ext/image_pack/vendor/mozjpeg/simd/mips64/jquanti-mmi.c +0 -124
- data/ext/image_pack/vendor/mozjpeg/simd/mips64/jsimd.c +0 -866
- data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jccolext-altivec.c +0 -269
- data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jccolor-altivec.c +0 -116
- data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jcgray-altivec.c +0 -111
- data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jcgryext-altivec.c +0 -228
- data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jcsample-altivec.c +0 -159
- data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jdcolext-altivec.c +0 -276
- data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jdcolor-altivec.c +0 -106
- data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jdmerge-altivec.c +0 -130
- data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jdmrgext-altivec.c +0 -329
- data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jdsample-altivec.c +0 -400
- data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jfdctfst-altivec.c +0 -154
- data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jfdctint-altivec.c +0 -258
- data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jidctfst-altivec.c +0 -255
- data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jidctint-altivec.c +0 -357
- data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jquanti-altivec.c +0 -250
- data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jsimd.c +0 -884
- data/ext/image_pack/vendor/mozjpeg/strtest.c +0 -170
- data/ext/image_pack/vendor/mozjpeg/tjbench.c +0 -1044
- data/ext/image_pack/vendor/mozjpeg/tjexample.c +0 -406
- data/ext/image_pack/vendor/mozjpeg/tjunittest.c +0 -961
- data/ext/image_pack/vendor/mozjpeg/tjutil.c +0 -70
- data/ext/image_pack/vendor/mozjpeg/transupp.c +0 -2373
- data/ext/image_pack/vendor/mozjpeg/turbojpeg-jni.c +0 -1259
- data/ext/image_pack/vendor/mozjpeg/turbojpeg.c +0 -2320
- data/ext/image_pack/vendor/mozjpeg/wrbmp.c +0 -552
- data/ext/image_pack/vendor/mozjpeg/wrgif.c +0 -580
- data/ext/image_pack/vendor/mozjpeg/wrjpgcom.c +0 -577
- data/ext/image_pack/vendor/mozjpeg/wrppm.c +0 -366
- data/ext/image_pack/vendor/mozjpeg/wrtarga.c +0 -258
- data/ext/image_pack/vendor/mozjpeg/yuvjpeg.c +0 -268
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Written by Josh Aas and Tim Terriberry
|
|
3
|
-
* Copyright (c) 2013, Mozilla Corporation
|
|
4
|
-
* All rights reserved.
|
|
5
|
-
*
|
|
6
|
-
* Redistribution and use in source and binary forms, with or without
|
|
7
|
-
* modification, are permitted provided that the following conditions are met:
|
|
8
|
-
*
|
|
9
|
-
* 1. Redistributions of source code must retain the above copyright notice,
|
|
10
|
-
* this list of conditions and the following disclaimer.
|
|
11
|
-
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
-
* this list of conditions and the following disclaimer in the documentation
|
|
13
|
-
* and/or other materials provided with the distribution.
|
|
14
|
-
* 3. Neither the name of the Mozilla Corporation nor the names of its
|
|
15
|
-
* contributors may be used to endorse or promote products derived from this
|
|
16
|
-
* software without specific prior written permission.
|
|
17
|
-
*
|
|
18
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
19
|
-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
20
|
-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
21
|
-
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
22
|
-
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
23
|
-
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
24
|
-
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
25
|
-
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
26
|
-
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
27
|
-
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
28
|
-
* POSSIBILITY OF SUCH DAMAGE.
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
/* Expects 4:2:0 YCbCr */
|
|
32
|
-
|
|
33
|
-
/* gcc -std=c99 yuvjpeg.c -I/opt/local/include/ -L/opt/local/lib/ -ljpeg -o yuvjpeg */
|
|
34
|
-
|
|
35
|
-
#include <errno.h>
|
|
36
|
-
#include <stdio.h>
|
|
37
|
-
#include <string.h>
|
|
38
|
-
#include <stdlib.h>
|
|
39
|
-
|
|
40
|
-
#include "jpeglib.h"
|
|
41
|
-
|
|
42
|
-
void extend_edge(JSAMPLE *image, int width, int height, unsigned char *yuv,
|
|
43
|
-
int luma_width, int luma_height, int chroma_width, int chroma_height) {
|
|
44
|
-
int x;
|
|
45
|
-
int y;
|
|
46
|
-
|
|
47
|
-
for (y = 0; y < luma_height; y++) {
|
|
48
|
-
for (x = 0; x < luma_width; x++) {
|
|
49
|
-
image[width*y + x] = yuv[luma_width*y + x];
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
for (y = 0; y < chroma_height; y++) {
|
|
53
|
-
for (x = 0; x < chroma_width; x++) {
|
|
54
|
-
image[width*height + (width/2)*y + x] =
|
|
55
|
-
yuv[luma_width*luma_height + chroma_width*y + x];
|
|
56
|
-
image[width*height + (width/2)*((height/2) + y) + x] =
|
|
57
|
-
yuv[luma_width*luma_height + chroma_width*(chroma_height + y) + x];
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/* Perform right edge extension. */
|
|
62
|
-
for (y = 0; y < luma_height; y++) {
|
|
63
|
-
for (x = luma_width; x < width; x++) {
|
|
64
|
-
image[width*y + x] = image[width*y + (x - 1)];
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
for (y = 0; y < chroma_height; y++) {
|
|
68
|
-
for (x = chroma_width; x < width/2; x++) {
|
|
69
|
-
image[width*height + (width/2)*y + x] =
|
|
70
|
-
image[width*height + (width/2)*y + (x - 1)];
|
|
71
|
-
image[width*height + (width/2)*((height/2) + y) + x] =
|
|
72
|
-
image[width*height + (width/2)*((height/2) + y) + (x - 1)];
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/* Perform bottom edge extension. */
|
|
77
|
-
for (x = 0; x < width; x++) {
|
|
78
|
-
for (y = luma_height; y < height; y++) {
|
|
79
|
-
image[width*y + x] = image[width*(y - 1) + x];
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
for (x = 0; x < width/2; x++) {
|
|
83
|
-
for (y = chroma_height; y < height/2; y++) {
|
|
84
|
-
image[width*height + (width/2)*y + x] =
|
|
85
|
-
image[width*height + (width/2)*(y - 1) + x];
|
|
86
|
-
image[width*height + (width/2)*((height/2) + y) + x] =
|
|
87
|
-
image[width*height + (width/2)*((height/2) + (y - 1)) + x];
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
int main(int argc, char *argv[]) {
|
|
93
|
-
long quality;
|
|
94
|
-
int matches;
|
|
95
|
-
int luma_width;
|
|
96
|
-
int luma_height;
|
|
97
|
-
int chroma_width;
|
|
98
|
-
int chroma_height;
|
|
99
|
-
int frame_width;
|
|
100
|
-
int frame_height;
|
|
101
|
-
const char *yuv_path;
|
|
102
|
-
const char *jpg_path;
|
|
103
|
-
FILE *yuv_fd;
|
|
104
|
-
size_t yuv_size;
|
|
105
|
-
unsigned char *yuv_buffer;
|
|
106
|
-
JSAMPLE *jpg_buffer;
|
|
107
|
-
struct jpeg_compress_struct cinfo;
|
|
108
|
-
struct jpeg_error_mgr jerr;
|
|
109
|
-
FILE *jpg_fd;
|
|
110
|
-
JSAMPROW yrow_pointer[16];
|
|
111
|
-
JSAMPROW cbrow_pointer[8];
|
|
112
|
-
JSAMPROW crrow_pointer[8];
|
|
113
|
-
JSAMPROW *plane_pointer[3];
|
|
114
|
-
int y;
|
|
115
|
-
|
|
116
|
-
if (argc != 5) {
|
|
117
|
-
fprintf(stderr, "Required arguments:\n");
|
|
118
|
-
fprintf(stderr, "1. JPEG quality value, 0-100\n");
|
|
119
|
-
fprintf(stderr, "2. Image size (e.g. '512x512')\n");
|
|
120
|
-
fprintf(stderr, "3. Path to YUV input file\n");
|
|
121
|
-
fprintf(stderr, "4. Path to JPG output file\n");
|
|
122
|
-
return 1;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
errno = 0;
|
|
126
|
-
|
|
127
|
-
quality = strtol(argv[1], NULL, 10);
|
|
128
|
-
if (errno != 0 || quality < 0 || quality > 100) {
|
|
129
|
-
fprintf(stderr, "Invalid JPEG quality value!\n");
|
|
130
|
-
return 1;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
matches = sscanf(argv[2], "%dx%d", &luma_width, &luma_height);
|
|
134
|
-
if (matches != 2) {
|
|
135
|
-
fprintf(stderr, "Invalid image size input!\n");
|
|
136
|
-
return 1;
|
|
137
|
-
}
|
|
138
|
-
if (luma_width <= 0 || luma_height <= 0) {
|
|
139
|
-
fprintf(stderr, "Invalid image size input!\n");
|
|
140
|
-
return 1;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
chroma_width = (luma_width + 1) >> 1;
|
|
144
|
-
chroma_height = (luma_height + 1) >> 1;
|
|
145
|
-
|
|
146
|
-
/* Will check these for validity when opening via 'fopen'. */
|
|
147
|
-
yuv_path = argv[3];
|
|
148
|
-
jpg_path = argv[4];
|
|
149
|
-
|
|
150
|
-
yuv_fd = fopen(yuv_path, "r");
|
|
151
|
-
if (!yuv_fd) {
|
|
152
|
-
fprintf(stderr, "Invalid path to YUV file!\n");
|
|
153
|
-
return 1;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
fseek(yuv_fd, 0, SEEK_END);
|
|
157
|
-
yuv_size = ftell(yuv_fd);
|
|
158
|
-
fseek(yuv_fd, 0, SEEK_SET);
|
|
159
|
-
|
|
160
|
-
/* Check that the file size matches 4:2:0 yuv. */
|
|
161
|
-
if (yuv_size !=
|
|
162
|
-
(size_t)luma_width*luma_height + 2*chroma_width*chroma_height) {
|
|
163
|
-
fclose(yuv_fd);
|
|
164
|
-
fprintf(stderr, "Unexpected input format!\n");
|
|
165
|
-
return 1;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
yuv_buffer = malloc(yuv_size);
|
|
169
|
-
if (!yuv_buffer) {
|
|
170
|
-
fclose(yuv_fd);
|
|
171
|
-
fprintf(stderr, "Memory allocation failure!\n");
|
|
172
|
-
return 1;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
if (fread(yuv_buffer, yuv_size, 1, yuv_fd) != 1) {
|
|
176
|
-
fprintf(stderr, "Error reading yuv file\n");
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
fclose(yuv_fd);
|
|
180
|
-
|
|
181
|
-
frame_width = (luma_width + (16 - 1)) & ~(16 - 1);
|
|
182
|
-
frame_height = (luma_height + (16 - 1)) & ~(16 - 1);
|
|
183
|
-
|
|
184
|
-
jpg_buffer =
|
|
185
|
-
malloc(frame_width*frame_height + 2*(frame_width/2)*(frame_height/2));
|
|
186
|
-
if (!jpg_buffer) {
|
|
187
|
-
free(yuv_buffer);
|
|
188
|
-
fprintf(stderr, "Memory allocation failure!\n");
|
|
189
|
-
return 1;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
extend_edge(jpg_buffer, frame_width, frame_height,
|
|
193
|
-
yuv_buffer, luma_width, luma_height, chroma_width, chroma_height);
|
|
194
|
-
|
|
195
|
-
free(yuv_buffer);
|
|
196
|
-
|
|
197
|
-
cinfo.err = jpeg_std_error(&jerr);
|
|
198
|
-
jpeg_create_compress(&cinfo);
|
|
199
|
-
|
|
200
|
-
jpg_fd = fopen(jpg_path, "wb");
|
|
201
|
-
if (!jpg_fd) {
|
|
202
|
-
free(jpg_buffer);
|
|
203
|
-
fprintf(stderr, "Invalid path to JPEG file!\n");
|
|
204
|
-
return 1;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
jpeg_stdio_dest(&cinfo, jpg_fd);
|
|
208
|
-
|
|
209
|
-
cinfo.image_width = luma_width;
|
|
210
|
-
cinfo.image_height = luma_height;
|
|
211
|
-
cinfo.input_components = 3;
|
|
212
|
-
|
|
213
|
-
cinfo.in_color_space = JCS_YCbCr;
|
|
214
|
-
jpeg_set_defaults(&cinfo);
|
|
215
|
-
|
|
216
|
-
cinfo.raw_data_in = TRUE;
|
|
217
|
-
|
|
218
|
-
cinfo.comp_info[0].h_samp_factor = 2;
|
|
219
|
-
cinfo.comp_info[0].v_samp_factor = 2;
|
|
220
|
-
cinfo.comp_info[0].dc_tbl_no = 0;
|
|
221
|
-
cinfo.comp_info[0].ac_tbl_no = 0;
|
|
222
|
-
cinfo.comp_info[0].quant_tbl_no = 0;
|
|
223
|
-
|
|
224
|
-
cinfo.comp_info[1].h_samp_factor = 1;
|
|
225
|
-
cinfo.comp_info[1].v_samp_factor = 1;
|
|
226
|
-
cinfo.comp_info[1].dc_tbl_no = 1;
|
|
227
|
-
cinfo.comp_info[1].ac_tbl_no = 1;
|
|
228
|
-
cinfo.comp_info[1].quant_tbl_no = 1;
|
|
229
|
-
|
|
230
|
-
cinfo.comp_info[2].h_samp_factor = 1;
|
|
231
|
-
cinfo.comp_info[2].v_samp_factor = 1;
|
|
232
|
-
cinfo.comp_info[2].dc_tbl_no = 1;
|
|
233
|
-
cinfo.comp_info[2].ac_tbl_no = 1;
|
|
234
|
-
cinfo.comp_info[2].quant_tbl_no = 1;
|
|
235
|
-
|
|
236
|
-
jpeg_set_quality(&cinfo, quality, TRUE);
|
|
237
|
-
cinfo.optimize_coding = TRUE;
|
|
238
|
-
|
|
239
|
-
jpeg_start_compress(&cinfo, TRUE);
|
|
240
|
-
|
|
241
|
-
plane_pointer[0] = yrow_pointer;
|
|
242
|
-
plane_pointer[1] = cbrow_pointer;
|
|
243
|
-
plane_pointer[2] = crrow_pointer;
|
|
244
|
-
|
|
245
|
-
while (cinfo.next_scanline < cinfo.image_height) {
|
|
246
|
-
int scanline;
|
|
247
|
-
scanline = cinfo.next_scanline;
|
|
248
|
-
|
|
249
|
-
for (y = 0; y < 16; y++) {
|
|
250
|
-
yrow_pointer[y] = &jpg_buffer[frame_width*(scanline + y)];
|
|
251
|
-
}
|
|
252
|
-
for (y = 0; y < 8; y++) {
|
|
253
|
-
cbrow_pointer[y] = &jpg_buffer[frame_width*frame_height +
|
|
254
|
-
(frame_width/2)*((scanline/2) + y)];
|
|
255
|
-
crrow_pointer[y] = &jpg_buffer[frame_width*frame_height +
|
|
256
|
-
(frame_width/2)*(frame_height/2) + (frame_width/2)*((scanline/2) + y)];
|
|
257
|
-
}
|
|
258
|
-
jpeg_write_raw_data(&cinfo, plane_pointer, 16);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
jpeg_finish_compress(&cinfo);
|
|
262
|
-
jpeg_destroy_compress(&cinfo);
|
|
263
|
-
|
|
264
|
-
free(jpg_buffer);
|
|
265
|
-
fclose(jpg_fd);
|
|
266
|
-
|
|
267
|
-
return 0;
|
|
268
|
-
}
|