Skip to content

Commit 47e01a7

Browse files
committed
Image: print more debug info when errored
1 parent a336145 commit 47e01a7

File tree

2 files changed

+48
-26
lines changed

2 files changed

+48
-26
lines changed

src/logo/image/image.c

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,6 @@ static bool printImageIterm(FFinstance* instance)
5757

5858
static bool printImageKittyDirect(FFinstance* instance)
5959
{
60-
if(instance->config.logo.width == 0 || instance->config.logo.height == 0)
61-
return false;
62-
63-
if(!ffFileExists(instance->config.logo.source.chars, S_IFREG))
64-
return false;
65-
66-
if(!ffStrbufEndsWithIgnCaseS(&instance->config.logo.source, ".png"))
67-
return false;
68-
6960
ffPrintCharTimes(' ', instance->config.logo.paddingLeft);
7061
FFstrbuf base64 = base64Encode(&instance->config.logo.source);
7162
printf("\033_Ga=T,f=100,t=f,c=%u,r=%u,C=1;%s\033\\\033[9999999D",
@@ -667,17 +658,8 @@ static bool getCharacterPixelDimensions(FFLogoRequestData* requestData)
667658
return requestData->characterPixelWidth > 1.0 && requestData->characterPixelHeight > 1.0;
668659
}
669660

670-
bool ffLogoPrintImageIfExists(FFinstance* instance, FFLogoType type)
661+
static bool printImageIfExistsSlowPath(FFinstance* instance, FFLogoType type)
671662
{
672-
if(type == FF_LOGO_TYPE_IMAGE_ITERM)
673-
return printImageIterm(instance);
674-
675-
//Performance optimisation
676-
#ifndef FF_HAVE_CHAFA
677-
if(type == FF_LOGO_TYPE_IMAGE_CHAFA)
678-
return false;
679-
#endif
680-
681663
FFLogoRequestData requestData;
682664
requestData.type = type;
683665
requestData.characterPixelWidth = 1;
@@ -686,8 +668,10 @@ bool ffLogoPrintImageIfExists(FFinstance* instance, FFLogoType type)
686668
if(
687669
(type != FF_LOGO_TYPE_IMAGE_CHAFA || instance->config.logo.width == 0 || instance->config.logo.height == 0) &&
688670
!getCharacterPixelDimensions(&requestData)
689-
)
671+
) {
672+
fputs("Logo: getCharacterPixelDimensions() failed", stderr);
690673
return false;
674+
}
691675

692676
requestData.logoPixelWidth = simpleCeil((double) instance->config.logo.width * requestData.characterPixelWidth);
693677
requestData.logoPixelHeight = simpleCeil((double) instance->config.logo.height * requestData.characterPixelHeight);
@@ -713,6 +697,7 @@ bool ffLogoPrintImageIfExists(FFinstance* instance, FFLogoType type)
713697
{
714698
//We can safely return here, because if realpath failed, we surely won't be able to read the file
715699
ffStrbufDestroy(&requestData.cacheDir);
700+
fputs("Logo: Querying realpath of the image source failed", stderr);
716701
return false;
717702
}
718703
ffStrbufRecalculateLength(&requestData.cacheDir);
@@ -741,16 +726,53 @@ bool ffLogoPrintImageIfExists(FFinstance* instance, FFLogoType type)
741726
#endif
742727

743728
ffStrbufDestroy(&requestData.cacheDir);
744-
return result == FF_LOGO_IMAGE_RESULT_SUCCESS;
729+
730+
switch(result)
731+
{
732+
case FF_LOGO_IMAGE_RESULT_INIT_ERROR:
733+
fputs("Logo: Init Image Magick library failed\n", stderr);
734+
return false;
735+
case FF_LOGO_IMAGE_RESULT_RUN_ERROR:
736+
fputs("Logo: Failed to load / convert the image source\n", stderr);
737+
return false;
738+
default
739+
return true;
740+
}
745741
}
746742

747-
#else //FF_HAVE_IMAGEMAGICK{6, 7}
743+
#endif //FF_HAVE_IMAGEMAGICK{6, 7}
744+
748745
bool ffLogoPrintImageIfExists(FFinstance* instance, FFLogoType type)
749746
{
747+
if(!ffFileExists(instance->config.logo.source.chars, S_IFREG))
748+
{
749+
fputs("Logo: Image file not found\n", stderr);
750+
return false;
751+
}
752+
750753
if(type == FF_LOGO_TYPE_IMAGE_ITERM)
751754
return printImageIterm(instance);
752-
if(type == FF_LOGO_TYPE_IMAGE_KITTY)
755+
756+
if(
757+
type == FF_LOGO_TYPE_IMAGE_KITTY &&
758+
ffStrbufEndsWithIgnCaseS(&instance->config.logo.source, ".png") &&
759+
instance->config.logo.width &&
760+
instance->config.logo.height
761+
)
753762
return printImageKittyDirect(instance);
754-
return false;
763+
764+
#ifndef FF_HAVE_CHAFA
765+
if(type == FF_LOGO_TYPE_IMAGE_CHAFA)
766+
{
767+
fputs("Logo: Fastfetch was built without Chafa support\n", stderr);
768+
return false;
769+
}
770+
#endif
771+
772+
#if defined(FF_HAVE_IMAGEMAGICK7) || defined(FF_HAVE_IMAGEMAGICK6)
773+
return printImageIfExistsSlowPath()
774+
#else
775+
fputs("Logo: Fastfetch was built without ImageMagick support\n", stderr);
776+
return false;
777+
#endif
755778
}
756-
#endif //FF_HAVE_IMAGEMAGICK{6, 7}

src/logo/image/image.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ typedef enum FFLogoImageResult
1111
{
1212
FF_LOGO_IMAGE_RESULT_SUCCESS, //Logo printed
1313
FF_LOGO_IMAGE_RESULT_INIT_ERROR, //Failed to load library, try again with next IM version
14-
FF_LOGO_IMAGE_RESULT_RUN_ERROR //Failed to load / convert image, cancle whole sixel code
14+
FF_LOGO_IMAGE_RESULT_RUN_ERROR //Failed to load / convert image, cancel whole sixel code
1515
} FFLogoImageResult;
1616

1717
typedef struct FFLogoRequestData

0 commit comments

Comments
 (0)