Unable to draw .avif images

85 views
Skip to first unread message

Steven

unread,
Nov 30, 2024, 10:56:03 AM11/30/24
to skia-discuss
Hi, I'm trying to draw .avif images to on a skcanvas but it doesn't appear to be working.

I compiled skia (chrome/m132 branch, a756a57) in a ubuntu 24.04 container with these commands:
```
bin/gn gen out/Shared --args='is_official_build=true is_component_build=true skia_enable_gpu=false skia_use_libavif=true skia_use_system_libjpeg_turbo=false skia_use_system_libwebp=false skia_use_system_libpng=false skia_use_system_icu=false skia_use_system_harfbuzz=false'
ninja -C out/Shared
```

This is my main.cpp:
```
#include "include/core/SkCanvas.h"
#include "include/core/SkPaint.h"
#include "include/core/SkSurface.h"
#include "include/core/SkStream.h"
#include "include/encode/SkPngEncoder.h"
#include <iostream>
#include <memory>
#include <fstream>
#include <vector>

int main() {
  std::unique_ptr<SkStreamAsset> stream = SkStream::MakeFromFile("dog.avif");

  sk_sp<SkImage> dog = SkImages::DeferredFromEncodedData(stream->getData());

  if (dog == nullptr) {
std::cout << "dog is null" << std::endl;
return 1;
  }

  SkImageInfo skImgInfo = SkImageInfo::MakeN32Premul(1000, 1000);

  sk_sp<SkSurface> surface = SkSurfaces::Raster(skImgInfo);

  SkPaint paint;
  paint.setColor(0xFFFFFFFF);

  surface->getCanvas()->drawRect(SkRect::MakeXYWH(50, 50, 500, 500), paint);
  surface->getCanvas()->drawImage(dog, 100, 100);

  sk_sp<SkImage> image = surface->makeImageSnapshot();

  sk_sp<SkData> pngData = SkPngEncoder::Encode(nullptr, image.get(), {});
  std::ofstream outFile("output.png", std::ios::binary);
  outFile.write((const char *)pngData->data(), pngData->size());
  outFile.close();

  std::cout << "success" << std::endl;
}
```

Compiled with:
```
clang++ main.cpp -o hello \
    -I/root/skia2 \
    -I/root/skia2/include \
    -L/root/skia2/out/Shared \
    -Wl,-rpath=/root/skia2/out/Shared \
    -lskia -ldl -lpthread -lm -lz -lfreetype
```

It creates the output.png file correctly but it doesn't contain the image from dog.avif, only the rectangle. Interestingly, if I convert the dog.avif image to a .png file then it works correctly (both the rectangle and image present in output.png).

Am I doing something wrong or is it a bug in skia?

(dog.avif is from here)

Steven

unread,
Dec 2, 2024, 10:50:33 AM12/2/24
to skia-discuss

I tried to be as descriptive as possible with my environment so that anyone could reproduce it and judge if the problem is a bug or me just missing something. If there's anything else I can provide please let me know.
Reply all
Reply to author
Forward
0 new messages