29 uint8_t pal_small[16 * 3];
40class ScreenshotProvider_Pcx :
public ScreenshotProvider {
42 ScreenshotProvider_Pcx() : ScreenshotProvider(
"pcx",
"PCX", 20) {}
50 if (pixelformat == 32) {
54 if (pixelformat != 8 || w == 0)
return false;
57 if (!of.has_value())
return false;
62 pcx.manufacturer = 10;
66 pcx.xmax = TO_LE16(w - 1);
67 pcx.ymax = TO_LE16(h - 1);
68 pcx.hdpi = TO_LE16(320);
69 pcx.vdpi = TO_LE16(320);
72 pcx.cpal = TO_LE16(1);
73 pcx.width = pcx.pitch = TO_LE16(w);
74 pcx.height = TO_LE16(h);
77 if (fwrite(&pcx,
sizeof(pcx), 1, f) != 1) {
82 maxlines =
Clamp(65536 / w, 16, 128);
85 std::vector<uint8_t> buff(
static_cast<size_t>(w) * maxlines);
90 uint n = std::min(h - y, maxlines);
94 callb(buff.data(), y, w, n);
98 for (i = 0; i != n; i++) {
99 const uint8_t *bufp = buff.data() + i * w;
100 uint8_t runchar = bufp[0];
105 for (j = 1; j < w; j++) {
106 uint8_t ch = bufp[j];
108 if (ch != runchar || runcount >= 0x3f) {
109 if (runcount > 1 || (runchar & 0xC0) == 0xC0) {
110 if (fputc(0xC0 | runcount, f) == EOF) {
114 if (fputc(runchar, f) == EOF) {
124 if (runcount > 1 || (runchar & 0xC0) == 0xC0) {
125 if (fputc(0xC0 | runcount, f) == EOF) {
129 if (fputc(runchar, f) == EOF) {
136 if (fputc(12, f) == EOF) {
141 uint8_t tmp[256 * 3];
143 for (uint i = 0; i < 256; i++) {
144 tmp[i * 3 + 0] = palette[i].r;
145 tmp[i * 3 + 1] = palette[i].g;
146 tmp[i * 3 + 2] = palette[i].b;
148 success = fwrite(tmp,
sizeof(tmp), 1, f) == 1;
const std::string_view name
static std::optional< FileHandle > Open(const std::string &filename, std::string_view mode)
Open an RAII file handle if possible.
bool MakeImage(std::string_view name, const ScreenshotCallback &callb, uint w, uint h, int pixelformat, const Colour *palette) const override
Create and write an image to a file.
Functions related to debugging.
#define Debug(facility, severity, format_string,...)
Output a line of debugging information.
@ Misc
Misc message facility.
@ Critical
Critical, user should know about this.
Function to handling different endian machines.
Functions for standard in/out file operations.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
A number of safeguards to prevent using unsafe methods.
Types related to screenshot providers.
std::function< void(void *buf, uint y, uint pitch, uint n)> ScreenshotCallback
Callback function signature for generating lines of pixel data to be written to the screenshot file.
Definition of base types and functions in a cross-platform compatible way.