gen2brain / jpegli

Go encoder/decoder for JPEG based on jpegli
BSD 3-Clause "New" or "Revised" License
25 stars 4 forks source link

Decoding returns a broken image #5

Open Wikidepia opened 5 days ago

Wikidepia commented 5 days ago

Hello, I am currently trying to decode this JPEG but it returns a weird image.

Actual Image: https://upload.disroot.org/r/WLZUs3ve#nr0+u64ZD6ALuIlbtdk3QLji6sVkQjVJGksQuiumXbI=

449724492_7255535117880797_1506613584152756254_n

449724492_7255535117880797_1506613584152756254_n.jpeg JPEG 1080x764 1080x764+0+0 8-bit sRGB 74710B 0.000u 0:00.002

Reencoded image:

decjpegli-encstd

Here is my code:

package main

import (
    "bytes"
    "image/jpeg"
    "io/ioutil"
    "os"

    "github.com/gen2brain/jpegli"
)

func main() {
    // Read image.jpeg
    imageData, err := ioutil.ReadFile("449724492_7255535117880797_1506613584152756254_n.jpeg")
    if err != nil {
        panic(err)
    }
    img, err := jpegli.Decode(bytes.NewReader(imageData))
    if err != nil {
        panic(err)
    }

    // Encode image.jpeg
    fi, _ := os.Create("decjpegli-encstd.jpeg")
    err = jpeg.Encode(fi, img, &jpeg.Options{Quality: 100})
    if err != nil {
        panic(err)
    }
}

For some reason if decoded with ScaleTarget it seems to decode properly, but the size is not similar to scale target.

gen2brain commented 5 days ago

Thanks for reporting. I am on vacation and generally will not be very active during the summer so I don't know when I can look into this. The ScaleTarget will use RGB scanlines and not raw data so that will always work, also you will get similar sizes and not the exact size, that part also needs some review. Is it any different if you use jpegli to encode and not stdlib? There is some padding applied for nonstandard dimensions.