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