ohmu
·
2026-10-15
1/*
2 * Copyright (c) 2014-2020 Hayaki Saito
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy of
5 * this software and associated documentation files (the "Software"), to deal in
6 * the Software without restriction, including without limitation the rights to
7 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8 * the Software, and to permit persons to whom the Software is furnished to do so,
9 * subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in all
12 * copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 */
21
22#include <stddef.h> /* for size_t */
23
24#ifndef LIBSIXEL_SIXEL_H
25#define LIBSIXEL_SIXEL_H
26
27/*
28 * fastfetch: upstream defines this as `__declspec(dllexport)` on Windows, but
29 * this vendored subset is compiled into libfastfetch statically rather than
30 * into a standalone DLL. Keeping the attribute would (a) add every libsixel
31 * symbol to fastfetch's export table and (b) make these declarations disagree
32 * with the ones in dither.h / output.h / quant.h / allocator.h, which do not
33 * carry it (clang: -Wdll-attribute-on-redeclaration).
34 * Re-apply this change when re-syncing with upstream.
35 */
36#define SIXELAPI
37
38#define LIBSIXEL_VERSION "1.8.7-r2"
39#define LIBSIXEL_ABI_VERSION "1:6:0"
40
41typedef unsigned char sixel_index_t;
42
43/* limitations */
44#define SIXEL_OUTPUT_PACKET_SIZE 16384
45#define SIXEL_PALETTE_MIN 2
46#define SIXEL_PALETTE_MAX 256
47#define SIXEL_USE_DEPRECATED_SYMBOLS 1
48#define SIXEL_ALLOCATE_BYTES_MAX 10248UL * 1024UL * 128UL /* up to 128M */
49#define SIXEL_WIDTH_LIMIT 1000000
50#define SIXEL_HEIGHT_LIMIT 1000000
51
52/* loader settings */
53#define SIXEL_DEFALUT_GIF_DELAY 1
54
55/* return value */
56typedef int SIXELSTATUS;
57#define SIXEL_OK 0x0000 /* succeeded */
58#define SIXEL_FALSE 0x1000 /* failed */
59
60#define SIXEL_RUNTIME_ERROR (SIXEL_FALSE | 0x0100) /* runtime error */
61#define SIXEL_LOGIC_ERROR (SIXEL_FALSE | 0x0200) /* logic error */
62#define SIXEL_FEATURE_ERROR (SIXEL_FALSE | 0x0300) /* feature not enabled */
63#define SIXEL_LIBC_ERROR (SIXEL_FALSE | 0x0400) /* errors caused by curl */
64#define SIXEL_CURL_ERROR (SIXEL_FALSE | 0x0500) /* errors occures in libc functions */
65#define SIXEL_JPEG_ERROR (SIXEL_FALSE | 0x0600) /* errors occures in libjpeg functions */
66#define SIXEL_PNG_ERROR (SIXEL_FALSE | 0x0700) /* errors occures in libpng functions */
67#define SIXEL_GDK_ERROR (SIXEL_FALSE | 0x0800) /* errors occures in gdk functions */
68#define SIXEL_GD_ERROR (SIXEL_FALSE | 0x0900) /* errors occures in gd functions */
69#define SIXEL_STBI_ERROR (SIXEL_FALSE | 0x0a00) /* errors occures in stb_image functions */
70#define SIXEL_STBIW_ERROR (SIXEL_FALSE | 0x0b00) /* errors occures in stb_image_write functions */
71
72#define SIXEL_INTERRUPTED (SIXEL_OK | 0x0001) /* interrupted by a signal */
73
74#define SIXEL_BAD_ALLOCATION (SIXEL_RUNTIME_ERROR | 0x0001) /* malloc() failed */
75#define SIXEL_BAD_ARGUMENT (SIXEL_RUNTIME_ERROR | 0x0002) /* bad argument detected */
76#define SIXEL_BAD_INPUT (SIXEL_RUNTIME_ERROR | 0x0003) /* bad input detected */
77#define SIXEL_BAD_INTEGER_OVERFLOW (SIXEL_RUNTIME_ERROR | 0x0004) /* integer overflow */
78
79#define SIXEL_NOT_IMPLEMENTED (SIXEL_FEATURE_ERROR | 0x0001) /* feature not implemented */
80
81#define SIXEL_SUCCEEDED(status) (((status) & 0x1000) == 0)
82#define SIXEL_FAILED(status) (((status) & 0x1000) != 0)
83
84/* method for finding the largest dimension for splitting,
85 * and sorting by that component */
86#define SIXEL_LARGE_AUTO 0x0 /* choose automatically the method for finding the largest
87 dimension */
88#define SIXEL_LARGE_NORM 0x1 /* simply comparing the range in RGB space */
89#define SIXEL_LARGE_LUM 0x2 /* transforming into luminosities before the comparison */
90
91/* method for choosing a color from the box */
92#define SIXEL_REP_AUTO 0x0 /* choose automatically the method for selecting
93 representative color from each box */
94#define SIXEL_REP_CENTER_BOX 0x1 /* choose the center of the box */
95#define SIXEL_REP_AVERAGE_COLORS 0x2 /* choose the average all the color
96 in the box (specified in Heckbert's paper) */
97#define SIXEL_REP_AVERAGE_PIXELS 0x3 /* choose the average all the pixels in the box */
98
99/* method for diffusing */
100#define SIXEL_DIFFUSE_AUTO 0x0 /* choose diffusion type automatically */
101#define SIXEL_DIFFUSE_NONE 0x1 /* don't diffuse */
102#define SIXEL_DIFFUSE_ATKINSON 0x2 /* diffuse with Bill Atkinson's method */
103#define SIXEL_DIFFUSE_FS 0x3 /* diffuse with Floyd-Steinberg method */
104#define SIXEL_DIFFUSE_JAJUNI 0x4 /* diffuse with Jarvis, Judice & Ninke method */
105#define SIXEL_DIFFUSE_STUCKI 0x5 /* diffuse with Stucki's method */
106#define SIXEL_DIFFUSE_BURKES 0x6 /* diffuse with Burkes' method */
107#define SIXEL_DIFFUSE_A_DITHER 0x7 /* positionally stable arithmetic dither */
108#define SIXEL_DIFFUSE_X_DITHER 0x8 /* positionally stable arithmetic xor based dither */
109
110/* quality modes */
111#define SIXEL_QUALITY_AUTO 0x0 /* choose quality mode automatically */
112#define SIXEL_QUALITY_HIGH 0x1 /* high quality palette construction */
113#define SIXEL_QUALITY_LOW 0x2 /* low quality palette construction */
114#define SIXEL_QUALITY_FULL 0x3 /* full quality palette construction */
115#define SIXEL_QUALITY_HIGHCOLOR 0x4 /* high color */
116
117/* built-in dither */
118#define SIXEL_BUILTIN_MONO_DARK 0x0 /* monochrome terminal with dark background */
119#define SIXEL_BUILTIN_MONO_LIGHT 0x1 /* monochrome terminal with light background */
120#define SIXEL_BUILTIN_XTERM16 0x2 /* xterm 16color */
121#define SIXEL_BUILTIN_XTERM256 0x3 /* xterm 256color */
122#define SIXEL_BUILTIN_VT340_MONO 0x4 /* vt340 monochrome */
123#define SIXEL_BUILTIN_VT340_COLOR 0x5 /* vt340 color */
124#define SIXEL_BUILTIN_G1 0x6 /* 1bit grayscale */
125#define SIXEL_BUILTIN_G2 0x7 /* 2bit grayscale */
126#define SIXEL_BUILTIN_G4 0x8 /* 4bit grayscale */
127#define SIXEL_BUILTIN_G8 0x9 /* 8bit grayscale */
128
129/* offset value of pixelFormat */
130#define SIXEL_FORMATTYPE_COLOR (0)
131#define SIXEL_FORMATTYPE_GRAYSCALE (1 << 6)
132#define SIXEL_FORMATTYPE_PALETTE (1 << 7)
133
134/* pixelformat type of input image
135 NOTE: for compatibility, the value of PIXELFORAMT_COLOR_RGB888 must be 3 */
136#define SIXEL_PIXELFORMAT_RGB555 (SIXEL_FORMATTYPE_COLOR | 0x01) /* 15bpp */
137#define SIXEL_PIXELFORMAT_RGB565 (SIXEL_FORMATTYPE_COLOR | 0x02) /* 16bpp */
138#define SIXEL_PIXELFORMAT_RGB888 (SIXEL_FORMATTYPE_COLOR | 0x03) /* 24bpp */
139#define SIXEL_PIXELFORMAT_BGR555 (SIXEL_FORMATTYPE_COLOR | 0x04) /* 15bpp */
140#define SIXEL_PIXELFORMAT_BGR565 (SIXEL_FORMATTYPE_COLOR | 0x05) /* 16bpp */
141#define SIXEL_PIXELFORMAT_BGR888 (SIXEL_FORMATTYPE_COLOR | 0x06) /* 24bpp */
142#define SIXEL_PIXELFORMAT_ARGB8888 (SIXEL_FORMATTYPE_COLOR | 0x10) /* 32bpp */
143#define SIXEL_PIXELFORMAT_RGBA8888 (SIXEL_FORMATTYPE_COLOR | 0x11) /* 32bpp */
144#define SIXEL_PIXELFORMAT_ABGR8888 (SIXEL_FORMATTYPE_COLOR | 0x12) /* 32bpp */
145#define SIXEL_PIXELFORMAT_BGRA8888 (SIXEL_FORMATTYPE_COLOR | 0x13) /* 32bpp */
146#define SIXEL_PIXELFORMAT_G1 (SIXEL_FORMATTYPE_GRAYSCALE | 0x00) /* 1bpp grayscale */
147#define SIXEL_PIXELFORMAT_G2 (SIXEL_FORMATTYPE_GRAYSCALE | 0x01) /* 2bpp grayscale */
148#define SIXEL_PIXELFORMAT_G4 (SIXEL_FORMATTYPE_GRAYSCALE | 0x02) /* 4bpp grayscale */
149#define SIXEL_PIXELFORMAT_G8 (SIXEL_FORMATTYPE_GRAYSCALE | 0x03) /* 8bpp grayscale */
150#define SIXEL_PIXELFORMAT_AG88 (SIXEL_FORMATTYPE_GRAYSCALE | 0x13) /* 16bpp gray+alpha */
151#define SIXEL_PIXELFORMAT_GA88 (SIXEL_FORMATTYPE_GRAYSCALE | 0x23) /* 16bpp gray+alpha */
152#define SIXEL_PIXELFORMAT_PAL1 (SIXEL_FORMATTYPE_PALETTE | 0x00) /* 1bpp palette */
153#define SIXEL_PIXELFORMAT_PAL2 (SIXEL_FORMATTYPE_PALETTE | 0x01) /* 2bpp palette */
154#define SIXEL_PIXELFORMAT_PAL4 (SIXEL_FORMATTYPE_PALETTE | 0x02) /* 4bpp palette */
155#define SIXEL_PIXELFORMAT_PAL8 (SIXEL_FORMATTYPE_PALETTE | 0x03) /* 8bpp palette */
156
157/* palette type */
158#define SIXEL_PALETTETYPE_AUTO 0 /* choose palette type automatically */
159#define SIXEL_PALETTETYPE_HLS 1 /* HLS colorspace */
160#define SIXEL_PALETTETYPE_RGB 2 /* RGB colorspace */
161
162/* policies of SIXEL encoding */
163#define SIXEL_ENCODEPOLICY_AUTO 0 /* choose encoding policy automatically */
164#define SIXEL_ENCODEPOLICY_FAST 1 /* encode as fast as possible */
165#define SIXEL_ENCODEPOLICY_SIZE 2 /* encode to as small sixel sequence as possible */
166
167/* method for re-sampling */
168#define SIXEL_RES_NEAREST 0 /* Use nearest neighbor method */
169#define SIXEL_RES_GAUSSIAN 1 /* Use guaussian filter */
170#define SIXEL_RES_HANNING 2 /* Use hanning filter */
171#define SIXEL_RES_HAMMING 3 /* Use hamming filter */
172#define SIXEL_RES_BILINEAR 4 /* Use bilinear filter */
173#define SIXEL_RES_WELSH 5 /* Use welsh filter */
174#define SIXEL_RES_BICUBIC 6 /* Use bicubic filter */
175#define SIXEL_RES_LANCZOS2 7 /* Use lanczos-2 filter */
176#define SIXEL_RES_LANCZOS3 8 /* Use lanczos-3 filter */
177#define SIXEL_RES_LANCZOS4 9 /* Use lanczos-4 filter */
178
179/* image format */
180#define SIXEL_FORMAT_GIF 0x0 /* read only */
181#define SIXEL_FORMAT_PNG 0x1 /* read/write */
182#define SIXEL_FORMAT_BMP 0x2 /* read only */
183#define SIXEL_FORMAT_JPG 0x3 /* read only */
184#define SIXEL_FORMAT_TGA 0x4 /* read only */
185#define SIXEL_FORMAT_WBMP 0x5 /* read only with --with-gd configure option */
186#define SIXEL_FORMAT_TIFF 0x6 /* read only */
187#define SIXEL_FORMAT_SIXEL 0x7 /* read only */
188#define SIXEL_FORMAT_PNM 0x8 /* read only */
189#define SIXEL_FORMAT_GD2 0x9 /* read only with --with-gd configure option */
190#define SIXEL_FORMAT_PSD 0xa /* read only */
191#define SIXEL_FORMAT_HDR 0xb /* read only */
192
193/* loop mode */
194#define SIXEL_LOOP_AUTO 0 /* honer the setting of GIF header */
195#define SIXEL_LOOP_FORCE 1 /* always enable loop */
196#define SIXEL_LOOP_DISABLE 2 /* always disable loop */
197
198/* setopt flags */
199#define SIXEL_OPTFLAG_INPUT ('i') /* -i, --input: specify input file name. */
200#define SIXEL_OPTFLAG_OUTPUT ('o') /* -o, --output: specify output file name. */
201#define SIXEL_OPTFLAG_OUTFILE ('o') /* -o, --outfile: specify output file name. */
202#define SIXEL_OPTFLAG_7BIT_MODE ('7') /* -7, --7bit-mode: for 7bit terminals or printers (default) */
203#define SIXEL_OPTFLAG_8BIT_MODE ('8') /* -8, --8bit-mode: for 8bit terminals or printers */
204#define SIXEL_OPTFLAG_HAS_GRI_ARG_LIMIT ('R') /* -R, --gri-limit: limit arguments of DECGRI('!') to 255 */
205#define SIXEL_OPTFLAG_COLORS ('p') /* -p COLORS, --colors=COLORS: specify number of colors */
206#define SIXEL_OPTFLAG_MAPFILE ('m') /* -m FILE, --mapfile=FILE: specify set of colors */
207#define SIXEL_OPTFLAG_MONOCHROME ('e') /* -e, --monochrome: output monochrome sixel image */
208#define SIXEL_OPTFLAG_INSECURE ('k') /* -k, --insecure: allow to connect to SSL sites without certs */
209#define SIXEL_OPTFLAG_INVERT ('i') /* -i, --invert: assume the terminal background color */
210#define SIXEL_OPTFLAG_HIGH_COLOR ('I') /* -I, --high-color: output 15bpp sixel image */
211#define SIXEL_OPTFLAG_USE_MACRO ('u') /* -u, --use-macro: use DECDMAC and DEVINVM sequences */
212#define SIXEL_OPTFLAG_MACRO_NUMBER ('n') /* -n MACRONO, --macro-number=MACRONO:
213 specify macro register number */
214#define SIXEL_OPTFLAG_COMPLEXION_SCORE ('C') /* -C COMPLEXIONSCORE, --complexion-score=COMPLEXIONSCORE:
215 specify an number argument for the score of
216 complexion correction. */
217#define SIXEL_OPTFLAG_IGNORE_DELAY ('g') /* -g, --ignore-delay: render GIF animation without delay */
218#define SIXEL_OPTFLAG_STATIC ('S') /* -S, --static: render animated GIF as a static image */
219#define SIXEL_OPTFLAG_DIFFUSION ('d') /* -d DIFFUSIONTYPE, --diffusion=DIFFUSIONTYPE:
220 choose diffusion method which used with -p option.
221 DIFFUSIONTYPE is one of them:
222 auto -> choose diffusion type
223 automatically (default)
224 none -> do not diffuse
225 fs -> Floyd-Steinberg method
226 atkinson -> Bill Atkinson's method
227 jajuni -> Jarvis, Judice & Ninke
228 stucki -> Stucki's method
229 burkes -> Burkes' method
230 a_dither -> positionally stable
231 arithmetic dither
232 a_dither -> positionally stable
233 arithmetic xor based dither
234 */
235#define SIXEL_OPTFLAG_FIND_LARGEST ('f') /* -f FINDTYPE, --find-largest=FINDTYPE:
236 choose method for finding the largest
237 dimension of median cut boxes for
238 splitting, make sense only when -p
239 option (color reduction) is
240 specified
241 FINDTYPE is one of them:
242 auto -> choose finding method
243 automatically (default)
244 norm -> simply comparing the
245 range in RGB space
246 lum -> transforming into
247 luminosities before the
248 comparison
249 */
250#define SIXEL_OPTFLAG_SELECT_COLOR ('s') /* -s SELECTTYPE, --select-color=SELECTTYPE
251 choose the method for selecting
252 representative color from each
253 median-cut box, make sense only
254 when -p option (color reduction) is
255 specified
256 SELECTTYPE is one of them:
257 auto -> choose selecting
258 method automatically
259 (default)
260 center -> choose the center of
261 the box
262 average -> calculate the color
263 average into the box
264 histogram -> similar with average
265 but considers color
266 histogram
267 */
268#define SIXEL_OPTFLAG_CROP ('c') /* -c REGION, --crop=REGION:
269 crop source image to fit the
270 specified geometry. REGION should
271 be formatted as '%dx%d+%d+%d'
272 */
273#define SIXEL_OPTFLAG_WIDTH ('w') /* -w WIDTH, --width=WIDTH:
274 resize image to specified width
275 WIDTH is represented by the
276 following syntax
277 auto -> preserving aspect
278 ratio (default)
279 <number>% -> scale width with
280 given percentage
281 <number> -> scale width with
282 pixel counts
283 <number>px -> scale width with
284 pixel counts
285 */
286#define SIXEL_OPTFLAG_HEIGHT ('h') /* -h HEIGHT, --height=HEIGHT:
287 resize image to specified height
288 HEIGHT is represented by the
289 following syntax
290 auto -> preserving aspect
291 ratio (default)
292 <number>% -> scale height with
293 given percentage
294 <number> -> scale height with
295 pixel counts
296 <number>px -> scale height with
297 pixel counts
298 */
299#define SIXEL_OPTFLAG_RESAMPLING ('r') /* -r RESAMPLINGTYPE, --resampling=RESAMPLINGTYPE:
300 choose resampling filter used
301 with -w or -h option (scaling)
302 RESAMPLINGTYPE is one of them:
303 nearest -> Nearest-Neighbor
304 method
305 gaussian -> Gaussian filter
306 hanning -> Hanning filter
307 hamming -> Hamming filter
308 bilinear -> Bilinear filter
309 (default)
310 welsh -> Welsh filter
311 bicubic -> Bicubic filter
312 lanczos2 -> Lanczos-2 filter
313 lanczos3 -> Lanczos-3 filter
314 lanczos4 -> Lanczos-4 filter
315 */
316#define SIXEL_OPTFLAG_QUALITY ('q') /* -q QUALITYMODE, --quality=QUALITYMODE:
317 select quality of color
318 quanlization.
319 auto -> decide quality mode
320 automatically (default)
321 low -> low quality and high
322 speed mode
323 high -> high quality and low
324 speed mode
325 full -> full quality and careful
326 speed mode
327 */
328#define SIXEL_OPTFLAG_LOOPMODE ('l') /* -l LOOPMODE, --loop-control=LOOPMODE:
329 select loop control mode for GIF
330 animation.
331 auto -> honor the setting of
332 GIF header (default)
333 force -> always enable loop
334 disable -> always disable loop
335 */
336#define SIXEL_OPTFLAG_PALETTE_TYPE ('t') /* -t PALETTETYPE, --palette-type=PALETTETYPE:
337 select palette color space type
338 auto -> choose palette type
339 automatically (default)
340 hls -> use HLS color space
341 rgb -> use RGB color space
342 */
343#define SIXEL_OPTFLAG_BUILTIN_PALETTE ('b') /* -b BUILTINPALETTE, --builtin-palette=BUILTINPALETTE:
344 select built-in palette type
345 xterm16 -> X default 16 color map
346 xterm256 -> X default 256 color map
347 vt340mono -> VT340 monochrome map
348 vt340color -> VT340 color map
349 gray1 -> 1bit grayscale map
350 gray2 -> 2bit grayscale map
351 gray4 -> 4bit grayscale map
352 gray8 -> 8bit grayscale map
353 */
354#define SIXEL_OPTFLAG_ENCODE_POLICY ('E') /* -E ENCODEPOLICY, --encode-policy=ENCODEPOLICY:
355 select encoding policy
356 auto -> choose encoding policy
357 automatically (default)
358 fast -> encode as fast as possible
359 size -> encode to as small sixel
360 sequence as possible
361 */
362#define SIXEL_OPTFLAG_BGCOLOR ('B') /* -B BGCOLOR, --bgcolor=BGCOLOR:
363 specify background color
364 BGCOLOR is represented by the
365 following syntax
366 #rgb
367 #rrggbb
368 #rrrgggbbb
369 #rrrrggggbbbb
370 rgb:r/g/b
371 rgb:rr/gg/bb
372 rgb:rrr/ggg/bbb
373 rgb:rrrr/gggg/bbbb
374 */
375#define SIXEL_OPTFLAG_PENETRATE ('P') /* -P, --penetrate:
376 penetrate GNU Screen using DCS
377 pass-through sequence */
378#define SIXEL_OPTFLAG_PIPE_MODE ('D') /* -D, --pipe-mode: (deprecated)
379 read source images from stdin continuously */
380#define SIXEL_OPTFLAG_VERBOSE ('v') /* -v, --verbose: show debugging info */
381#define SIXEL_OPTFLAG_VERSION ('V') /* -V, --version: show version and license info */
382#define SIXEL_OPTFLAG_HELP ('H') /* -H, --help: show this help */
383
384#if SIXEL_USE_DEPRECATED_SYMBOLS
385/* output character size */
386enum characterSize {
387 CSIZE_7BIT = 0, /* 7bit character */
388 CSIZE_8BIT = 1 /* 8bit character */
389};
390
391/* method for finding the largest dimension for splitting,
392 * and sorting by that component */
393enum methodForLargest {
394 LARGE_AUTO = 0, /* choose automatically the method for finding the largest
395 dimension */
396 LARGE_NORM = 1, /* simply comparing the range in RGB space */
397 LARGE_LUM = 2 /* transforming into luminosities before the comparison */
398};
399
400/* method for choosing a color from the box */
401enum methodForRep {
402 REP_AUTO = 0, /* choose automatically the method for selecting
403 representative color from each box */
404 REP_CENTER_BOX = 1, /* choose the center of the box */
405 REP_AVERAGE_COLORS = 2, /* choose the average all the color
406 in the box (specified in Heckbert's paper) */
407 REP_AVERAGE_PIXELS = 3 /* choose the average all the pixels in the box */
408};
409
410/* method for diffusing */
411enum methodForDiffuse {
412 DIFFUSE_AUTO = 0, /* choose diffusion type automatically */
413 DIFFUSE_NONE = 1, /* don't diffuse */
414 DIFFUSE_ATKINSON = 2, /* diffuse with Bill Atkinson's method */
415 DIFFUSE_FS = 3, /* diffuse with Floyd-Steinberg method */
416 DIFFUSE_JAJUNI = 4, /* diffuse with Jarvis, Judice & Ninke method */
417 DIFFUSE_STUCKI = 5, /* diffuse with Stucki's method */
418 DIFFUSE_BURKES = 6, /* diffuse with Burkes' method */
419 DIFFUSE_A_DITHER = 7, /* positionally stable arithmetic dither */
420 DIFFUSE_X_DITHER = 8 /* positionally stable arithmetic xor based dither */
421};
422
423/* quality modes */
424enum qualityMode {
425 QUALITY_AUTO = 0, /* choose quality mode automatically */
426 QUALITY_HIGH = 1, /* high quality palette construction */
427 QUALITY_LOW = 2, /* low quality palette construction */
428 QUALITY_FULL = 3, /* full quality palette construction */
429 QUALITY_HIGHCOLOR = 4 /* high color */
430};
431
432/* built-in dither */
433enum builtinDither {
434 BUILTIN_MONO_DARK = 0, /* monochrome terminal with dark background */
435 BUILTIN_MONO_LIGHT = 1, /* monochrome terminal with dark background */
436 BUILTIN_XTERM16 = 2, /* xterm 16color */
437 BUILTIN_XTERM256 = 3, /* xterm 256color */
438 BUILTIN_VT340_MONO = 4, /* vt340 monochrome */
439 BUILTIN_VT340_COLOR = 5 /* vt340 color */
440};
441
442/* offset value of enum pixelFormat */
443enum formatType {
444 FORMATTYPE_COLOR = 0,
445 FORMATTYPE_GRAYSCALE = 1 << 6,
446 FORMATTYPE_PALETTE = 1 << 7
447};
448
449/* pixelformat type of input image
450 NOTE: for compatibility, the value of PIXELFORAMT_COLOR_RGB888 must be 3 */
451enum pixelFormat {
452 PIXELFORMAT_RGB555 = FORMATTYPE_COLOR | 0x01, /* 15bpp */
453 PIXELFORMAT_RGB565 = FORMATTYPE_COLOR | 0x02, /* 16bpp */
454 PIXELFORMAT_RGB888 = FORMATTYPE_COLOR | 0x03, /* 24bpp */
455 PIXELFORMAT_BGR555 = FORMATTYPE_COLOR | 0x04, /* 15bpp */
456 PIXELFORMAT_BGR565 = FORMATTYPE_COLOR | 0x05, /* 16bpp */
457 PIXELFORMAT_BGR888 = FORMATTYPE_COLOR | 0x06, /* 24bpp */
458 PIXELFORMAT_ARGB8888 = FORMATTYPE_COLOR | 0x10, /* 32bpp */
459 PIXELFORMAT_RGBA8888 = FORMATTYPE_COLOR | 0x11, /* 32bpp */
460 PIXELFORMAT_G1 = FORMATTYPE_GRAYSCALE | 0x00, /* 1bpp grayscale */
461 PIXELFORMAT_G2 = FORMATTYPE_GRAYSCALE | 0x01, /* 2bpp grayscale */
462 PIXELFORMAT_G4 = FORMATTYPE_GRAYSCALE | 0x02, /* 4bpp grayscale */
463 PIXELFORMAT_G8 = FORMATTYPE_GRAYSCALE | 0x03, /* 8bpp grayscale */
464 PIXELFORMAT_AG88 = FORMATTYPE_GRAYSCALE | 0x13, /* 16bpp gray+alpha */
465 PIXELFORMAT_GA88 = FORMATTYPE_GRAYSCALE | 0x23, /* 16bpp gray+alpha */
466 PIXELFORMAT_PAL1 = FORMATTYPE_PALETTE | 0x00, /* 1bpp palette */
467 PIXELFORMAT_PAL2 = FORMATTYPE_PALETTE | 0x01, /* 2bpp palette */
468 PIXELFORMAT_PAL4 = FORMATTYPE_PALETTE | 0x02, /* 4bpp palette */
469 PIXELFORMAT_PAL8 = FORMATTYPE_PALETTE | 0x03 /* 8bpp palette */
470};
471
472/* palette type */
473enum paletteType {
474 PALETTETYPE_AUTO = 0, /* choose palette type automatically */
475 PALETTETYPE_HLS = 1, /* HLS colorspace */
476 PALETTETYPE_RGB = 2 /* RGB colorspace */
477};
478
479/* policies of SIXEL encoding */
480enum encodePolicy {
481 ENCODEPOLICY_AUTO = 0, /* choose encoding policy automatically */
482 ENCODEPOLICY_FAST = 1, /* encode as fast as possible */
483 ENCODEPOLICY_SIZE = 2 /* encode to as small sixel sequence as possible */
484};
485
486/* method for re-sampling */
487enum methodForResampling {
488 RES_NEAREST = 0, /* Use nearest neighbor method */
489 RES_GAUSSIAN = 1, /* Use guaussian filter */
490 RES_HANNING = 2, /* Use hanning filter */
491 RES_HAMMING = 3, /* Use hamming filter */
492 RES_BILINEAR = 4, /* Use bilinear filter */
493 RES_WELSH = 5, /* Use welsh filter */
494 RES_BICUBIC = 6, /* Use bicubic filter */
495 RES_LANCZOS2 = 7, /* Use lanczos-2 filter */
496 RES_LANCZOS3 = 8, /* Use lanczos-3 filter */
497 RES_LANCZOS4 = 9 /* Use lanczos-4 filter */
498};
499#endif
500
501typedef void *(* sixel_malloc_t)(size_t);
502typedef void *(* sixel_calloc_t)(size_t, size_t);
503typedef void *(* sixel_realloc_t)(void *, size_t);
504typedef void (* sixel_free_t)(void *);
505
506struct sixel_allocator;
507typedef struct sixel_allocator sixel_allocator_t;
508
509#ifdef __cplusplus
510extern "C" {
511#endif
512
513/* create allocator object */
514SIXELAPI SIXELSTATUS
515sixel_allocator_new(
516 sixel_allocator_t /* out */ **ppallocator, /* allocator object to be created */
517 sixel_malloc_t /* in */ fn_malloc, /* custom malloc() function */
518 sixel_calloc_t /* in */ fn_calloc, /* custom calloc() function */
519 sixel_realloc_t /* in */ fn_realloc, /* custom realloc() function */
520 sixel_free_t /* in */ fn_free); /* custom free() function */
521
522/* increase reference count of allocator object (thread-unsafe) */
523SIXELAPI void
524sixel_allocator_ref(
525 sixel_allocator_t /* in */ *allocator); /* allocator object to be
526 increment reference counter */
527
528/* decrease reference count of output context object (thread-unsafe) */
529SIXELAPI void
530sixel_allocator_unref(sixel_allocator_t *allocator);
531
532/* call custom malloc() */
533SIXELAPI void *
534sixel_allocator_malloc(
535 sixel_allocator_t /* in */ *allocator, /* allocator object */
536 size_t /* in */ n); /* allocation size */
537
538/* call custom calloc() */
539SIXELAPI void *
540sixel_allocator_calloc(
541 sixel_allocator_t /* in */ *allocator, /* allocator object */
542 size_t /* in */ nelm, /* allocation size */
543 size_t /* in */ elsize); /* allocation size */
544
545/* call custom realloc() */
546SIXELAPI void *
547sixel_allocator_realloc(
548 sixel_allocator_t /* in */ *allocator, /* allocator object */
549 void /* in */ *p, /* existing buffer to be re-allocated */
550 size_t /* in */ n); /* re-allocation size */
551
552/* call custom free() */
553SIXELAPI void
554sixel_allocator_free(
555 sixel_allocator_t /* in */ *allocator, /* allocator object */
556 void /* in */ *p); /* existing buffer to be freed */
557
558#ifdef HAVE_TESTS
559extern volatile int sixel_debug_malloc_counter;
560
561void *
562sixel_bad_malloc(size_t size);
563
564void *
565sixel_bad_calloc(size_t count, size_t size);
566
567void *
568sixel_bad_realloc(void *ptr, size_t size);
569#endif /* HAVE_TESTS */
570
571#ifdef __cplusplus
572}
573#endif
574
575/* output context manipulation API */
576
577struct sixel_output;
578typedef struct sixel_output sixel_output_t;
579typedef int (* sixel_write_function)(char *data, int size, void *priv);
580
581#ifdef __cplusplus
582extern "C" {
583#endif
584
585/* create new output context object */
586SIXELAPI SIXELSTATUS
587sixel_output_new(
588 sixel_output_t /* out */ **output, /* output object to be created */
589 sixel_write_function /* in */ fn_write, /* callback for output sixel */
590 void /* in */ *priv, /* private data given as
591 3rd argument of fn_write */
592 sixel_allocator_t /* in */ *allocator); /* allocator, null if you use
593 default allocator */
594
595/* deprecated: create an output object */
596SIXELAPI __attribute__((deprecated)) sixel_output_t *
597sixel_output_create(
598 sixel_write_function /* in */ fn_write, /* callback for output sixel */
599 void /* in */ *priv); /* private data given as
600 3rd argument of fn_write */
601/* destroy output context object */
602SIXELAPI void
603sixel_output_destroy(sixel_output_t /* in */ *output); /* output context */
604
605/* increase reference count of output context object (thread-unsafe) */
606SIXELAPI void
607sixel_output_ref(sixel_output_t /* in */ *output); /* output context */
608
609/* decrease reference count of output context object (thread-unsafe) */
610SIXELAPI void
611sixel_output_unref(sixel_output_t /* in */ *output); /* output context */
612
613/* get 8bit output mode which indicates whether it uses C1 control characters */
614SIXELAPI int
615sixel_output_get_8bit_availability(
616 sixel_output_t /* in */ *output); /* output context */
617
618/* set 8bit output mode state */
619SIXELAPI void
620sixel_output_set_8bit_availability(
621 sixel_output_t /* in */ *output, /* output context */
622 int /* in */ availability); /* 0: do not use 8bit characters
623 1: use 8bit characters */
624
625/* set whether limit arguments of DECGRI('!') to 255 */
626SIXELAPI void
627sixel_output_set_gri_arg_limit(
628 sixel_output_t /* in */ *output, /* output context */
629 int /* in */ value); /* 0: don't limit arguments of DECGRI
630 1: limit arguments of DECGRI to 255 */
631
632/* set GNU Screen penetration feature enable or disable */
633SIXELAPI void
634sixel_output_set_penetrate_multiplexer(
635 sixel_output_t /* in */ *output, /* output context */
636 int /* in */ penetrate); /* 0: penetrate GNU Screen
637 1: do not penetrate GNU Screen */
638
639/* set whether we skip DCS envelope */
640SIXELAPI void
641sixel_output_set_skip_dcs_envelope(
642 sixel_output_t /* in */ *output, /* output context */
643 int /* in */ skip); /* 0: output DCS envelope
644 1: do not output DCS envelope */
645
646/* set palette type: RGB or HLS */
647SIXELAPI void
648sixel_output_set_palette_type(
649 sixel_output_t /* in */ *output, /* output context */
650 int /* in */ palettetype); /* PALETTETYPE_RGB: RGB palette
651 PALETTETYPE_HLS: HLS palette */
652
653/* set encodeing policy: auto, fast or size */
654SIXELAPI void
655sixel_output_set_encode_policy(
656 sixel_output_t /* in */ *output, /* output context */
657 int /* in */ encode_policy);
658
659
660#ifdef __cplusplus
661}
662#endif
663
664
665/* color quantization API */
666
667/* handle type of dither context object */
668struct sixel_dither;
669typedef struct sixel_dither sixel_dither_t;
670
671#ifdef __cplusplus
672extern "C" {
673#endif
674
675/* create dither context object */
676SIXELAPI SIXELSTATUS
677sixel_dither_new(
678 sixel_dither_t /* out */ **ppdither, /* dither object to be created */
679 int /* in */ ncolors, /* required colors */
680 sixel_allocator_t /* in */ *allocator); /* allocator, null if you use
681 default allocator */
682
683/* create dither context object */
684SIXELAPI __attribute__((deprecated)) sixel_dither_t *
685sixel_dither_create(int /* in */ ncolors); /* number of colors */
686
687/* get built-in dither context object */
688SIXELAPI sixel_dither_t *
689sixel_dither_get(int builtin_dither); /* ID of built-in dither object */
690
691/* destroy dither context object */
692SIXELAPI void
693sixel_dither_destroy(sixel_dither_t *dither); /* dither context object */
694
695/* increase reference count of dither context object (thread-unsafe) */
696SIXELAPI void
697sixel_dither_ref(sixel_dither_t *dither); /* dither context object */
698
699/* decrease reference count of dither context object (thread-unsafe) */
700SIXELAPI void
701sixel_dither_unref(sixel_dither_t *dither); /* dither context object */
702
703/* initialize internal palette from specified pixel buffer */
704SIXELAPI SIXELSTATUS
705sixel_dither_initialize(
706 sixel_dither_t *dither, /* dither context object */
707 unsigned char /* in */ *data, /* sample image */
708 int /* in */ width, /* image width */
709 int /* in */ height, /* image height */
710 int /* in */ pixelformat, /* one of enum pixelFormat */
711 int /* in */ method_for_largest, /* method for finding the largest dimension */
712 int /* in */ method_for_rep, /* method for choosing a color from the box */
713 int /* in */ quality_mode); /* quality of histogram processing */
714
715/* set diffusion type, choose from enum methodForDiffuse */
716SIXELAPI void
717sixel_dither_set_diffusion_type(
718 sixel_dither_t /* in */ *dither, /* dither context object */
719 int /* in */ method_for_diffuse); /* one of enum methodForDiffuse */
720
721/* get number of palette colors */
722SIXELAPI int
723sixel_dither_get_num_of_palette_colors(
724 sixel_dither_t /* in */ *dither); /* dither context object */
725
726/* get number of histogram colors */
727SIXELAPI int
728sixel_dither_get_num_of_histogram_colors(
729 sixel_dither_t /* in */ *dither); /* dither context object */
730
731SIXELAPI __attribute__((deprecated)) int /* typoed! remains for compatibility. */
732sixel_dither_get_num_of_histgram_colors(
733 sixel_dither_t /* in */ *dither); /* dither context object */
734
735/* get palette */
736SIXELAPI unsigned char *
737sixel_dither_get_palette(
738 sixel_dither_t /* in */ *dither); /* dither context object */
739
740/* set palette */
741SIXELAPI void
742sixel_dither_set_palette(
743 sixel_dither_t /* in */ *dither, /* dither context object */
744 unsigned char /* in */ *palette);
745
746/* set the factor of complexion color correcting */
747SIXELAPI void
748sixel_dither_set_complexion_score(
749 sixel_dither_t /* in */ *dither, /* dither context object */
750 int /* in */ score); /* complexion score (>= 1) */
751
752/* set whether omitting palette difinition */
753SIXELAPI void
754sixel_dither_set_body_only(
755 sixel_dither_t /* in */ *dither, /* dither context object */
756 int /* in */ bodyonly); /* 0: output palette section(default)
757 1: do not output palette section */
758/* set whether optimize palette size */
759SIXELAPI void
760sixel_dither_set_optimize_palette(
761 sixel_dither_t /* in */ *dither, /* dither context object */
762 int /* in */ do_opt); /* 0: optimize palette size
763 1: don't optimize palette size */
764/* set pixelformat */
765SIXELAPI void
766sixel_dither_set_pixelformat(
767 sixel_dither_t /* in */ *dither, /* dither context object */
768 int /* in */ pixelformat); /* one of enum pixelFormat */
769
770/* set transparent */
771SIXELAPI void
772sixel_dither_set_transparent(
773 sixel_dither_t /* in */ *dither, /* dither context object */
774 int /* in */ transparent); /* transparent color index */
775
776#ifdef __cplusplus
777}
778#endif
779
780/* converter API */
781
782typedef void * (* sixel_allocator_function)(size_t size);
783
784#ifdef __cplusplus
785extern "C" {
786#endif
787
788/* convert pixels into sixel format and write it to output context */
789SIXELAPI SIXELSTATUS
790sixel_encode(
791 unsigned char /* in */ *pixels, /* pixel bytes */
792 int /* in */ width, /* image width */
793 int /* in */ height, /* image height */
794 int /* in */ depth, /* color depth: now unused */
795 sixel_dither_t /* in */ *dither, /* dither context */
796 sixel_output_t /* in */ *context); /* output context */
797
798/* convert sixel data into indexed pixel bytes and palette data */
799SIXELAPI SIXELSTATUS
800sixel_decode_raw(
801 unsigned char /* in */ *p, /* sixel bytes */
802 int /* in */ len, /* size of sixel bytes */
803 unsigned char /* out */ **pixels, /* decoded pixels */
804 int /* out */ *pwidth, /* image width */
805 int /* out */ *pheight, /* image height */
806 unsigned char /* out */ **palette, /* ARGB palette */
807 int /* out */ *ncolors, /* palette size (<= 256) */
808 sixel_allocator_t /* in */ *allocator); /* allocator object or null */
809
810SIXELAPI __attribute__((deprecated)) SIXELSTATUS
811sixel_decode(
812 unsigned char /* in */ *sixels, /* sixel bytes */
813 int /* in */ size, /* size of sixel bytes */
814 unsigned char /* out */ **pixels, /* decoded pixels */
815 int /* out */ *pwidth, /* image width */
816 int /* out */ *pheight, /* image height */
817 unsigned char /* out */ **palette, /* RGBA palette */
818 int /* out */ *ncolors, /* palette size (<= 256) */
819 sixel_allocator_function /* in */ fn_malloc); /* malloc function */
820
821#ifdef __cplusplus
822}
823#endif
824
825/* helper API */
826
827#ifdef __cplusplus
828extern "C" {
829#endif
830
831SIXELAPI void
832sixel_helper_set_additional_message(
833 const char /* in */ *message /* error message */
834);
835
836SIXELAPI char const *
837sixel_helper_get_additional_message(void);
838
839/* convert error status code int formatted string */
840SIXELAPI char const *
841sixel_helper_format_error(
842 SIXELSTATUS /* in */ status /* status code */
843);
844
845/* compute pixel depth from pixelformat */
846SIXELAPI int
847sixel_helper_compute_depth(
848 int /* in */ pixelformat /* one of enum pixelFormat */
849);
850
851/* convert pixelFormat into PIXELFORMAT_RGB888 */
852SIXELAPI SIXELSTATUS
853sixel_helper_normalize_pixelformat(
854 unsigned char /* out */ *dst, /* destination buffer */
855 int /* out */ *dst_pixelformat, /* converted pixelformat */
856 unsigned char const /* in */ *src, /* source pixels */
857 int /* in */ src_pixelformat, /* format of source image */
858 int /* in */ width, /* width of source image */
859 int /* in */ height /* height of source image */
860);
861
862/* scale image to specified size */
863SIXELAPI SIXELSTATUS
864sixel_helper_scale_image(
865 unsigned char /* out */ *dst, /* destination buffer */
866 unsigned char const /* in */ *src, /* source image data */
867 int /* in */ srcw, /* source image width */
868 int /* in */ srch, /* source image height */
869 int /* in */ pixelformat, /* one of enum pixelFormat */
870 int /* in */ dstw, /* destination image width */
871 int /* in */ dsth, /* destination image height */
872 int /* in */ method_for_resampling, /* one of methodForResampling */
873 sixel_allocator_t /* in */ *allocator /* allocator object */
874);
875
876#ifdef __cplusplus
877}
878#endif
879
880
881/* image loader/writer API */
882
883#if SIXEL_USE_DEPRECATED_SYMBOLS
884enum imageFormat {
885 FORMAT_GIF = 0, /* read only */
886 FORMAT_PNG = 1, /* read/write */
887 FORMAT_BMP = 2, /* read only */
888 FORMAT_JPG = 3, /* read only */
889 FORMAT_TGA = 4, /* read only */
890 FORMAT_WBMP = 5, /* read only with --with-gd configure option */
891 FORMAT_TIFF = 6, /* read only */
892 FORMAT_SIXEL = 7, /* read only */
893 FORMAT_PNM = 8, /* read only */
894 FORMAT_GD2 = 9, /* read only with --with-gd configure option */
895 FORMAT_PSD = 10, /* read only */
896 FORMAT_HDR = 11 /* read only */
897};
898
899/* loop mode */
900enum loopControl {
901 LOOP_AUTO = 0, /* honer the setting of GIF header */
902 LOOP_FORCE = 1, /* always enable loop */
903 LOOP_DISABLE = 2 /* always disable loop */
904};
905#endif
906
907/* handle type of dither context object */
908struct sixel_frame;
909typedef struct sixel_frame sixel_frame_t;
910
911#ifdef __cplusplus
912extern "C" {
913#endif
914
915/* constructor of frame object */
916SIXELAPI SIXELSTATUS
917sixel_frame_new(
918 sixel_frame_t /* out */ **ppframe, /* frame object to be created */
919 sixel_allocator_t /* in */ *allocator); /* allocator, null if you use
920 default allocator */
921/* deprecated version of sixel_frame_new() */
922SIXELAPI __attribute__((deprecated)) sixel_frame_t *
923sixel_frame_create(void);
924
925/* increase reference count of frame object (thread-unsafe) */
926SIXELAPI void
927sixel_frame_ref(sixel_frame_t /* in */ *frame);
928
929/* decrease reference count of frame object (thread-unsafe) */
930SIXELAPI void
931sixel_frame_unref(sixel_frame_t /* in */ *frame);
932
933/* initialize frame object with a pixel buffer */
934SIXELAPI SIXELSTATUS
935sixel_frame_init(
936 sixel_frame_t /* in */ *frame, /* frame object to be initialize */
937 unsigned char /* in */ *pixels, /* pixel buffer */
938 int /* in */ width, /* pixel width of buffer */
939 int /* in */ height, /* pixel height of buffer */
940 int /* in */ pixelformat, /* pixelformat of buffer */
941 unsigned char /* in */ *palette, /* palette for buffer or NULL */
942 int /* in */ ncolors /* number of palette colors or (-1) */
943);
944
945/* get pixels */
946SIXELAPI unsigned char *
947sixel_frame_get_pixels(sixel_frame_t /* in */ *frame); /* frame object */
948
949/* get palette */
950SIXELAPI unsigned char *
951sixel_frame_get_palette(sixel_frame_t /* in */ *frame); /* frame object */
952
953/* get width */
954SIXELAPI int
955sixel_frame_get_width(sixel_frame_t /* in */ *frame); /* frame object */
956
957/* get height */
958SIXELAPI int
959sixel_frame_get_height(sixel_frame_t /* in */ *frame); /* frame object */
960
961/* get ncolors */
962SIXELAPI int
963sixel_frame_get_ncolors(sixel_frame_t /* in */ *frame); /* frame object */
964
965/* get pixelformat */
966SIXELAPI int
967sixel_frame_get_pixelformat(sixel_frame_t /* in */ *frame); /* frame object */
968
969/* get transparent */
970SIXELAPI int
971sixel_frame_get_transparent(sixel_frame_t /* in */ *frame); /* frame object */
972
973/* get transparent */
974SIXELAPI int
975sixel_frame_get_multiframe(sixel_frame_t /* in */ *frame); /* frame object */
976
977/* get delay */
978SIXELAPI int
979sixel_frame_get_delay(sixel_frame_t /* in */ *frame); /* frame object */
980
981/* get frame no */
982SIXELAPI int
983sixel_frame_get_frame_no(sixel_frame_t /* in */ *frame); /* frame object */
984
985/* get loop no */
986SIXELAPI int
987sixel_frame_get_loop_no(sixel_frame_t /* in */ *frame); /* frame object */
988
989/* strip alpha from RGBA/ARGB formatted pixbuf */
990SIXELAPI int
991sixel_frame_strip_alpha(
992 sixel_frame_t /* in */ *frame,
993 unsigned char /* in */ *bgcolor);
994
995/* resize a frame to given size with specified resampling filter */
996SIXELAPI SIXELSTATUS
997sixel_frame_resize(
998 sixel_frame_t /* in */ *frame,
999 int /* in */ width,
1000 int /* in */ height,
1001 int /* in */ method_for_resampling);
1002
1003/* clip frame */
1004SIXELAPI SIXELSTATUS
1005sixel_frame_clip(
1006 sixel_frame_t /* in */ *frame,
1007 int /* in */ x,
1008 int /* in */ y,
1009 int /* in */ width,
1010 int /* in */ height);
1011
1012typedef SIXELSTATUS (* sixel_load_image_function)(
1013 sixel_frame_t /* in */ *frame,
1014 void /* in/out */ *context);
1015
1016/* Note: this function returns SIXEL_OK without calling FN_LOAD when the file
1017 content is empty or 1-byte LF. This implies an assumption that CONTEXT is
1018 initialized to be the default value for the empty file before calling this
1019 function. If it is not the case, the caller needs to properly detect it and
1020 handle this, or otherwise, CONTEXT can be used uninitialized in subsequent
1021 codes. */
1022SIXELAPI SIXELSTATUS
1023sixel_helper_load_image_file(
1024 char const /* in */ *filename, /* source file name */
1025 int /* in */ fstatic, /* whether to extract static image */
1026 int /* in */ fuse_palette, /* whether to use paletted image */
1027 int /* in */ reqcolors, /* requested number of colors */
1028 unsigned char /* in */ *bgcolor, /* background color */
1029 int /* in */ loop_control, /* one of enum loopControl */
1030 sixel_load_image_function /* in */ fn_load, /* callback */
1031 int /* in */ finsecure, /* true if do not verify SSL */
1032 int const /* in */ *cancel_flag, /* cancel flag */
1033 void /* in/out */ *context, /* private data for callback */
1034 sixel_allocator_t /* in */ *allocator); /* allocator object */
1035
1036/* write image to file */
1037SIXELAPI SIXELSTATUS
1038sixel_helper_write_image_file(
1039 unsigned char /* in */ *data, /* source pixel data */
1040 int /* in */ width, /* source data width */
1041 int /* in */ height, /* source data height */
1042 unsigned char /* in */ *palette, /* palette of source data */
1043 int /* in */ pixelformat, /* source pixelFormat */
1044 char const /* in */ *filename, /* destination filename */
1045 int /* in */ imageformat, /* one of enum imageformat */
1046 sixel_allocator_t /* in */ *allocator); /* allocator object */
1047
1048#ifdef __cplusplus
1049}
1050#endif
1051
1052
1053/* easy encoder API */
1054
1055/* handle type of dither context object */
1056struct sixel_encoder;
1057typedef struct sixel_encoder sixel_encoder_t;
1058
1059#ifdef __cplusplus
1060extern "C" {
1061#endif
1062
1063/* create encoder object */
1064SIXELAPI SIXELSTATUS
1065sixel_encoder_new(
1066 sixel_encoder_t /* out */ **ppencoder, /* encoder object to be created */
1067 sixel_allocator_t /* in */ *allocator); /* allocator, null if you use
1068 default allocator */
1069
1070/* deprecated version of sixel_decoder_new() */
1071SIXELAPI __attribute__((deprecated)) sixel_encoder_t *
1072sixel_encoder_create(void);
1073
1074/* increase reference count of encoder object (thread-unsafe) */
1075SIXELAPI void
1076sixel_encoder_ref(sixel_encoder_t /* in */ *encoder);
1077
1078/* decrease reference count of encoder object (thread-unsafe) */
1079SIXELAPI void
1080sixel_encoder_unref(sixel_encoder_t /* in */ *encoder);
1081
1082/* set cancel state flag to encoder object */
1083SIXELAPI SIXELSTATUS
1084sixel_encoder_set_cancel_flag(
1085 sixel_encoder_t /* in */ *encoder,
1086 int /* in */ *cancel_flag);
1087
1088/* set an option flag to encoder object */
1089SIXELAPI SIXELSTATUS
1090sixel_encoder_setopt(
1091 sixel_encoder_t /* in */ *encoder,
1092 int /* in */ arg,
1093 char const /* in */ *optarg);
1094
1095/* load source data from specified file and encode it to SIXEL format */
1096SIXELAPI SIXELSTATUS
1097sixel_encoder_encode(
1098 sixel_encoder_t /* in */ *encoder,
1099 char const /* in */ *filename);
1100
1101/* encode specified pixel data to SIXEL format
1102 * output to encoder->outfd */
1103SIXELAPI SIXELSTATUS
1104sixel_encoder_encode_bytes(
1105 sixel_encoder_t /* in */ *encoder,
1106 unsigned char /* in */ *bytes,
1107 int /* in */ width,
1108 int /* in */ height,
1109 int /* in */ pixelformat,
1110 unsigned char /* in */ *palette,
1111 int /* in */ ncolors);
1112
1113#ifdef __cplusplus
1114}
1115#endif
1116
1117
1118/* easy encoder API */
1119
1120/* handle type of dither context object */
1121struct sixel_decoder;
1122typedef struct sixel_decoder sixel_decoder_t;
1123
1124#ifdef __cplusplus
1125extern "C" {
1126#endif
1127
1128/* create decoder object */
1129SIXELAPI SIXELSTATUS
1130sixel_decoder_new(
1131 sixel_decoder_t /* out */ **ppdecoder, /* decoder object to be created */
1132 sixel_allocator_t /* in */ *allocator); /* allocator, null if you use
1133 default allocator */
1134
1135/* deprecated version of sixel_decoder_new() */
1136SIXELAPI __attribute__((deprecated)) sixel_decoder_t *
1137sixel_decoder_create(void);
1138
1139/* increase reference count of decoder object (thread-unsafe) */
1140SIXELAPI void
1141sixel_decoder_ref(sixel_decoder_t *decoder);
1142
1143/* decrease reference count of decoder object (thread-unsafe) */
1144SIXELAPI void
1145sixel_decoder_unref(sixel_decoder_t *decoder);
1146
1147/* set an option flag to decoder object */
1148SIXELAPI SIXELSTATUS
1149sixel_decoder_setopt(
1150 sixel_decoder_t /* in */ *decoder, /* decoder object */
1151 int /* in */ arg, /* one of SIXEL_OPTFLAG_*** */
1152 char const /* in */ *optarg); /* null or an argument of optflag */
1153
1154/* load source data from stdin or the file specified with
1155 SIXEL_OPTFLAG_INPUT flag, and decode it */
1156SIXELAPI SIXELSTATUS
1157sixel_decoder_decode(
1158 sixel_decoder_t /* in */ *decoder);
1159
1160#ifdef __cplusplus
1161}
1162#endif
1163
1164#endif /* LIBSIXEL_SIXEL_H */
1165
1166/* emacs Local Variables: */
1167/* emacs mode: c */
1168/* emacs tab-width: 4 */
1169/* emacs indent-tabs-mode: nil */
1170/* emacs c-basic-offset: 4 */
1171/* emacs End: */
1172/* vim: set expandtab ts=4 sts=4 sw=4 : */
1173/* EOF */