File indexing completed on 2025-01-05 03:56:48

0001 /* -*- C++ -*-
0002  * File: dcraw_half.c
0003  * Copyright 2008-2021 LibRaw LLC (info@libraw.org)
0004  * Created: Sat Mar  8 , 2008
0005  *
0006  * LibRaw  C API sample:  emulates "dcraw  -h"
0007  *
0008 LibRaw is free software; you can redistribute it and/or modify
0009 it under the terms of the one of two licenses as you choose:
0010 
0011 1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1
0012    (See file LICENSE.LGPL provided in LibRaw distribution archive for details).
0013 
0014 2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
0015    (See file LICENSE.CDDL provided in LibRaw distribution archive for details).
0016 
0017 
0018  */
0019 #include <stdio.h>
0020 #include <string.h>
0021 #include <stdlib.h>
0022 #include <math.h>
0023 
0024 #include "libraw/libraw.h"
0025 
0026 #define HANDLE_FATAL_ERROR(ret)                                                \
0027   if (ret)                                                                     \
0028   {                                                                            \
0029     fprintf(stderr, "%s: libraw  %s\n", av[i], libraw_strerror(ret));          \
0030     if (LIBRAW_FATAL_ERROR(ret))                                               \
0031       exit(1);                                                                 \
0032   }
0033 
0034 #define HANDLE_ALL_ERRORS(ret)                                                 \
0035   if (ret)                                                                     \
0036   {                                                                            \
0037     fprintf(stderr, "%s: libraw  %s\n", av[i], libraw_strerror(ret));          \
0038     continue;                                                                  \
0039   }
0040 
0041 int main(int ac, char *av[])
0042 {
0043   int i;
0044   libraw_data_t *iprc = libraw_init(0);
0045 
0046   if (!iprc)
0047   {
0048     fprintf(stderr, "Cannot create libraw handle\n");
0049     exit(1);
0050   }
0051 
0052   iprc->params.half_size = 1; /* dcraw -h */
0053 
0054   for (i = 1; i < ac; i++)
0055   {
0056     char outfn[1024];
0057     int ret = libraw_open_file(iprc, av[i]);
0058     HANDLE_ALL_ERRORS(ret);
0059 
0060     printf("Processing %s (%s %s)\n", av[i], iprc->idata.make,
0061            iprc->idata.model);
0062 
0063     ret = libraw_unpack(iprc);
0064     HANDLE_ALL_ERRORS(ret);
0065 
0066     ret = libraw_dcraw_process(iprc);
0067     HANDLE_ALL_ERRORS(ret);
0068 
0069     strcpy(outfn, av[i]);
0070     strcat(outfn, ".ppm");
0071     printf("Writing to %s\n", outfn);
0072 
0073     ret = libraw_dcraw_ppm_tiff_writer(iprc, outfn);
0074     HANDLE_FATAL_ERROR(ret);
0075   }
0076   libraw_close(iprc);
0077   return 0;
0078 }