Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
dng_opcode.c
Go to the documentation of this file.
1/*
2 This file is part of darktable,
3 Copyright (C) 2022 paolodepetrillo.
4
5 darktable is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 darktable is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with darktable. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19#include <glib.h>
20#include <stdio.h>
21
22#include "debug.h"
23#include "dng_opcode.h"
24
25#define OPCODE_ID_GAINMAP (9)
26
27static double get_double(uint8_t *ptr)
28{
29 guint64 in;
30 union {
31 guint64 out;
32 double v;
33 } u;
34 memcpy(&in, ptr, sizeof(in));
35 u.out = GUINT64_FROM_BE(in);
36 return u.v;
37}
38
39static float get_float(uint8_t *ptr)
40{
41 guint32 in;
42 union {
43 guint32 out;
44 float v;
45 } u;
46 memcpy(&in, ptr, sizeof(in));
47 u.out = GUINT32_FROM_BE(in);
48 return u.v;
49}
50
51static uint32_t get_long(uint8_t *ptr)
52{
53 uint32_t in;
54 memcpy(&in, ptr, sizeof(in));
55 return GUINT32_FROM_BE(in);
56}
57
58void dt_dng_opcode_process_opcode_list_2(uint8_t *buf, uint32_t buf_size, dt_image_t *img)
59{
60 g_list_free_full(img->dng_gain_maps, dt_free_gpointer);
61 img->dng_gain_maps = NULL;
62
63 uint32_t count = get_long(&buf[0]);
64 uint32_t offset = 4;
65 while(count > 0)
66 {
67 uint32_t opcode_id = get_long(&buf[offset]);
68 uint32_t flags = get_long(&buf[offset + 8]);
69 uint32_t param_size = get_long(&buf[offset + 12]);
70 uint8_t *param = &buf[offset + 16];
71
72 if(offset + 16 + param_size > buf_size)
73 {
74 dt_print(DT_DEBUG_IMAGEIO, "[dng_opcode] Invalid opcode size in OpcodeList2\n");
75 return;
76 }
77
78 if(opcode_id == OPCODE_ID_GAINMAP)
79 {
80 uint32_t gain_count = (param_size - 76) / 4;
81 dt_dng_gain_map_t *gm = g_malloc(sizeof(dt_dng_gain_map_t) + gain_count * sizeof(float));
82 gm->top = get_long(&param[0]);
83 gm->left = get_long(&param[4]);
84 gm->bottom = get_long(&param[8]);
85 gm->right = get_long(&param[12]);
86 gm->plane = get_long(&param[16]);
87 gm->planes = get_long(&param[20]);
88 gm->row_pitch = get_long(&param[24]);
89 gm->col_pitch = get_long(&param[28]);
90 gm->map_points_v = get_long(&param[32]);
91 gm->map_points_h = get_long(&param[36]);
92 gm->map_spacing_v = get_double(&param[40]);
93 gm->map_spacing_h = get_double(&param[48]);
94 gm->map_origin_v = get_double(&param[56]);
95 gm->map_origin_h = get_double(&param[64]);
96 gm->map_planes = get_long(&param[72]);
97 for(int i = 0; i < gain_count; i++)
98 gm->map_gain[i] = get_float(&param[76 + 4*i]);
99
100 img->dng_gain_maps = g_list_append(img->dng_gain_maps, gm);
101 }
102 else
103 {
104 dt_print(DT_DEBUG_IMAGEIO, "[dng_opcode] OpcodeList2 has unsupported %s opcode %d\n",
105 flags & 1 ? "optional" : "mandatory", opcode_id);
106 }
107
108 offset += 16 + param_size;
109 count--;
110 }
111}
const dt_colormatrix_t dt_aligned_pixel_t out
void dt_print(dt_debug_thread_t thread, const char *msg,...)
Definition darktable.c:1542
@ DT_DEBUG_IMAGEIO
Definition darktable.h:733
static void dt_free_gpointer(gpointer ptr)
Definition darktable.h:463
static uint32_t get_long(uint8_t *ptr)
Definition dng_opcode.c:51
static double get_double(uint8_t *ptr)
Definition dng_opcode.c:27
static float get_float(uint8_t *ptr)
Definition dng_opcode.c:39
void dt_dng_opcode_process_opcode_list_2(uint8_t *buf, uint32_t buf_size, dt_image_t *img)
Definition dng_opcode.c:58
#define OPCODE_ID_GAINMAP
Definition dng_opcode.c:25
const float v
dt_mipmap_buffer_dsc_flags flags
Definition mipmap_cache.c:4
const float const float param
uint32_t row_pitch
Definition dng_opcode.h:52
uint32_t map_planes
Definition dng_opcode.h:60
uint32_t map_points_v
Definition dng_opcode.h:54
uint32_t col_pitch
Definition dng_opcode.h:53
uint32_t map_points_h
Definition dng_opcode.h:55
GList * dng_gain_maps
Definition image.h:368