Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.10.x version, changes topic. #75

Closed
bigcat88 opened this issue Feb 12, 2023 · 1 comment
Closed

0.10.x version, changes topic. #75

bigcat88 opened this issue Feb 12, 2023 · 1 comment
Labels
Important information Major release changes Stale

Comments

@bigcat88
Copy link
Owner

bigcat88 commented Feb 12, 2023

Here will be information about changes for 0.10 version.

Release date: NEXT WEEK (21.02-23.02)

Main features of 0.10.0 version:

  • Removed CFFI bindings, added native C module, most parts of project were reworked.
  • Support for encoding of LA & LA;16 modes.
  • Ability to build project from source with LibHeif==1.12.0

pillow_heif.libheif_info() was simplified to such dictionary:

{
    'libheif': '1.14.2',
    'HEIF': 'x265 HEVC encoder (3.4+31-6722fce1f)',
    'AVIF': 'AOMedia Project AV1 Encoder 3.5.0'
}

Changes when using as a Pillow plugin:

  • no breaking changes.
  • in info dictionary metadata.content_type is now str instead of bytes.

Changes when using as a standalone:

  • convert_to method removed, instead optional bgr_mode parameter to open_heif & read_heif added.

  • open_heif/read_heif with convert_hdr_to_8bit=False will open 10/12 bit images in 16 bit mode automatically(and it faster now and takes less RAM during decoding).

    BGR modes(OpenCV) - old code:

    heif_file = pillow_heif.open_heif("images/rgb12.heif", convert_hdr_to_8bit=False)
    heif_file.convert_to("BGRA;16" if heif_file.has_alpha else "BGR;16")
    np_array = np.asarray(heif_file)
    cv2.imwrite("rgb16.png", np_array)

    ->

    heif_file = pillow_heif.open_heif("images/rgb12.heif", convert_hdr_to_8bit=False, bgr_mode=True)
    np_array = np.asarray(heif_file)
    cv2.imwrite("rgb16.png", np_array)
  • original_bit_depth in info dictionary was renamed to bit_depth, standalone bit_depth was removed.

    heif_file = pillow_heif.open_heif("images/rgb12.heif")
    print("image bit depth:" , heif_file.bit_depth)

    ->

    heif_file = pillow_heif.open_heif("images/rgb12.heif")
    print("image bit depth:" , heif_file.info["bit_depth"])

    it is standardized now and shows the bit-depth of image in file(not the decoded one, so it may differs from bit depth of mode), for both Pillow plugin and stand-alone usage.

  • thumbnails was simplified, temporary remove ability for getting their data and now it is just a list with thumbnails boxes.

    For both the Pillow plugin and standalone use, this list will be in the info dictionary. It simply allows you to delete thumbnails or add new ones without being able to retrieve their data. (I can’t make it universal for both modes, when there is an idea how to do it without loss of performance, I’ll do it)

  • encode function added.

    def encode(mode: str, size: tuple, data, fp, **kwargs) -> None:
        """Encodes data in a ``fp``.
    
        :param mode: `BGR(A);16`, `RGB(A);16`, LA;16`, `L;16`, `I;16L`, `BGR(A)`, `RGB(A)`, `LA`, `L`
        :param size: tuple with ``width`` and ``height`` of an image.
        :param data: bytes object with raw image data.
        :param fp: A filename (string), pathlib.Path object or an object with ``write`` method."""

    Useful in situations where you want just save one image to a new file.
    Old code that do the same(it still will be worked):

    cv_img = cv2.imread("images/jpeg_gif_png/RGBA_16.png", cv2.IMREAD_UNCHANGED)
    heif_file = pillow_heif.from_bytes(
        mode="BGRA;16",
        size=(cv_img.shape[1], cv_img.shape[0]),
        data=bytes(cv_img)
    )
    heif_file.save("RGBA_10bit.heic", quality=-1)

    New alternative:

    cv_img = cv2.imread("images/jpeg_gif_png/RGBA_16.png", cv2.IMREAD_UNCHANGED)
    pillow_heif.encode(
       mode="BGRA;16",
       size=(cv_img.shape[1], cv_img.shape[0]),
       data=bytes(cv_img),
       fp="RGBA_10bit.heic",
       quality=-1)

    Both methods are faster now, as data passes directly to LibHeif(encode will be faster as it does not create HeifFile class).

@bigcat88 bigcat88 added in progress working on it Important information Major release changes fixed in upcoming release fix will arrive with next release and removed in progress working on it labels Feb 12, 2023
@bigcat88
Copy link
Owner Author

The main and most important change to me, is that from this version info dictionaries are fully equal between Pillow version and open_heif version.
That's will make use and support of this project very simple.

bigcat88 added a commit that referenced this issue Feb 19, 2023
@bigcat88 bigcat88 added Stale and removed fixed in upcoming release fix will arrive with next release labels Feb 24, 2023
@bigcat88 bigcat88 closed this as completed Apr 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Important information Major release changes Stale
Projects
None yet
Development

No branches or pull requests

1 participant