API: created helper functions to inherit image formats

This commit is contained in:
Andrew Haynes
2026-03-22 18:27:51 -04:00
parent 49748c8795
commit 5d8804fdeb
2 changed files with 37 additions and 8 deletions
+29 -6
View File
@@ -189,20 +189,43 @@ jpeg_save(const unsigned int* src_buf, const JPEG* attr, const char* name)
}
void
ppm_to_jpeg(PPM* in, JPEG* out)
transcode_to_jpeg(PPM* in, JPEG* out)
{
unsigned int* src_buf = ppm_load(in->name, in);
unsigned int* dst = ppm_load(in->name, in);
out->width = in->width;
out->height = in->height;
jpeg_save(src_buf, out, out->name);
jpeg_save(dst, out, out->name);
free(dst);
}
void
jpeg_to_ppm(JPEG* input, PPM* out)
transcode_to_ppm(JPEG* input, PPM* out)
{
unsigned int* src_buf = jpeg_load(input);
unsigned int* dst = jpeg_load(input);
out->width = input->width;
out->height = input->height;
out->len = out->width * out->height;
ppm_save(src_buf, *out);
ppm_save(dst, *out);
free(dst);
}
PPM
inherit_from_jpeg(const JPEG* in, const char fmt) {
PPM image = {
.width = in->width,
.height = in->height,
.len = in->width * in->height,
.fmt = fmt
};
return image;
}
JPEG
inherit_from_ppm(const PPM* in) {
JPEG image = {
.width = in->width,
.height = in->height,
.len = in->width * in->height,
};
return image;
}