1/*
2 * Copyright 2021, J��r��me Duval, jerome.duval@gmail.com.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef LIBRAW_H
6#define LIBRAW_H
7
8
9#include <DataIO.h>
10#include <SupportDefs.h>
11
12#include <libraw/libraw_const.h>
13
14
15class LibRaw;
16class LibRaw_haiku_datastream;
17
18
19struct image_meta_info {
20	char	manufacturer[64];
21	char	model[64];
22	char	software[64];
23	float	flash_used;
24	float	iso_speed;
25	float	shutter;
26	float	aperture;
27	float	focal_length;
28	double	pixel_aspect;
29	uint32	raw_width;
30	uint32	raw_height;
31	int		flip;
32	uint32	dng_version;
33	uint32	shot_order;
34	int32	black;
35	int32	maximum;
36	float	camera_multipliers[4];
37	float	pre_multipliers[4];
38	float	rgb_camera[3][4];	/* RGB from camera color */
39	time_t	timestamp;
40};
41
42struct image_data_info {
43	uint32	width;
44	uint32	height;
45	uint32	output_width;
46	uint32	output_height;
47	uint32	bits_per_sample;
48	uint32	compression;
49	uint32	photometric_interpretation;
50	uint32	flip;
51	uint32	samples;
52	uint32	bytes;
53	off_t	data_offset;
54	bool	is_raw;
55};
56
57#define COMPRESSION_NONE		1
58#define COMPRESSION_OLD_JPEG	6		// Old JPEG (before 6.0)
59#define COMPRESSION_PACKBITS	32773	// Macintosh RLE
60
61
62typedef void (*monitor_hook)(const char* message, float percentage, void* data);
63
64class LibRAW {
65public:
66								LibRAW(BPositionIO& stream);
67								~LibRAW();
68
69			status_t			Identify();
70			status_t			ReadImageAt(uint32 index, uint8*& outputBuffer,
71									size_t& bufferSize);
72
73			void				GetMetaInfo(image_meta_info& metaInfo) const;
74			uint32				CountImages() const;
75			status_t			ImageAt(uint32 index, image_data_info& info)
76									const;
77
78			status_t			GetEXIFTag(off_t& offset, size_t& length,
79									bool& bigEndian) const;
80			void				SetProgressMonitor(monitor_hook hook,
81									void* data);
82
83			void				SetHalfSize(bool half);
84
85private:
86	static	int					ProgressCallback(void *data,
87									enum LibRaw_progress p,
88									int iteration, int expected);
89			int					_ProgressCallback(enum LibRaw_progress p,
90									int iteration, int expected);
91
92			monitor_hook		fProgressMonitor;
93			void*				fProgressData;
94
95			LibRaw*				fRaw;
96			LibRaw_haiku_datastream* fDatastream;
97};
98
99
100#endif	// LIBRAW_H
101