brendan-duncan / image

Dart Image Library for opening, manipulating, and saving various different image file formats.
MIT License
1.14k stars 255 forks source link

adjustColor. Reverting brigtness back to the initial state. #640

Closed fedorstepanovv closed 3 months ago

fedorstepanovv commented 3 months ago

I need to support a few different color adjusting operations. (e.g contrast, brightness).

When i need to change a specific value, i make use of a method where I do such steps:

  1. decode the current uin8list: img.Image? baseImage = img.decodeImage(params.originalImage);
  2. Based on a chosen modification, (in our case brightness), I use adjustColor to modify the value.
  3. I encode the image back to uint8list: updatedImage = img.encodeJpg(baseImage) and return it back.
  4. I display the updated image using an Image.memory()

The problem is that if I apply a higher brightness or darker than the original image is, I can't return it to the original image back if I choose the initial value. The image is getting brighter and it's impossible to revert it without assigning the whole uin8tlist back to the original image's uint8list. For eg. A high brightness value make the image too white. If i set a lower value, i won't see any changes.

What is the possible way to deal with such a behavior. Can we somehow revert the image's brightness or other similar operations back?

fedorstepanovv commented 3 months ago

The issue is not related to the library itself. I fixed it by preventing an image from doing accumulated adjustments, when you apply the same effect to an image that is already adjusted (using the same effect)