samizdatco / skia-canvas

A GPU-accelerated 2D graphics environment for Node.js
MIT License
1.67k stars 63 forks source link

Load raw pixels buffer into Image? #113

Open GEEKiDoS opened 2 years ago

GEEKiDoS commented 2 years ago

I'm working with games and need to load the dds or textures in assetbundle(unity) into Image. But seems there's no method that I can just feed decoded pixels into it.

ggolda commented 1 year ago

Would be great to have a way to create image from raw decoded pixel buffer.

ggolda commented 1 year ago

@samizdatco currently rust based Image creates SKImage only using from_encoded_data function. Maybe there is a way to add an options object to loadImage function that accepts something like js sharp when it receives raw images:

sharp(frame, {
    raw: {
      width: 1920,
      height: 1080,
      channels: 4,
      premultiplied: true
    }
  })

As I know Skia itself supports creating SkImages from pixel buffers if you provide SkImageInfo. Would be a great addition to this library, because currently there is no way to draw frames from ffmpeg for example without double decoding :(