44
55#define FF_KITTY_MAX_CHUNK_SIZE 4096
66
7+ #ifdef FF_HAVE_ZLIB
8+ #include <zlib.h>
9+
10+ static bool compressBlob (const FFinstance * instance , void * * blob , size_t * length )
11+ {
12+ FF_LIBRARY_LOAD (zlib , instance -> config .libZ , false, "libz.so" , 2 )
13+ FF_LIBRARY_LOAD_SYMBOL (zlib , compressBound , false)
14+ FF_LIBRARY_LOAD_SYMBOL (zlib , compress2 , false)
15+
16+ uLong compressedLength = ffcompressBound (* length );
17+ void * compressed = malloc (compressedLength );
18+ if (compressed == NULL )
19+ {
20+ dlclose (zlib );
21+ return false;
22+ }
23+
24+ int compressResult = ffcompress2 (compressed , & compressedLength , * blob , * length , Z_BEST_COMPRESSION );
25+ dlclose (zlib );
26+ if (compressResult != Z_OK )
27+ {
28+ free (compressed );
29+ return false;
30+ }
31+
32+ free (* blob );
33+
34+ * length = (size_t ) compressedLength ;
35+ * blob = compressed ;
36+ return true;
37+ }
38+
39+ #endif // FF_HAVE_ZLIB
40+
741//We use only the defines from here, that are exactly the same in both versions
842#ifdef FF_HAVE_IMAGEMAGICK7
943 #include <MagickCore/MagickCore.h>
@@ -44,7 +78,7 @@ static void printImageKittyChunc(char** blob, size_t* length, uint32_t chunkSize
4478 * length -= toWrite ;
4579}
4680
47- static bool printImageKitty (ImageInfo * imageInfo , Image * image , ExceptionInfo * ExceptionInfo , uint32_t paddingLeft , ImageMagickFunctions * functions )
81+ static bool printImageKitty (const FFinstance * instance , ImageInfo * imageInfo , Image * image , ExceptionInfo * ExceptionInfo , uint32_t paddingLeft , ImageMagickFunctions * functions )
4882{
4983 functions -> ffCopyMagickString (imageInfo -> magick , "RGBA" , 5 );
5084
@@ -53,16 +87,23 @@ static bool printImageKitty(ImageInfo* imageInfo, Image* image, ExceptionInfo* E
5387 if (!checkAllocationResult (blob , length ))
5488 return false;
5589
56- void * encoded = functions -> ffBase64Encode (blob , length , & length );
90+ #ifdef FF_HAVE_ZLIB
91+ bool isCompressed = compressBlob (instance , & blob , & length );
92+ #else
93+ FF_UNUSED (instance )
94+ bool isCompressed = false;
95+ #endif
96+
97+ char * encoded = functions -> ffBase64Encode (blob , length , & length );
5798 free (blob );
5899 if (!checkAllocationResult (encoded , length ))
59100 return false;
60101
61102 ffPrintCharTimes (' ' , paddingLeft );
62103
63- char * currentPos = ( char * ) encoded ;
104+ char * currentPos = encoded ;
64105
65- printf ("\033_Ga=T,f=32,s=%u,v=%u,m=1;\033\\" , (uint32_t ) image -> columns , (uint32_t ) image -> rows );
106+ printf ("\033_Ga=T,f=32,s=%u,v=%u,m=1%s ;\033\\" , (uint32_t ) image -> columns , (uint32_t ) image -> rows , isCompressed ? ",o=z" : "" );
66107 while (length > 0 )
67108 printImageKittyChunc (& currentPos , & length , FF_KITTY_MAX_CHUNK_SIZE );
68109 fputs ("\033_Gm=0;\033\\" , stdout );
@@ -159,7 +200,7 @@ FFLogoImageResult ffLogoPrintImageImpl(FFinstance* instance, void* imageMagick,
159200
160201 bool printSuccessful ;
161202 if (type == FF_LOGO_TYPE_KITTY )
162- printSuccessful = printImageKitty (imageInfoOut , resizedImage , exceptionInfo , instance -> config .logoPaddingLeft , & functions );
203+ printSuccessful = printImageKitty (instance , imageInfoOut , resizedImage , exceptionInfo , instance -> config .logoPaddingLeft , & functions );
163204 else
164205 printSuccessful = printImageSixel (imageInfoOut , resizedImage , exceptionInfo , instance -> config .logoPaddingLeft , & functions );
165206
@@ -179,7 +220,7 @@ FFLogoImageResult ffLogoPrintImageImpl(FFinstance* instance, void* imageMagick,
179220 return FF_LOGO_IMAGE_RESULT_SUCCESS ;
180221}
181222
182- #endif
223+ #endif //FF_HAVE_IMAGEMAGICK{6, 7}
183224
184225bool ffLogoPrintImageIfExists (FFinstance * instance , FFLogoType type )
185226{
0 commit comments