Making mosaic images with ffmpeg
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.3 KiB

#pragma once
#include "av.hpp"
#include <memory>
#include <string>
#include <vector>
#include <functional>
// Basic image representation
// 3 bytes per pixel (rgb), so size of data is width*height*3
struct raw_rgb_image {
std::vector<uint8_t, av::allocator<uint8_t>> data;
av::frame frame;
raw_rgb_image();
raw_rgb_image(int W, int H);
int width() const;
int height() const;
AVPixelFormat format() const;
};
// dumps image in ppm format
void save_as_ppm(raw_rgb_image const & image, std::string const & filename);
// opens an image in its own format
av::frame open_image(std::string const & filename);
// crops to the bottom right square (cheap operation)
void crop_to_square(av::frame & frame);
av::frame crop_to_square(av::frame const & frame);
av::frame crop_to_square(av::frame && frame);
// converts and resizes
raw_rgb_image to_raw_rgb_image(av::frame const & frame, int new_width, int new_height);
// Legacy
inline raw_rgb_image open_as_rgb(const std::string &filename){
return to_raw_rgb_image(crop_to_square(open_image(filename)), 512, 512);
}
// apply function to every tile, fun :: Column, Row, Image -> Void
void apply_to_tiles(std::string const & filename, int h_tiles, int v_tiles, std::function<void(int, int, av::frame const &)> fun);
// does what you think it does
void save_as_jpg(av::frame const & frame, std::string const & filename);