netpyoung / unity.webp

:art: WebP made easy for Unity3d
https://netpyoung.github.io/unity.webp/
MIT License
237 stars 28 forks source link

Pixel copy to flip texture is too slow, WebPDecoderOptions.flip should be used, but how? #21

Open shunia opened 4 years ago

shunia commented 4 years ago

Pixel copy is blocking the main thread and consumes too much time, which is not acceptable.

I tried with one of our webp animation file, and the overall performance is something like:

libwebp decode: 230ms
flip upside down by pixel copy: 735ms

And because these all happened in the main thread, it freeze the app for almost 1 secend.

And then I found this in project libwebp inside the 1.0.0 tag, which is the exact version used by unity.webp:

// Decoding options
struct WebPDecoderOptions {
  ...
  int flip;                           // flip output vertically
  ...
};

This flip option has been implemented to solve the upside down problem, but how could I use this option? Please help.

netpyoung commented 4 years ago

Oh I see, i will check source of that option.

On Thu, 26 Mar 2020, 10:43 shunia, notifications@github.com wrote:

Pixel copy is blocking the main thread and consumes too much time, which is not acceptable.

I tried with one of our webp animation file, and the overall performance is something like:

libwebp decode: 230ms flip upside down by pixel copy: 735ms

And because these all happened in the main thread, it freeze the app for almost 1 secend.

And then I found this in project libwebp inside the 1.0.0 tag, which is the exact version used by unity.webp:

// Decoding options struct WebPDecoderOptions { ... int flip; // flip output vertically ... };

This flip option has been implemented to solve the upside down problem, but how could I use this option? Please help.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/netpyoung/unity.webp/issues/21, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACR2EOFMKP3B3PDUGB42QLRJKXMFANCNFSM4LT4FCOA .

netpyoung commented 4 years ago

I used function WebPAnimDecoderNewInternal

But I failed to find insert WebPDecoderOptions option to there. So It seems need to write manually like this https://stackoverflow.com/a/28472740 .

During weekends I will trying that again

shunia commented 3 years ago

Possible solution here: https://github.com/netpyoung/unity.webp/pull/24

netpyoung commented 3 years ago

after merge, I fixed compile error then I realized flip parameter comes from WebPAnimDecoderOptions not in WebPDecoderOptions .

shunia commented 3 years ago

Oh, I forgot to organize WebPDecoderWrapper.cs.

The flip option won't work, though i forgot the details: https://github.com/webmproject/libwebp/blob/be738c6d396fa5a272c1b209be4379a7532debfe/src/dec/buffer_dec.c#L153

And Texture2DExt.LoadRGBAFromWebP works just great and implemented well so I just used it.