clone

a photo toolkit for your phone that never uploads: fuji film looks for raw files, social crops, error level analysis

main
gudpics / native / raw / wrapper.cpp
wrapper.cpp 2.2K
1// SPDX-License-Identifier: AGPL-3.0-or-later2// Thin C ABI over LibRaw for the browser: open a RAF from memory, develop to 8-bit RGB.3#include "libraw/libraw.h"4#include <cstring>5extern "C" {6static LibRaw* lr = nullptr;7static libraw_processed_image_t* img = nullptr;8static void reset_img(){ if(img){ LibRaw::dcraw_clear_mem(img); img=nullptr; } }9int raw_open(const void* buf, size_t len){10 reset_img(); if(lr){ lr->recycle(); } else lr = new LibRaw();11 return lr->open_buffer(const_cast<void*>(buf), len);12}13const char* raw_make(){ return lr ? lr->imgdata.idata.make : ""; }14const char* raw_model(){ return lr ? lr->imgdata.idata.model : ""; }15int raw_width(){ return lr ? lr->imgdata.sizes.width : 0; }16int raw_height(){ return lr ? lr->imgdata.sizes.height : 0; }17int raw_film_mode(){ return lr ? (int)lr->imgdata.makernotes.fuji.FilmMode : 0; }18int raw_is_xtrans(){ return lr ? (lr->imgdata.idata.filters == 9) : 0; }19int raw_dev_dr(){ return lr ? (int)lr->imgdata.makernotes.fuji.DevelopmentDynamicRange : 0; }20int raw_auto_dr(){ return lr ? (int)lr->imgdata.makernotes.fuji.AutoDynamicRange : 0; }21int raw_dr_setting(){ return lr ? (int)lr->imgdata.makernotes.fuji.DynamicRangeSetting : 0; }22// gamma: 0 = linear, 1 = sRGB curve. color: 1 sRGB, 8 Rec2020. half: 1 = half size.23int raw_develop(int half, int gamma, int color, int bps){24 if(!lr) return -1; reset_img();25 libraw_output_params_t& p = lr->imgdata.params;26 p.half_size = half; p.use_camera_wb = 1; p.use_auto_wb = 0; p.output_color = color; p.output_bps = bps;27 p.no_auto_bright = 1; p.highlight = 0; p.user_qual = half ? 0 : 1; p.fbdd_noiserd = 0; p.med_passes = 0;28 if(gamma){ p.gamm[0] = 1.0/2.4; p.gamm[1] = 12.92; } else { p.gamm[0] = 1; p.gamm[1] = 1; }29 int r = lr->unpack(); if(r) return r;30 r = lr->dcraw_process(); if(r) return r;31 int err = 0; img = lr->dcraw_make_mem_image(&err); return err;32}33unsigned char* raw_data(){ return img ? img->data : nullptr; }34int raw_out_width(){ return img ? img->width : 0; }35int raw_out_height(){ return img ? img->height : 0; }36int raw_out_bits(){ return img ? img->bits : 0; }37unsigned raw_out_size(){ return img ? img->data_size : 0; }38void raw_free(){ reset_img(); if(lr){ delete lr; lr=nullptr; } }39}