Remove generated files
[framework/connectivity/libgphoto2.git] / camlibs / st2205 / st2205.h
1 /* Sitronix st2205 picframe access library
2  *
3  *   Copyright (c) 2010 Hans de Goede <hdegoede@redhat.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation; either version 2.1 of the License, or
8  * (at your option) any later version.
9  *
10  * This program 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 Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19 #ifndef __ST2205_H__
20 #define __ST2205_H__
21 #include "config.h"
22
23 #include <stdio.h>
24 #ifdef HAVE_ICONV
25 #include <iconv.h>
26 #endif
27
28 #include <gphoto2/gphoto2-library.h>
29 #include <gphoto2-endian.h>
30
31 #define GP_MODULE "st2205"
32
33 #define ST2205_CMD_OFFSET 0x6200
34 #define ST2205_WRITE_OFFSET 0x6600
35 #define ST2205_READ_OFFSET 0xb000
36 /* 2 block sizes, first is bytes per transfer, second is bytes per erase /
37    program cycle */
38 #define ST2205_BLOCK_SIZE 32768
39 #define ST2205_ERASE_BLOCK_SIZE 65536
40 #define ST2205_FAT_SIZE 8192
41 #define ST2205_COUNT_OFFSET 0x6
42 /* 16 bytes info per file + a 16 bytes header */
43 #define ST2205_FILE_OFFSET(x) (((x) + 1) * 16)
44 #define ST2205_LOOKUP_SIZE (0x8000 - 0x0477)
45 #define ST2205_V1_LOOKUP_OFFSET 0x8477
46 #define ST2205_V2_LOOKUP_OFFSET 0xd8477
47 #define ST2205_V1_FIRMWARE_SIZE 65536
48 #define ST2205_V2_FIRMWARE_SIZE 262144
49 #define ST2205_V1_PICTURE_START 65536
50 #define ST2205_V2_PICTURE_START 8192
51 #define ST2205_LOOKUP_CHECKSUM 0x0016206f
52 #define ST2205_SHUFFLE_SIZE (240 * 320 / 64)
53 #define ST2205_HEADER_MARKER 0xf5
54 /* The "FAT" cannot contain more then 510 entries */
55 #define ST2205_MAX_NO_FILES 510
56 #define ST2205_FILENAME_LENGTH 10
57
58 enum {
59         ORIENTATION_AUTO,
60         ORIENTATION_LANDSCAPE,
61         ORIENTATION_PORTRAIT,
62 };
63
64 /* We prefix all names with there idx in the FAT table, to make sure they are
65    all unique and don't change when files with the same name (after converting
66    to ascii and truncating) are added / deleted. */
67 #define ST2205_SET_FILENAME(dest, name, idx) \
68         snprintf(dest, sizeof(st2205_filename), "%04d-%s.png", (idx) + 1, name)
69
70 struct st2205_coord {
71         uint16_t x;
72         uint16_t y;
73 };
74
75 struct st2205_image_header {
76         uint8_t marker;   /* Always 0xF5 */
77         uint16_t width;   /* big endian */
78         uint16_t height;  /* big endian */
79         uint16_t blocks;  /* number of 8x8 blocks in the image, big endian */
80         uint8_t shuffle_table; /* shuffle table idx (for transition effects) */
81         uint8_t unknown2; /* Unknown usually 0x04 */
82         uint8_t unknown3; /* shuffle related, must have a special value depend
83                              on the pattern see the table in st2205_init */
84         uint16_t length;  /* length of the data *following* the header (be) */
85         uint8_t unknown4[4]; /* Always 4x 0x00 (padding ?) */
86 } __attribute__((packed));
87
88 #define CHECK(result) {int r=(result); if (r<0) return (r);}
89
90 /* The + 5 is space for the "####-" prefix we add, + 4 for .png postfix. */
91 typedef char st2205_filename[ST2205_FILENAME_LENGTH + 5 + 4 + 1];
92 typedef int16_t st2205_lookup_row[8];
93
94 struct _CameraPrivateLibrary {
95         /* Used by library.c glue code */
96 #ifdef HAVE_ICONV
97         iconv_t cd;
98 #endif
99         st2205_filename filenames[ST2205_MAX_NO_FILES];
100
101         /* Driver configuration settings */
102         int syncdatetime;
103         int orientation;
104
105         /* Used by st2205.c / st2205_decode.c */
106         int width;
107         int height;
108         int compressed; /* Is the image data compressed or rgb565 ? */
109         FILE *mem_dump;
110         char *mem;
111         char *buf; /* 512 bytes aligned buffer (for sending / reading cmds) */
112         int mem_size;
113         int firmware_size;
114         int picture_start;
115         int no_fats;
116         int block_is_present[2097152 / ST2205_BLOCK_SIZE];
117         int block_dirty[2097152 / ST2205_BLOCK_SIZE];
118         st2205_lookup_row lookup[3][256];
119         struct st2205_coord shuffle[8][ST2205_SHUFFLE_SIZE];
120         int no_shuffles;
121         unsigned char unknown3[8];
122         unsigned int rand_seed;
123 };
124
125 /* functions in st2205.c */
126 int
127 st2205_open_device(Camera *camera);
128
129 int
130 st2205_open_dump(Camera *camera, const char *dump,
131                  int width, int height);
132
133 void st2205_close(Camera *camera);
134
135 int
136 st2205_get_filenames(Camera *camera, st2205_filename *names);
137
138 int
139 st2205_read_file(Camera *camera, int idx, int **rgb24);
140
141 int
142 st2205_read_raw_file(Camera *camera, int idx, unsigned char **raw);
143
144 int
145 st2205_set_time_and_date(Camera *camera, struct tm *t);
146
147 /* This function returns the index used to save the file at on success */
148 int
149 st2205_write_file(Camera *camera,
150         const char *filename, int **rgb24);
151
152 int
153 st2205_delete_file(Camera *camera, int idx);
154
155 int
156 st2205_delete_all(Camera *camera);
157
158 int
159 st2205_commit(Camera *camera);
160
161 int
162 st2205_get_mem_size(Camera *camera);
163
164 int
165 st2205_get_free_mem_size(Camera *camera);
166
167 /* functions in st2205_decode.c */
168 int
169 st2205_decode_image(CameraPrivateLibrary *pl, unsigned char *src, int **dest);
170
171 int
172 st2205_code_image(CameraPrivateLibrary *pl, int **src,
173         unsigned char *dest, uint8_t shuffle_pattern, int allow_uv_corr);
174
175 int
176 st2205_rgb565_to_rgb24(CameraPrivateLibrary *pl, unsigned char *src,
177         int **dest);
178
179 int
180 st2205_rgb24_to_rgb565(CameraPrivateLibrary *pl, int **src,
181         unsigned char *dest);
182
183 #endif