#include <cstdint>
#include <vector>

#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"

bool decode_image_bytes(const uint8_t* data, int len, std::vector<uint8_t>& rgba, int& width,
                        int& height) {
  int w = 0;
  int h = 0;
  int channels = 0;
  unsigned char* img = stbi_load_from_memory(data, len, &w, &h, &channels, 4);
  if (!img) {
    return false;
  }
  width = w;
  height = h;
  rgba.assign(img, img + static_cast<size_t>(w * h * 4));
  stbi_image_free(img);
  return true;
}
