1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
#include <stdio.h>
#include "libdng.h"
void
usage(char *name)
{
fprintf(stderr, "Usage: %s src-file output-file\n", name);
fprintf(stderr, "Read the main image from a DNG file and dump it as raw data\n\n");
}
int
main(int argc, char *argv[])
{
libdng_init();
libdng_info info = {0};
libdng_new(&info);
uint32_t width, height;
uint8_t *image;
size_t image_length;
if (argc < 3) {
fprintf(stderr, "Missing required argument\n");
usage(argv[0]);
return 1;
}
if (!libdng_read(&info, argv[1])) {
fprintf(stderr, "Could not load the metadata from the original file\n");
return 1;
}
if (!libdng_read_image(&info, argv[1], 1, &image, &image_length, &width, &height)) {
fprintf(stderr, "Could not load image data from the original file\n");
return 1;
}
printf("Got %dx%d image of %zu bytes\n", width, height, image_length);
FILE *fp = fopen(argv[2] ,"wb");
if (!fp) {
fprintf(stderr, "Could not open output file\n");
return 1;
}
fwrite(image, image_length, 1, fp);
fclose(fp);
return 0;
}
|