#pragma once

#include <cstdint>
#include <string>
#include <vector>

namespace lm {

struct ImageSize
{
  int width = 0;
  int height = 0;
};

class MapImageUtil
{
public:
  /** Decode P5 PGM (grayscale). */
  static bool decodePgm(const std::string& bytes, std::vector<uint8_t>& gray, ImageSize& size, std::string& err);

  /** Read PNG width/height from IHDR without full decode. */
  static bool pngDimensions(const std::string& bytes, ImageSize& size, std::string& err);

  /**
   * Normalize map image to PNG bytes (always output filename map.png).
   * Supports PNG passthrough or PGM conversion; optional negate (ROS map_server).
   */
  static bool toPngBytes(const std::string& bytes,
                         const std::string& filename_hint,
                         int negate,
                         std::string& png_out,
                         ImageSize& size,
                         std::string& err);
};

}  // namespace lm
