Search code examples
clinuximlib2

erorr reading Rgb Images uisng imLIb2


I am trying to read a raw RGBA image using imLIb2 (https://docs.enlightenment.org/api/imlib2/html/ -> according to this page it seems like they accept RGBA data for images)

    #include <Imlib2.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

int main(int argc, char **argv)
{
    /* an image handle */
    Imlib_Image image;

    /* load the image */
    Imlib_Load_Error error;
    image = imlib_load_image_with_error_return("rgba.raw", &error);

    printf("load error:%d", error);

    if (image)
    {
        imlib_context_set_image(image);
        
        imlib_image_set_format("png");
        /* save the image */
        imlib_save_image("working.png");
    }
    else
    {
        printf("not loaded\n");
    }
}

loading other images formats like png and Jpeg work properly but when trying to load an RGBA image I get the error "IMLIB_LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT". Could someone tell me if I am missing something or should add Some header to the RGBA image or should I call some more functions before opening an RGBA image?

If Imlib2 doesn't support reading RgbA images is there any alternative C-library that can read rgb image and do scaling like functions?


Solution

  • So this for if someone is facing the same issue

    Thanks to @mark-setchell for contributing!!

    magickcore Api is an alternative C-library that can be used to perform functions on raw RGB.

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <time.h>
    #include <magick/ImageMagick.h>
    
    int main(int argc, char **argv)
    {
        ExceptionInfo
            exception;
    
        Image
            *image,
            *images,
            *resize_image,
            *thumbnails;
    
        ImageInfo
            *image_info;
    
        /*
          Initialize the image info structure and read an image.
        */
        
        InitializeMagick(NULL);
        GetExceptionInfo(&exception);
        image_info = CloneImageInfo((ImageInfo *)NULL);
        image_info->size = "1920x1080";
        image_info->depth = 8;
        (void)strcpy(image_info->filename, "image.rgba");
        images = ReadImage(image_info, &exception);
    
        if (images == (Image *)NULL)
            exit(1);
    
        resize_image = MinifyImage(images, &exception);
    
        if (resize_image == (Image *)NULL)
            printf("error \n");
    
        DestroyImageInfo(image_info);
        
        DestroyMagick();
        return (0);
    }
    

    for reading raw images the depth and the WxH have to be specified for the image. the above is a very small example for reducing the size in half. (https://imagemagick.org/script/magick-core.php).