27static void fix_colors(
unsigned char *imagedata,
size_t imagedata_size) {
28 for (
size_t i = 0; i < imagedata_size; i += 4) {
29 const unsigned char blue = imagedata[i];
30 const unsigned char red = imagedata[i + 2];
32 imagedata[i + 2] = blue;
36static size_t div_up(
size_t dividend,
size_t divisor) {
37 return dividend / divisor + (dividend % divisor != 0);
41 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
44 return div_up(original_size, 3) * 4;
52 while (data_i < size) {
55 unsigned char d0 =
data[data_i];
59 unsigned char d1 = data_i + 1 < size ?
data[data_i + 1] : 0;
63 if (size <= data_i + 1) {
67 unsigned char d2 = data_i + 2 < size ?
data[data_i + 2] : 0;
71 if (size <= data_i + 2) {
82 while (buf_i % 4 != 0) {
90 unsigned height,
bool is_compressed) {
91 const size_t chunk_size = 4096;
97 int has_next_chunk =
offset + chunk_size <= size;
99 printf(
"\033_Ga=T,f=32,s=%u,v=%u%s%s;", width, height,
100 chunk_size < size ?
",m=1" :
"", is_compressed ?
",o=z" :
"");
102 printf(
"\033_Gm=%d;", has_next_chunk);
105 size_t this_chunk_size = has_next_chunk ? chunk_size : size -
offset;
106 fwrite(output +
offset, this_chunk_size, 1, stdout);
116 unsigned char *imagedata = job->
imagedata;
117 size_t imagedata_size = job->
width * job->
height * 4;
133static int zlib_compress(
unsigned char *source, uLong source_len,
134 unsigned char **dest,
size_t *dest_len) {
135 uLong dest_cap = compressBound(source_len);
138 const int ret =
compress(*dest, &dest_cap, source, source_len);
139 *dest_len = dest_cap;
143static void zkitty_format(
GVJ_t *job) {
144 unsigned char *imagedata = job->
imagedata;
145 const uLong imagedata_size = job->
width * job->
height * 4;
150 int ret = zlib_compress(imagedata, imagedata_size, &zbuf, &zsize);
172 {1,
"kittyz:cairo", 1, &device_engine_zkitty, &device_features_zkitty},
Memory allocation wrappers that exit on failure.
static void * gv_alloc(size_t size)
static double compress(info *nl, int nn)
swig_ptr_object_handlers offset
#define GVDEVICE_DOES_TRUECOLOR
static void kitty_format(GVJ_t *job)
static char * base64_encode(const unsigned char *data, size_t size)
static gvdevice_engine_t device_engine_kitty
static size_t base64_encoded_size(size_t original_size)
static size_t div_up(size_t dividend, size_t divisor)
static const char base64_alphabet[]
static void fix_colors(unsigned char *imagedata, size_t imagedata_size)
gvplugin_installed_t gvdevice_types_kitty[]
static gvdevice_features_t device_features_kitty
static void kitty_write(unsigned char *data, size_t data_size, unsigned width, unsigned height, bool is_compressed)
unsigned char * imagedata
location of imagedata
void(* format)(GVJ_t *firstjob)
graphs, nodes and edges info: Agraphinfo_t, Agnodeinfo_t and Agedgeinfo_t