emmcb / cxx-image

A flexible and lightweight image processing library written in modern C++17.
Apache License 2.0
1 stars 1 forks source link

PLAIN error: Cannot guess relevant width alignment corresponding to file size #2

Closed Uzver123 closed 1 month ago

Uzver123 commented 1 month ago

Keep getting this error when trying to convert file no solution that i can find in source code, can you suggest anything?

emmcb commented 1 month ago

Hello,

I suspect that this is because your pixel type is unknown, for a PLAIN image in your ImageReader::Options you must also provide the correct options.fileInfo.imageLayout and/or options.fileInfo.pixelType fields.

The error message was not meaningful because I found that the pixel type error check was after the alignment guess, however the alignment guess requires a correct pixel type, so you would end up with this alignment error in case you do not provide a pixel type. I just committed a fix to this.

Please let me know if you manage to read your image with this or if something still doesn't work.

Uzver123 commented 1 month ago

Thanks for quick response, even though i know how to somewhat read C++ code i am not aware how to compile it and i was using the other Python lib (link) that works with your project which adds complexity in integrating latest updates. Its above my pay grade so to say. Is there way to make it work without integrating latest commit?

I already had imageLayoutspecified, if i also add pixelType: bayer_bggr it still shows same error Cannot guess relevant width alignment corresponding to file size.

Suspect that this could problem with image itself, or some specific way android is encoding YUV420 NV12 because yesterday i have spent all evening trying to convert it using many different image libraries for Python and standalone ones (ffmpeg, gstreamer), all they failed with similar error message or produced file that consist of scaled color lines.

Could you take a look at this images (link) from Android 11 and see if you able to load them properly with your fix.

emmcb commented 1 month ago

Ok thank you for the informations, my latest update only fixes the error message, it will also work with the older version used by the python bindings.

I investigated the images you attached and here what I found:

Here is the corresponding json file to use with the truncated file:

{
    "fileInfo": {
        "format": "plain",
        "width": 4032,
        "height": 3008,
    "imageLayout": "nv12"
    }
}

With these changes I checked that I can convert your nv12 image to a jpg image using the cxx-image convert tool and it looks ok.

emmcb commented 1 month ago

In 53c56de74ac3d2a68bed963ab7c3ed2631590a79 I have added the heightAlignment and sizeAlignment properties in addition to the existing widthAlignment. This allows to read your provided files as is, without manually removing the padding, using the following json:

RAW:

{
    "fileInfo": {
        "fileFormat": "plain",
        "width": 4000,
        "height": 3000,
        "pixelPrecision": 16,
        "imageLayout": "planar",
        "pixelType": "bayer_bggr",
        "sizeAlignment": 4096
    }
}

YUV:

{
    "fileInfo": {
        "fileFormat": "plain",
        "width": 4000,
        "height": 3000,
        "imageLayout": "nv12",
        "widthAlignment": 64,
        "heightAlignment": 16,
        "sizeAlignment": 4096
    }
}

The python bindings however are not updated because I do not own them. Maybe at some point I can create a fork so that I can maintain them updated with the latest C++ library, but I currently lack some time to do this.