qttk 0.1.0
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 +7 -0
- data/.gitignore +2 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +36 -0
- data/README.markdown +131 -0
- data/Rakefile +17 -0
- data/TODO.markdown +236 -0
- data/bin/qt +7 -0
- data/etc/gutenprint/gp-tool.rb +56 -0
- data/etc/gutenprint/gutenprint-filter.c +400 -0
- data/etc/gutenprint/gutenprint.rb +86 -0
- data/etc/gutenprint/stp-test +326 -0
- data/etc/images/3551599565_db282cf840_o.jpg +0 -0
- data/etc/images/4843122063_d582c569e9_o.jpg +0 -0
- data/etc/images/4843128953_83c1770907_o.jpg +0 -0
- data/lib/quadtone.rb +56 -0
- data/lib/quadtone/cgats.rb +137 -0
- data/lib/quadtone/cluster_calculator.rb +81 -0
- data/lib/quadtone/color.rb +83 -0
- data/lib/quadtone/color/cmyk.rb +112 -0
- data/lib/quadtone/color/device_n.rb +23 -0
- data/lib/quadtone/color/gray.rb +46 -0
- data/lib/quadtone/color/lab.rb +150 -0
- data/lib/quadtone/color/qtr.rb +71 -0
- data/lib/quadtone/color/rgb.rb +71 -0
- data/lib/quadtone/color/xyz.rb +80 -0
- data/lib/quadtone/curve.rb +138 -0
- data/lib/quadtone/curve_set.rb +196 -0
- data/lib/quadtone/descendants.rb +9 -0
- data/lib/quadtone/environment.rb +5 -0
- data/lib/quadtone/extensions/math.rb +11 -0
- data/lib/quadtone/extensions/pathname3.rb +11 -0
- data/lib/quadtone/printer.rb +106 -0
- data/lib/quadtone/profile.rb +217 -0
- data/lib/quadtone/quad_file.rb +59 -0
- data/lib/quadtone/renderer.rb +139 -0
- data/lib/quadtone/run.rb +10 -0
- data/lib/quadtone/sample.rb +32 -0
- data/lib/quadtone/separator.rb +36 -0
- data/lib/quadtone/target.rb +277 -0
- data/lib/quadtone/tool.rb +61 -0
- data/lib/quadtone/tools/add_printer.rb +73 -0
- data/lib/quadtone/tools/characterize.rb +43 -0
- data/lib/quadtone/tools/chart.rb +31 -0
- data/lib/quadtone/tools/check.rb +16 -0
- data/lib/quadtone/tools/dir.rb +15 -0
- data/lib/quadtone/tools/edit.rb +23 -0
- data/lib/quadtone/tools/init.rb +82 -0
- data/lib/quadtone/tools/install.rb +15 -0
- data/lib/quadtone/tools/linearize.rb +28 -0
- data/lib/quadtone/tools/list.rb +19 -0
- data/lib/quadtone/tools/print.rb +38 -0
- data/lib/quadtone/tools/printer_options.rb +40 -0
- data/lib/quadtone/tools/rename.rb +17 -0
- data/lib/quadtone/tools/render.rb +43 -0
- data/lib/quadtone/tools/rewrite.rb +15 -0
- data/lib/quadtone/tools/separate.rb +71 -0
- data/lib/quadtone/tools/show.rb +15 -0
- data/lib/quadtone/tools/test.rb +26 -0
- data/qttk.gemspec +34 -0
- metadata +215 -0
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'quadtone'
|
2
|
+
include Quadtone
|
3
|
+
|
4
|
+
module Quadtone
|
5
|
+
|
6
|
+
class GPTool < Tool
|
7
|
+
|
8
|
+
attr_accessor :printer
|
9
|
+
|
10
|
+
def parse_option(option, args)
|
11
|
+
case option
|
12
|
+
when '--printer', '-p'
|
13
|
+
@printer = args.shift
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def run(image_file)
|
18
|
+
image_file = Pathname.new(image_file)
|
19
|
+
|
20
|
+
raise "Must specify printer with --printer" unless @printer
|
21
|
+
|
22
|
+
gp = Gutenprint.new(@printer)
|
23
|
+
|
24
|
+
gp_channels = gp.channels
|
25
|
+
|
26
|
+
geometry = gp.geometry
|
27
|
+
width = geometry[:width]
|
28
|
+
height = geometry[:height]
|
29
|
+
|
30
|
+
;;warn "[reading #{image_file}]"
|
31
|
+
image_list = Magick::ImageList.new(image_file)
|
32
|
+
# ;;warn "[rotating]"
|
33
|
+
# ;;image_list.rotate!(90)
|
34
|
+
# ;;warn "[scaling]"
|
35
|
+
# scale = geometry[:x_resolution] / 72.0
|
36
|
+
# image_list.sample!(scale)
|
37
|
+
|
38
|
+
;;warn "[writing output ESCP/2]"
|
39
|
+
gp.print(
|
40
|
+
:num_channels => gp_channels.length,
|
41
|
+
:rows => image_list.rows,
|
42
|
+
:columns => image_list.columns,
|
43
|
+
:output_file => image_file.with_extname('.escp2'),
|
44
|
+
) do |io|
|
45
|
+
|
46
|
+
image_list.rows.times do |row|
|
47
|
+
row_str = image_list.columns.times.map do |col|
|
48
|
+
image_list.to_a.map { |img| 65535 - img.pixel_color(col, row).intensity }.pack('S*')
|
49
|
+
end.join
|
50
|
+
io.print row_str
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,400 @@
|
|
1
|
+
/*
|
2
|
+
* This sample program may be used to generate test patterns. It also
|
3
|
+
* serves as an example of how to use the gimp-print API.
|
4
|
+
*
|
5
|
+
* As the purpose of this program is to allow fine grained control over
|
6
|
+
* the output, it uses the raw CMYK output type. This feeds 16 bits each
|
7
|
+
* of CMYK to the driver. This mode performs no correction on the data;
|
8
|
+
* it passes it directly to the dither engine, performing no color,
|
9
|
+
* density, gamma, etc. correction. Most programs will use one of the
|
10
|
+
* other modes (RGB, density and gamma corrected 8-bit CMYK, grayscale, or
|
11
|
+
* black and white).
|
12
|
+
*/
|
13
|
+
|
14
|
+
/*
|
15
|
+
|
16
|
+
would be better to read TIFF files directly and interleave strips from multipage files
|
17
|
+
|
18
|
+
http://www.libtiff.org/libtiff.html
|
19
|
+
https://www.ibm.com/developerworks/linux/library/l-libtiff/
|
20
|
+
|
21
|
+
*/
|
22
|
+
|
23
|
+
#include <stdlib.h>
|
24
|
+
#include <unistd.h>
|
25
|
+
#include <stdio.h>
|
26
|
+
#include <math.h>
|
27
|
+
#include <string.h>
|
28
|
+
#include <errno.h>
|
29
|
+
#include <assert.h>
|
30
|
+
|
31
|
+
#include <gutenprint/gutenprint.h>
|
32
|
+
|
33
|
+
int g_channel_bit_depth = 16;
|
34
|
+
int g_raw_channels = 0;
|
35
|
+
char *g_driver = NULL;
|
36
|
+
int g_image_height = 0;
|
37
|
+
int g_image_width = 0;
|
38
|
+
char *g_page_size = NULL;
|
39
|
+
|
40
|
+
const stp_printer_t *g_printer = NULL;
|
41
|
+
stp_vars_t *g_vars = NULL;
|
42
|
+
FILE *g_input_file = NULL;
|
43
|
+
FILE *g_output_file = NULL;
|
44
|
+
|
45
|
+
static void
|
46
|
+
writefunc(void *file, const char *buf, size_t bytes)
|
47
|
+
{
|
48
|
+
fwrite(buf, 1, bytes, (FILE *)file);
|
49
|
+
}
|
50
|
+
|
51
|
+
static stp_image_status_t
|
52
|
+
Image_get_row(stp_image_t *image, unsigned char *data, size_t byte_limit, int row)
|
53
|
+
{
|
54
|
+
if (fread(data, 1, byte_limit, g_input_file) == byte_limit) {
|
55
|
+
// ;;fprintf(stderr, "[Image_get_row: limit = %lu, row = %d] => STP_IMAGE_STATUS_OK\n", byte_limit, row);
|
56
|
+
;;fprintf(stderr, ".");
|
57
|
+
return STP_IMAGE_STATUS_OK;
|
58
|
+
} else {
|
59
|
+
// ;;fprintf(stderr, "[Image_get_row: limit = %lu, row = %d] => STP_IMAGE_STATUS_ABORT\n", byte_limit, row);
|
60
|
+
;;fprintf(stderr, "!");
|
61
|
+
return STP_IMAGE_STATUS_ABORT;
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
static int
|
66
|
+
Image_width(stp_image_t *image)
|
67
|
+
{
|
68
|
+
fprintf(stderr, "[Image_width => %d]\n", g_image_width);
|
69
|
+
return g_image_width;
|
70
|
+
}
|
71
|
+
|
72
|
+
static int
|
73
|
+
Image_height(stp_image_t *image)
|
74
|
+
{
|
75
|
+
fprintf(stderr, "[Image_height => %d]\n", g_image_height);
|
76
|
+
return g_image_height;
|
77
|
+
}
|
78
|
+
|
79
|
+
static void
|
80
|
+
Image_init(stp_image_t *image)
|
81
|
+
{
|
82
|
+
fprintf(stderr, "[Image_init]\n");
|
83
|
+
}
|
84
|
+
|
85
|
+
static void
|
86
|
+
Image_reset(stp_image_t *image)
|
87
|
+
{
|
88
|
+
fprintf(stderr, "[Image_reset]\n");
|
89
|
+
}
|
90
|
+
|
91
|
+
static void
|
92
|
+
Image_conclude(stp_image_t *image)
|
93
|
+
{
|
94
|
+
fprintf(stderr, "[Image_conclude]\n");
|
95
|
+
}
|
96
|
+
|
97
|
+
static const char *
|
98
|
+
Image_get_appname(stp_image_t *image)
|
99
|
+
{
|
100
|
+
fprintf(stderr, "[Image_get_appname]\n");
|
101
|
+
return "gutenprint-filter";
|
102
|
+
}
|
103
|
+
|
104
|
+
static void
|
105
|
+
show_printer_list(void)
|
106
|
+
{
|
107
|
+
int i;
|
108
|
+
|
109
|
+
for (i = 0; i < stp_printer_model_count(); i++) {
|
110
|
+
const stp_printer_t *printer = stp_get_printer_by_index(i);
|
111
|
+
printf("%s: %s\n", stp_printer_get_driver(printer), stp_printer_get_long_name(printer));
|
112
|
+
}
|
113
|
+
}
|
114
|
+
|
115
|
+
static void
|
116
|
+
show_params(stp_vars_t *v)
|
117
|
+
{
|
118
|
+
stp_parameter_list_t params = stp_get_parameter_list(v);
|
119
|
+
int count = stp_parameter_list_count(params);
|
120
|
+
int i;
|
121
|
+
|
122
|
+
for (i = 0; i < count; i++) {
|
123
|
+
const stp_parameter_t *p = stp_parameter_list_param(params, i);
|
124
|
+
|
125
|
+
if (p->p_type == STP_PARAMETER_TYPE_STRING_LIST) {
|
126
|
+
const char *val = stp_get_string_parameter(v, p->name);
|
127
|
+
printf("%30s = %s (string)\n", p->name, val);
|
128
|
+
|
129
|
+
} else if (p->p_type == STP_PARAMETER_TYPE_INT) {
|
130
|
+
int val = stp_get_int_parameter(v, p->name);
|
131
|
+
printf("%30s = %d (int)\n", p->name, val);
|
132
|
+
|
133
|
+
} else if (p->p_type == STP_PARAMETER_TYPE_BOOLEAN) {
|
134
|
+
int val = stp_get_boolean_parameter(v, p->name);
|
135
|
+
printf("%30s = %s (bool)\n", p->name, val ? "true" : "false");
|
136
|
+
|
137
|
+
} else if (p->p_type == STP_PARAMETER_TYPE_CURVE) {
|
138
|
+
const stp_curve_t *val = stp_get_curve_parameter(v, p->name);
|
139
|
+
printf("%30s = %p (curve)\n", p->name, val);
|
140
|
+
|
141
|
+
} else if (p->p_type == STP_PARAMETER_TYPE_DOUBLE) {
|
142
|
+
double val = stp_get_float_parameter(v, p->name);
|
143
|
+
printf("%30s = %f (float)\n", p->name, val);
|
144
|
+
|
145
|
+
} else if (p->p_type == STP_PARAMETER_TYPE_FILE) {
|
146
|
+
const char *val = stp_get_file_parameter(v, p->name);
|
147
|
+
printf("%30s = %s (file)\n", p->name, val);
|
148
|
+
|
149
|
+
} else if (p->p_type == STP_PARAMETER_TYPE_RAW) {
|
150
|
+
const void *val = stp_get_file_parameter(v, p->name);
|
151
|
+
printf("%30s = %p (raw)\n", p->name, val);
|
152
|
+
|
153
|
+
} else if (p->p_type == STP_PARAMETER_TYPE_DIMENSION) {
|
154
|
+
int val = stp_get_dimension_parameter(v, p->name);
|
155
|
+
printf("%30s = %d (dimension)\n", p->name, val);
|
156
|
+
|
157
|
+
} else if (p->p_type == STP_PARAMETER_TYPE_ARRAY) {
|
158
|
+
const stp_array_t *array = stp_get_array_parameter(v, p->name);
|
159
|
+
int x_size, y_size;
|
160
|
+
stp_array_get_size(array, &x_size, &y_size);
|
161
|
+
printf("%30s = ??? (%dx%d array)\n", p->name, x_size, y_size);
|
162
|
+
|
163
|
+
} else {
|
164
|
+
printf("%30s = ??? (<%d>)\n", p->name, p->p_type);
|
165
|
+
}
|
166
|
+
}
|
167
|
+
|
168
|
+
stp_parameter_list_destroy(params);
|
169
|
+
params = NULL;
|
170
|
+
}
|
171
|
+
|
172
|
+
static void
|
173
|
+
show_channels(void)
|
174
|
+
{
|
175
|
+
stp_parameter_t param;
|
176
|
+
stp_describe_parameter(g_vars, "RawChannelNames", ¶m);
|
177
|
+
|
178
|
+
stp_string_list_t *channels_strlist = param.bounds.str;
|
179
|
+
assert(channels_strlist);
|
180
|
+
|
181
|
+
int i;
|
182
|
+
for (i = 0; i < stp_string_list_count(channels_strlist); i++) {
|
183
|
+
stp_param_string_t *p = stp_string_list_param(channels_strlist, i);
|
184
|
+
printf("%s: %s\n", p->name, p->text);
|
185
|
+
}
|
186
|
+
|
187
|
+
stp_parameter_description_destroy(¶m);
|
188
|
+
}
|
189
|
+
|
190
|
+
static void
|
191
|
+
show_geometry(void)
|
192
|
+
{
|
193
|
+
int x_res, y_res;
|
194
|
+
|
195
|
+
stp_describe_resolution(g_vars, &x_res, &y_res);
|
196
|
+
printf("x_resolution: %d\n", x_res);
|
197
|
+
printf("y_resolution: %d\n", y_res);
|
198
|
+
|
199
|
+
printf("PageSize: %s\n", stp_get_string_parameter(g_vars, "PageSize"));
|
200
|
+
printf("top: %d\n", stp_get_top(g_vars));
|
201
|
+
printf("left: %d\n", stp_get_left(g_vars));
|
202
|
+
printf("width: %d\n", stp_get_width(g_vars));
|
203
|
+
printf("height: %d\n", stp_get_height(g_vars));
|
204
|
+
}
|
205
|
+
|
206
|
+
static void
|
207
|
+
init(void)
|
208
|
+
{
|
209
|
+
char tmp[32];
|
210
|
+
|
211
|
+
stp_init();
|
212
|
+
|
213
|
+
g_vars = stp_vars_create();
|
214
|
+
stp_vars_copy(g_vars, stp_default_settings());
|
215
|
+
stp_set_driver(g_vars, g_driver);
|
216
|
+
g_printer = stp_get_printer(g_vars);
|
217
|
+
assert(g_printer);
|
218
|
+
stp_set_printer_defaults(g_vars, g_printer);
|
219
|
+
|
220
|
+
stp_set_outfunc(g_vars, writefunc);
|
221
|
+
stp_set_errfunc(g_vars, writefunc);
|
222
|
+
stp_set_outdata(g_vars, g_output_file);
|
223
|
+
stp_set_errdata(g_vars, stderr);
|
224
|
+
|
225
|
+
stp_set_string_parameter(g_vars, "InputImageType", "Raw");
|
226
|
+
stp_set_string_parameter(g_vars, "PrintingMode", "Color");
|
227
|
+
stp_set_string_parameter(g_vars, "ColorCorrection", "Raw");
|
228
|
+
if (g_channel_bit_depth > 0) {
|
229
|
+
sprintf(tmp, "%d", g_channel_bit_depth);
|
230
|
+
stp_set_string_parameter(g_vars, "ChannelBitDepth", tmp);
|
231
|
+
}
|
232
|
+
if (g_raw_channels > 0) {
|
233
|
+
sprintf(tmp, "%d", g_raw_channels);
|
234
|
+
stp_set_string_parameter(g_vars, "RawChannels", tmp);
|
235
|
+
}
|
236
|
+
stp_set_string_parameter(g_vars, "Quality", "None");
|
237
|
+
stp_set_string_parameter(g_vars, "ImageType", "None");
|
238
|
+
stp_set_float_parameter(g_vars, "Density", 1.0);
|
239
|
+
stp_set_string_parameter(g_vars, "DitherAlgorithm", "Adaptive");
|
240
|
+
stp_set_boolean_parameter(g_vars, "SimpleGamma", 1);
|
241
|
+
|
242
|
+
if (stp_check_string_parameter(g_vars, "PageSize", STP_PARAMETER_ACTIVE) && strcmp(stp_get_string_parameter(g_vars, "PageSize"), "Auto") == 0) {
|
243
|
+
|
244
|
+
stp_parameter_t desc;
|
245
|
+
stp_describe_parameter(g_vars, "PageSize", &desc);
|
246
|
+
if (desc.p_type == STP_PARAMETER_TYPE_STRING_LIST) {
|
247
|
+
stp_set_string_parameter(g_vars, "PageSize", desc.deflt.str);
|
248
|
+
}
|
249
|
+
stp_parameter_description_destroy(&desc);
|
250
|
+
|
251
|
+
} else if (g_page_size) {
|
252
|
+
|
253
|
+
stp_set_string_parameter(g_vars, "PageSize", g_page_size);
|
254
|
+
}
|
255
|
+
|
256
|
+
stp_set_printer_defaults_soft(g_vars, g_printer);
|
257
|
+
|
258
|
+
{
|
259
|
+
int left, right, bottom, top;
|
260
|
+
|
261
|
+
stp_get_imageable_area(g_vars, &left, &right, &bottom, &top);
|
262
|
+
|
263
|
+
stp_set_width(g_vars, right - left);
|
264
|
+
stp_set_height(g_vars, bottom - top);
|
265
|
+
stp_set_left(g_vars, left);
|
266
|
+
stp_set_top(g_vars, top);
|
267
|
+
}
|
268
|
+
|
269
|
+
stp_merge_printvars(g_vars, stp_printer_get_defaults(g_printer));
|
270
|
+
|
271
|
+
stp_verify(g_vars);
|
272
|
+
}
|
273
|
+
|
274
|
+
static void
|
275
|
+
print(void)
|
276
|
+
{
|
277
|
+
static stp_image_t image = {
|
278
|
+
Image_init,
|
279
|
+
Image_reset,
|
280
|
+
Image_width,
|
281
|
+
Image_height,
|
282
|
+
Image_get_row,
|
283
|
+
Image_get_appname,
|
284
|
+
Image_conclude,
|
285
|
+
NULL
|
286
|
+
};
|
287
|
+
|
288
|
+
;;fprintf(stderr, "[starting job]\n");
|
289
|
+
stp_start_job(g_vars, &image);
|
290
|
+
;;fprintf(stderr, "[printing job]\n");
|
291
|
+
stp_print(g_vars, &image);
|
292
|
+
;;fprintf(stderr, "[ending job]\n");
|
293
|
+
stp_end_job(g_vars, &image);
|
294
|
+
}
|
295
|
+
|
296
|
+
static void
|
297
|
+
cleanup(void)
|
298
|
+
{
|
299
|
+
stp_vars_destroy(g_vars);
|
300
|
+
g_vars = NULL;
|
301
|
+
}
|
302
|
+
|
303
|
+
int
|
304
|
+
main(int argc, char **argv)
|
305
|
+
{
|
306
|
+
int opt_show_printer_list = 0;
|
307
|
+
int opt_show_channels = 0;
|
308
|
+
int opt_show_params = 0;
|
309
|
+
int opt_show_geometry = 0;
|
310
|
+
int opt;
|
311
|
+
|
312
|
+
g_input_file = stdin;
|
313
|
+
g_output_file = stdout;
|
314
|
+
|
315
|
+
while ((opt = getopt(argc, argv, "lgspP:b:c:d:w:h:o:")) != -1) {
|
316
|
+
switch (opt) {
|
317
|
+
case 'l':
|
318
|
+
opt_show_printer_list = 1;
|
319
|
+
break;
|
320
|
+
|
321
|
+
case 'g':
|
322
|
+
opt_show_geometry = 1;
|
323
|
+
break;
|
324
|
+
|
325
|
+
case 's':
|
326
|
+
opt_show_channels = 1;
|
327
|
+
break;
|
328
|
+
|
329
|
+
case 'p':
|
330
|
+
opt_show_params = 1;
|
331
|
+
break;
|
332
|
+
|
333
|
+
case 'P':
|
334
|
+
g_page_size = optarg;
|
335
|
+
break;
|
336
|
+
|
337
|
+
case 'b':
|
338
|
+
sscanf(optarg, "%d", &g_channel_bit_depth);
|
339
|
+
break;
|
340
|
+
|
341
|
+
case 'c':
|
342
|
+
sscanf(optarg, "%d", &g_raw_channels);
|
343
|
+
break;
|
344
|
+
|
345
|
+
case 'd':
|
346
|
+
g_driver = optarg;
|
347
|
+
break;
|
348
|
+
|
349
|
+
case 'w':
|
350
|
+
sscanf(optarg, "%d", &g_image_width);
|
351
|
+
break;
|
352
|
+
|
353
|
+
case 'h':
|
354
|
+
sscanf(optarg, "%d", &g_image_height);
|
355
|
+
break;
|
356
|
+
|
357
|
+
case 'o':
|
358
|
+
g_output_file = fopen(optarg, "w");
|
359
|
+
assert(g_output_file);
|
360
|
+
break;
|
361
|
+
|
362
|
+
default:
|
363
|
+
fprintf(stderr, "Usage...\n");
|
364
|
+
exit(1);
|
365
|
+
}
|
366
|
+
}
|
367
|
+
|
368
|
+
argc -= optind;
|
369
|
+
argv += optind;
|
370
|
+
|
371
|
+
init();
|
372
|
+
|
373
|
+
if (opt_show_printer_list) {
|
374
|
+
show_printer_list();
|
375
|
+
|
376
|
+
} else if (opt_show_channels) {
|
377
|
+
show_channels();
|
378
|
+
|
379
|
+
} else if (opt_show_params) {
|
380
|
+
show_params(g_vars);
|
381
|
+
|
382
|
+
} else if (opt_show_geometry) {
|
383
|
+
show_geometry();
|
384
|
+
|
385
|
+
} else {
|
386
|
+
;;fprintf(stderr, "[opening %s]\n", argv[0]);
|
387
|
+
if (strcmp(argv[0], "-") == 0)
|
388
|
+
print();
|
389
|
+
else {
|
390
|
+
g_input_file = fopen(argv[0], "r");
|
391
|
+
assert(g_input_file);
|
392
|
+
print();
|
393
|
+
fclose(g_input_file);
|
394
|
+
}
|
395
|
+
}
|
396
|
+
|
397
|
+
cleanup();
|
398
|
+
|
399
|
+
return 0;
|
400
|
+
}
|