18
# include <evil_private.h> /* mmap */
26
#define DATA32 unsigned int
27
#define DATA8 unsigned char
29
#define ARGB_JOIN(a,r,g,b) \
30
(((a) << 24) + ((r) << 16) + ((g) << 8) + (b))
35
#define D(fmt, args...) fprintf(stderr, fmt, ## args)
37
#define D(fmt, args...)
41
static size_t seg_size = 0;
42
static unsigned char *seg = MAP_FAILED;
43
static libraw_data_t *raw_data = NULL;
44
static void *data = NULL;
49
_raw_init(const char *file)
52
fd = open(file, O_RDONLY);
53
if (fd < 0) return EINA_FALSE;
55
if (stat(file, &ss)) goto close_file;
56
seg_size = ss.st_size;
57
seg = mmap(NULL, seg_size, PROT_READ, MAP_SHARED, fd, 0);
58
if (seg == MAP_FAILED) goto close_file;
61
raw_data = libraw_init(0);
62
raw_data->params.half_size = 0;
63
raw_data->params.user_qual = 2;
65
D("raw_open_buffer\n");
66
if (libraw_open_buffer(raw_data, seg, seg_size) != LIBRAW_SUCCESS)
80
libraw_close(raw_data);
81
if (seg != MAP_FAILED) munmap(seg, seg_size);
90
D("raw_open_buffer\n");
91
if ((ret = libraw_open_buffer(raw_data, seg, seg_size)) != LIBRAW_SUCCESS)
94
D("raw_adjust_size\n");
95
if ((ret = libraw_adjust_sizes_info_only(raw_data)) != LIBRAW_SUCCESS)
97
if (LIBRAW_FATAL_ERROR(ret))
101
if ((raw_data->sizes.width < 1) || (raw_data->sizes.height < 1))
104
width = raw_data->sizes.iwidth;
105
height = raw_data->sizes.iheight;
117
libraw_processed_image_t *image = NULL;
122
D("raw_open_unpack\n");
123
if ((ret = libraw_unpack(raw_data)) != LIBRAW_SUCCESS)
126
D("raw_dcraw_process\n");
127
if ((ret = libraw_dcraw_process(raw_data)) != LIBRAW_SUCCESS)
129
if (LIBRAW_FATAL_ERROR(ret))
133
D("raw_make_mem_image\n");
134
image = libraw_dcraw_make_mem_image(raw_data, &ret);
137
if ((image->width < 1) || (image->height < 1))
139
width = image->width;
140
height = image->height;
141
if (image->type != LIBRAW_IMAGE_BITMAP)
143
if (image->colors != 3)
145
#define SWAP(a, b) { a ^= b; a = (b ^=a); }
146
if ((image->bits == 16) && (eina_htons(0x55aa) != 0x55aa))
147
for (count = 0; count < image->data_size; count +=2)
148
SWAP(image->data[count], image->data[count + 1]);
150
shm_alloc((unsigned int)(image->width * image->height) * (sizeof(DATA32)));
154
memset(shm_addr, 0, (unsigned int)(image->width * image->height) * (sizeof(DATA32)));
156
bufptr = image->data;
157
for (count = (unsigned int)(image->width * image->height); count > 0; --count)
159
*dataptr = ARGB_JOIN(0xff, bufptr[0], bufptr[1], bufptr[2]);
174
int main(int argc, char **argv)
180
if (argc < 2) return -1;
183
for (i = 2; i < argc; ++i)
185
if (!strcmp(argv[i], "-head"))
187
else if (!strcmp(argv[i], "-key"))
188
{ // not used by raw loader
190
// const char *key = argv[i];
192
else if (!strcmp(argv[i], "-opt-scale-down-by"))
193
{ // not used by raw loader
195
// int scale_down = atoi(argv[i]);
197
else if (!strcmp(argv[i], "-opt-dpi"))
198
{ // not used by raw loader
200
// double dpi = ((double)atoi(argv[i])) / 1000.0;
202
else if (!strcmp(argv[i], "-opt-size"))
203
{ // not used by raw loader
205
// int size_w = atoi(argv[i]);
207
// int size_h = atoi(argv[i]);
213
if (!_raw_init(file)) return -1;
216
if (read_raw_header())
218
printf("size %d %d\n", width, height);
227
printf("size %d %d\n", width, height);
230
if (shm_fd) printf("shmfile %s\n", shmfile);
232
if (shm_fd >= 0) printf("shmfile %s\n", shmfile);
238
(unsigned int)(width * height) * sizeof(DATA32),