1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
use std::os::raw::{c_void, c_int, c_char, c_uchar};
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct Version {
pub major: u8,
pub minor: u8,
pub patch: u8,
}
pub const VERSION: Version = Version {
major: 1,
minor: 7,
patch: 3,
};
pub const ABI_VERSION: Version = Version {
major: 1,
minor: 6,
patch: 0,
};
pub const OUTPUT_PACKET_SIZE: u16 = 16384;
pub const PALETTE_MIN: u16 = 2;
pub const PALETTE_MAX: u16 = 256;
pub const USE_DEPRECATED_SYMBOLS: bool = true;
use status::Status;
pub mod status {
use std::os::raw::c_int;
pub type Status = c_int;
pub const OK: Status = 0x0000;
pub const ERR: Status = 0x1000;
pub const RUNTIME_ERROR: Status = ERR | 0x0100;
pub const LOGIC_ERROR: Status = ERR | 0x0200;
pub const FEATURE_ERROR: Status = ERR | 0x0300;
pub const LIBC_ERROR: Status = ERR | 0x0400;
pub const CURL_ERROR: Status = ERR | 0x0500;
pub const JPEG_ERROR: Status = ERR | 0x0600;
pub const PNG_ERROR: Status = ERR | 0x0700;
pub const GDK_ERROR: Status = ERR | 0x0800;
pub const GD_ERROR: Status = ERR | 0x0900;
pub const STBI_ERROR: Status = ERR | 0x0a00;
pub const STBIW_ERROR: Status = ERR | 0x0b00;
pub const INTERRUPTED: Status = OK | 0x0001;
pub const BAD_ALLOCATION: Status = RUNTIME_ERROR | 0x0001;
pub const BAD_ARGUMENT: Status = RUNTIME_ERROR | 0x0002;
pub const BAD_INPUT: Status = RUNTIME_ERROR | 0x0003;
pub const NOT_IMPLEMENTED: Status = FEATURE_ERROR | 0x0001;
}
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum CharacterSize {
SevenBit = 0,
EightBit = 1,
}
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum MethodForLargest {
Auto = 0,
Normal = 1,
Luminosity = 2,
}
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum MethodForRepColor {
Auto = 0,
CenterOfBox = 1,
AverageColor = 2,
AveragePixels = 3,
}
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum DiffusionMethod {
Auto = 0,
None = 1,
Atkinson = 2,
FS = 3,
JaJuNi = 4,
Stucki = 5,
Burkes = 6,
}
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum QualityMode {
Auto = 0,
High = 1,
Low = 2,
Full = 3,
HighColor = 4,
}
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum BuiltinDither {
MonoDark = 0,
MonoLight = 1,
XTerm16 = 2,
XTerm256 = 3,
VT340Mono = 4,
VT340Color = 5,
G1 = 6,
G2 = 7,
G4 = 8,
G8 = 9,
}
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum FormatType {
Color = 0,
Grayscale = 64,
Palette = 128,
}
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum PixelFormat {
RGB555 = FormatType::Color as isize | 0x01,
RGB565 = FormatType::Color as isize | 0x02,
RGB888 = FormatType::Color as isize | 0x03,
BGR555 = FormatType::Color as isize | 0x04,
BGR565 = FormatType::Color as isize | 0x05,
BGR888 = FormatType::Color as isize | 0x06,
ARGB8888 = FormatType::Color as isize | 0x10,
RGBA8888 = FormatType::Color as isize | 0x11,
ABGR8888 = FormatType::Color as isize | 0x12,
BGRA8888 = FormatType::Color as isize | 0x13,
G1 = FormatType::Grayscale as isize | 0x00,
G2 = FormatType::Grayscale as isize | 0x01,
G4 = FormatType::Grayscale as isize | 0x02,
G8 = FormatType::Grayscale as isize | 0x03,
AG88 = FormatType::Grayscale as isize | 0x13,
GA88 = FormatType::Grayscale as isize | 0x23,
Pal1 = FormatType::Palette as isize | 0x00,
Pal2 = FormatType::Palette as isize | 0x01,
Pal4 = FormatType::Palette as isize | 0x02,
Pal8 = FormatType::Palette as isize | 0x03,
}
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum PaletteType {
Auto = 0,
HLS = 1,
RGB = 2,
}
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum EncodePolicy {
Auto = 0,
Fast = 1,
Size = 2,
}
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum ResamplingMethod {
Nearest = 0,
Gaussian = 1,
Hanning = 2,
Hamming = 3,
Bilinear = 4,
Welsh = 5,
Bicubic = 6,
Lanczos2 = 7,
Lanczos3 = 8,
Lanczos4 = 9,
}
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum ImageFormat {
GIF = 0,
PNG = 1,
BMP = 2,
JPG = 3,
TGA = 4,
WBMP = 5,
TIFF = 6,
SIXEL = 7,
PNM = 8,
GD2 = 9,
PSD = 10,
HDR = 11,
}
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum LoopMode {
Auto = 0,
Force = 1,
Disable = 2,
}
#[repr(u8)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum DecoderOptflag {
Input = b'i',
Output = b'o',
}
#[repr(u8)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum Optflag {
OutFile = b'o',
UseSevenBitMode = b'7',
UseEightBitMode = b'8',
HasGRIArgLimit = b'R',
NumColors = b'p',
Mapfile = b'm',
Monochrome = b'e',
Insecure = b'k',
InvertBackground = b'i',
UseHighColor = b'I',
UseMacro = b'u',
MacroNumber = b'n',
ComplexionScore = b'C',
IgnoreGIFDelay = b'g',
StaticGIF = b'S',
Diffusion = b'd',
FindLargest = b'f',
SelectColor = b's',
CropRegion = b'c',
Width = b'w',
Height = b'h',
Resampling = b'r',
QualityMode = b'q',
LoopMode = b'l',
PaletteType = b't',
BuiltinPalette = b'b',
EncodingPolicy = b'E',
BackgroundColor = b'B',
PenetrateScreen = b'P',
PipeInput = b'D',
Verbose = b'v',
Version = b'V',
Help = b'H',
}
pub type MallocFn = Option<unsafe extern "C" fn(size: usize) -> *mut c_void>;
pub type CallocFn = Option<unsafe extern "C" fn(num_items: usize, size: usize) -> *mut c_void>;
pub type ReallocFn = Option<unsafe extern "C" fn(object: *mut c_void, new_size: usize)
-> *mut c_void>;
pub type FreeFn = Option<unsafe extern "C" fn(object: *mut c_void)>;
pub enum Allocator {}
extern "C" {
pub fn sixel_allocator_new(ppallocator: *mut *mut Allocator,
fn_malloc: MallocFn,
fn_calloc: CallocFn,
fn_realloc: ReallocFn,
fn_free: FreeFn)
-> Status;
pub fn sixel_allocator_ref(allocator: *mut Allocator);
pub fn sixel_allocator_unref(allocator: *mut Allocator);
pub fn sixel_allocator_malloc(allocator: *mut Allocator, n: usize) -> *mut c_void;
pub fn sixel_allocator_calloc(allocator: *mut Allocator,
nelm: usize,
elsize: usize)
-> *mut c_void;
pub fn sixel_allocator_realloc(allocator: *mut Allocator,
p: *mut c_void,
n: usize)
-> *mut c_void;
pub fn sixel_allocator_free(allocator: *mut Allocator, p: *mut c_void);
}
pub enum Output {}
pub type WriteFn = ::std::option::Option<unsafe extern "C" fn(data: *mut c_char,
size: c_int,
priv_: *mut c_void)
-> c_int>;
extern "C" {
pub fn sixel_output_new(output: *mut *mut Output,
fn_write: WriteFn,
priv_: *mut c_void,
allocator: *mut Allocator)
-> Status;
pub fn sixel_output_create(fn_write: WriteFn, priv_: *mut c_void) -> *mut Output;
pub fn sixel_output_destroy(output: *mut Output);
pub fn sixel_output_ref(output: *mut Output);
pub fn sixel_output_unref(output: *mut Output);
pub fn sixel_output_get_8bit_availability(output: *mut Output) -> c_int;
pub fn sixel_output_set_8bit_availability(output: *mut Output, availability: CharacterSize);
pub fn sixel_output_set_gri_arg_limit(output: *mut Output, value: c_int);
pub fn sixel_output_set_penetrate_multiplexer(output: *mut Output, penetrate: c_int);
pub fn sixel_output_set_skip_dcs_envelope(output: *mut Output, skip: c_int);
pub fn sixel_output_set_palette_type(output: *mut Output, palettetype: PaletteType);
pub fn sixel_output_set_encode_policy(output: *mut Output, encode_policy: EncodePolicy);
}
pub enum Dither {}
extern "C" {
pub fn sixel_dither_new(ppdither: *mut *mut Dither,
ncolors: c_int,
allocator: *mut Allocator)
-> Status;
pub fn sixel_dither_create(ncolors: c_int) -> *mut Dither;
pub fn sixel_dither_get(builtin_dither: BuiltinDither) -> *mut Dither;
pub fn sixel_dither_destroy(dither: *mut Dither);
pub fn sixel_dither_ref(dither: *mut Dither);
pub fn sixel_dither_unref(dither: *mut Dither);
pub fn sixel_dither_initialize(dither: *mut Dither,
data: *mut c_uchar,
width: c_int,
height: c_int,
pixelformat: PixelFormat,
method_for_largest: MethodForLargest,
method_for_rep: MethodForRepColor,
quality_mode: QualityMode)
-> Status;
pub fn sixel_dither_set_diffusion_type(dither: *mut Dither,
method_for_diffuse: DiffusionMethod);
pub fn sixel_dither_get_num_of_palette_colors(dither: *mut Dither) -> c_int;
pub fn sixel_dither_get_num_of_histogram_colors(dither: *mut Dither) -> c_int;
pub fn sixel_dither_get_num_of_histgram_colors(dither: *mut Dither) -> c_int;
pub fn sixel_dither_get_palette(dither: *mut Dither) -> *mut c_uchar;
pub fn sixel_dither_set_palette(dither: *mut Dither, palette: *mut c_uchar);
pub fn sixel_dither_set_complexion_score(dither: *mut Dither, score: c_int);
pub fn sixel_dither_set_body_only(dither: *mut Dither, bodyonly: c_int);
pub fn sixel_dither_set_optimize_palette(dither: *mut Dither, do_opt: c_int);
pub fn sixel_dither_set_pixelformat(dither: *mut Dither, pixelformat: PixelFormat);
pub fn sixel_dither_set_transparent(dither: *mut Dither, transparent: c_int);
}
extern "C" {
pub fn sixel_encode(pixels: *mut c_uchar,
width: c_int,
height: c_int,
depth: c_int,
dither: *mut Dither,
context: *mut Output)
-> Status;
pub fn sixel_decode_raw(p: *mut c_uchar,
len: c_int,
pixels: *mut *mut c_uchar,
pwidth: *mut c_int,
pheight: *mut c_int,
palette: *mut *mut c_uchar,
ncolors: *mut c_int,
allocator: *mut Allocator)
-> Status;
pub fn sixel_decode(sixels: *mut c_uchar,
size: c_int,
pixels: *mut *mut c_uchar,
pwidth: *mut c_int,
pheight: *mut c_int,
palette: *mut *mut c_uchar,
ncolors: *mut c_int,
fn_malloc: MallocFn)
-> Status;
}
extern "C" {
pub fn sixel_helper_set_additional_message(message: *const c_char);
pub fn sixel_helper_get_additional_message() -> *const c_char;
pub fn sixel_helper_format_error(status: Status) -> *const c_char;
pub fn sixel_helper_compute_depth(pixelformat: PixelFormat) -> c_int;
pub fn sixel_helper_normalize_pixelformat(dst: *mut c_uchar,
dst_pixelformat: *mut PixelFormat,
src: *const c_uchar,
src_pixelformat: PixelFormat,
width: c_int,
height: c_int)
-> Status;
pub fn sixel_helper_scale_image(dst: *mut c_uchar,
src: *const c_uchar,
srcw: c_int,
srch: c_int,
pixelformat: PixelFormat,
dstw: c_int,
dsth: c_int,
method_for_resampling: ResamplingMethod,
allocator: *mut Allocator)
-> Status;
}
pub enum Frame {}
extern "C" {
pub fn sixel_frame_new(ppframe: *mut *mut Frame, allocator: *mut Allocator) -> Status;
pub fn sixel_frame_create() -> *mut Frame;
pub fn sixel_frame_ref(frame: *mut Frame);
pub fn sixel_frame_unref(frame: *mut Frame);
pub fn sixel_frame_init(frame: *mut Frame,
pixels: *mut c_uchar,
width: c_int,
height: c_int,
pixelformat: PixelFormat,
palette: *mut c_uchar,
ncolors: c_int)
-> Status;
pub fn sixel_frame_get_pixels(frame: *mut Frame) -> *mut c_uchar;
pub fn sixel_frame_get_palette(frame: *mut Frame) -> *mut c_uchar;
pub fn sixel_frame_get_width(frame: *mut Frame) -> c_int;
pub fn sixel_frame_get_height(frame: *mut Frame) -> c_int;
pub fn sixel_frame_get_ncolors(frame: *mut Frame) -> c_int;
pub fn sixel_frame_get_pixelformat(frame: *mut Frame) -> c_int;
pub fn sixel_frame_get_transparent(frame: *mut Frame) -> c_int;
pub fn sixel_frame_get_multiframe(frame: *mut Frame) -> c_int;
pub fn sixel_frame_get_delay(frame: *mut Frame) -> c_int;
pub fn sixel_frame_get_frame_no(frame: *mut Frame) -> c_int;
pub fn sixel_frame_get_loop_no(frame: *mut Frame) -> c_int;
pub fn sixel_frame_strip_alpha(frame: *mut Frame, bgcolor: *mut c_uchar) -> c_int;
pub fn sixel_frame_resize(frame: *mut Frame,
width: c_int,
height: c_int,
method_for_resampling: ResamplingMethod)
-> Status;
pub fn sixel_frame_clip(frame: *mut Frame,
x: c_int,
y: c_int,
width: c_int,
height: c_int)
-> Status;
}
pub type LoadImageFn = Option<unsafe extern "C" fn(frame: *mut Frame, context: *mut c_void)
-> Status>;
extern "C" {
pub fn sixel_helper_load_image_file(filename: *const c_char,
fstatic: c_int,
fuse_palette: c_int,
reqcolors: c_int,
bgcolor: *mut c_uchar,
loop_control: LoopMode,
fn_load: LoadImageFn,
finsecure: c_int,
cancel_flag: *const c_int,
context: *mut c_void,
allocator: *mut Allocator)
-> Status;
pub fn sixel_helper_write_image_file(data: *mut c_uchar,
width: c_int,
height: c_int,
palette: *mut c_uchar,
pixelformat: PixelFormat,
filename: *const c_char,
imageformat: ImageFormat,
allocator: *mut Allocator)
-> Status;
}
pub enum Encoder {}
extern "C" {
pub fn sixel_encoder_new(ppencoder: *mut *mut Encoder, allocator: *mut Allocator) -> Status;
pub fn sixel_encoder_create() -> *mut Encoder;
pub fn sixel_encoder_ref(encoder: *mut Encoder);
pub fn sixel_encoder_unref(encoder: *mut Encoder);
pub fn sixel_encoder_set_cancel_flag(encoder: *mut Encoder, cancel_flag: *mut c_int) -> Status;
pub fn sixel_encoder_setopt(encoder: *mut Encoder,
arg: Optflag,
optarg: *const c_char)
-> Status;
pub fn sixel_encoder_encode(encoder: *mut Encoder, filename: *const c_char) -> Status;
pub fn sixel_encoder_encode_bytes(encoder: *mut Encoder,
bytes: *mut c_uchar,
width: c_int,
height: c_int,
pixelformat: PixelFormat,
palette: *mut c_uchar,
ncolors: c_int)
-> Status;
}
pub enum Decoder {}
extern "C" {
pub fn sixel_decoder_new(ppdecoder: *mut *mut Decoder, allocator: *mut Allocator) -> Status;
pub fn sixel_decoder_create() -> *mut Decoder;
pub fn sixel_decoder_ref(decoder: *mut Decoder);
pub fn sixel_decoder_unref(decoder: *mut Decoder);
pub fn sixel_decoder_setopt(decoder: *mut Decoder,
arg: DecoderOptflag,
optarg: *const c_char)
-> Status;
pub fn sixel_decoder_decode(decoder: *mut Decoder) -> Status;
}