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

0001 /* -*- C++ -*-
0002  * File: openvayer_sample.cpp
0003  * Copyright 2008-2021 LibRaw LLC (info@libraw.org)
0004  * Created: Feb 11, 2020
0005  *
0006  * LibRaw simple C++ API:  opens bayer data (Kodak KAI-0340 sensor) from buffer,
0007 dump as 8-bit tiff
0008 
0009 LibRaw is free software; you can redistribute it and/or modify
0010 it under the terms of the one of two licenses as you choose:
0011 
0012 1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1
0013    (See file LICENSE.LGPL provided in LibRaw distribution archive for details).
0014 
0015 2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
0016    (See file LICENSE.CDDL provided in LibRaw distribution archive for details).
0017 
0018  */
0019 
0020 #include <stdio.h>
0021 #include <string.h>
0022 #include <math.h>
0023 
0024 #include "libraw/libraw.h"
0025 
0026 #ifndef LIBRAW_WIN32_CALLS
0027 #include <unistd.h>
0028 #include <fcntl.h>
0029 #include <sys/stat.h>
0030 #include <sys/mman.h>
0031 #endif
0032 
0033 int main(int ac, char *av[])
0034 {
0035   if (ac != 2)
0036     return 1;
0037   FILE *in = fopen(av[1], "rb");
0038   fseek(in, 0, SEEK_END);
0039   unsigned fsz = ftell(in);
0040   unsigned char *buffer = (unsigned char *)malloc(fsz);
0041   if (!buffer)
0042     return 2;
0043   fseek(in, 0, SEEK_SET);
0044   unsigned readb = fread(buffer, 1, fsz, in);
0045   if (readb != fsz)
0046     return 3;
0047   LibRaw rp;
0048   rp.imgdata.params.output_tiff = 1;
0049   int ret = rp.open_bayer(buffer, fsz, 640, 480, 0, 0, 0, 0, 0,
0050                           LIBRAW_OPENBAYER_RGGB, 0, 0, 1400);
0051   if (ret != LIBRAW_SUCCESS)
0052     return 4;
0053   if ((ret = rp.unpack()) != LIBRAW_SUCCESS)
0054     printf("Unpack error: %d\n", ret);
0055 
0056   if ((ret = rp.dcraw_process()) != LIBRAW_SUCCESS)
0057     printf("Processing error: %d\n", ret);
0058 
0059   char outfn[256];
0060   sprintf(outfn, "%s.tif", av[1]);
0061   if (LIBRAW_SUCCESS != (ret = rp.dcraw_ppm_tiff_writer(outfn)))
0062     printf("Cannot write %s: %s\n", outfn, libraw_strerror(ret));
0063   else
0064     printf("Created %s\n", outfn);
0065 }