summaryrefslogtreecommitdiff
path: root/var/spack/repos/builtin/packages/gdal/uuid.patch
blob: 3990dad0cd43ae26b7c8bad36019562454048e8c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
diff -Naur jasper-1.900.1/src/libjasper/jp2/jp2_cod.c jasper-1.900.1.uuid/src/libjasper/jp2/jp2_cod.c
--- jasper-1.900.1/src/libjasper/jp2/jp2_cod.c	2007-01-19 15:43:05.000000000 -0600
+++ jasper-1.900.1.uuid/src/libjasper/jp2/jp2_cod.c	2007-03-06 07:49:58.000000000 -0600
@@ -5,6 +5,11 @@
  * All rights reserved.
  */
 
+/*
+ * Modified by Andrey Kiselev <dron@ak4719.spb.edu> to properly handle UUID
+ * box.
+ */
+
 /* __START_OF_JASPER_LICENSE__
  * 
  * JasPer License Version 2.0
@@ -127,6 +132,9 @@
 static int jp2_pclr_getdata(jp2_box_t *box, jas_stream_t *in);
 static int jp2_pclr_putdata(jp2_box_t *box, jas_stream_t *out);
 static void jp2_pclr_dumpdata(jp2_box_t *box, FILE *out);
+static void jp2_uuid_destroy(jp2_box_t *box);
+static int jp2_uuid_getdata(jp2_box_t *box, jas_stream_t *in);
+static int jp2_uuid_putdata(jp2_box_t *box, jas_stream_t *out);
 
 /******************************************************************************\
 * Local data.
@@ -164,7 +172,7 @@
 	{JP2_BOX_XML, "XML", 0,
 	  {0, 0, 0, 0, 0}},
 	{JP2_BOX_UUID, "UUID", 0,
-	  {0, 0, 0, 0, 0}},
+	  {0, jp2_uuid_destroy, jp2_uuid_getdata, jp2_uuid_putdata, 0}},
 	{JP2_BOX_UINF, "UINF", JP2_BOX_SUPER,
 	  {0, 0, 0, 0, 0}},
 	{JP2_BOX_ULST, "ULST", 0,
@@ -271,7 +279,7 @@
 	} else {
 		box->datalen = box->len - JP2_BOX_HDRLEN(false);
 	}
-	if (box->len != 0 && box->len < 8) {
+	if (box->len != 0 && box->len < JP2_BOX_HDRLEN(false)) {
 		goto error;
 	}
 
@@ -876,6 +884,56 @@
 	}
 }
 
+static void jp2_uuid_destroy(jp2_box_t *box)
+{
+	jp2_uuid_t *uuid = &box->data.uuid;
+	if (uuid->data)
+	{
+	    jas_free(uuid->data);
+	    uuid->data = NULL;
+	}
+}
+
+static int jp2_uuid_getdata(jp2_box_t *box, jas_stream_t *in)
+{
+	jp2_uuid_t *uuid = &box->data.uuid;
+	int i;
+	
+	for (i = 0; i < 16; i++)
+	{
+	    if (jp2_getuint8(in, &uuid->uuid[i]))
+		return -1;
+	}
+	
+	uuid->datalen = box->datalen - 16;
+	uuid->data = jas_malloc(uuid->datalen * sizeof(uint_fast8_t));
+	for (i = 0; i < uuid->datalen; i++)
+	{
+	    if (jp2_getuint8(in, &uuid->data[i]))
+		return -1;
+	}
+	return 0;
+}
+
+static int jp2_uuid_putdata(jp2_box_t *box, jas_stream_t *out)
+{
+	jp2_uuid_t *uuid = &box->data.uuid;
+	int i;
+	
+	for (i = 0; i < 16; i++)
+	{
+	    if (jp2_putuint8(out, uuid->uuid[i]))
+		return -1;
+	}
+	
+	for (i = 0; i < uuid->datalen; i++)
+	{
+	    if (jp2_putuint8(out, uuid->data[i]))
+		return -1;
+	}
+	return 0;
+}
+
 static int jp2_getint(jas_stream_t *in, int s, int n, int_fast32_t *val)
 {
 	int c;
diff -Naur jasper-1.900.1/src/libjasper/jp2/jp2_cod.h jasper-1.900.1.uuid/src/libjasper/jp2/jp2_cod.h
--- jasper-1.900.1/src/libjasper/jp2/jp2_cod.h	2007-01-19 15:43:05.000000000 -0600
+++ jasper-1.900.1.uuid/src/libjasper/jp2/jp2_cod.h	2007-03-06 07:49:58.000000000 -0600
@@ -5,6 +5,11 @@
  * All rights reserved.
  */
 
+/*
+ * Modified by Andrey Kiselev <dron@ak4719.spb.edu> to properly handle UUID
+ * box.
+ */
+
 /* __START_OF_JASPER_LICENSE__
  * 
  * JasPer License Version 2.0
@@ -229,6 +234,12 @@
 	jp2_cmapent_t *ents;
 } jp2_cmap_t;
 
+typedef struct {
+	uint_fast32_t datalen;
+	uint_fast8_t uuid[16];
+	uint_fast8_t *data;
+} jp2_uuid_t;
+
 #define	JP2_CMAP_DIRECT		0
 #define	JP2_CMAP_PALETTE	1
 
@@ -257,6 +268,7 @@
 		jp2_pclr_t pclr;
 		jp2_cdef_t cdef;
 		jp2_cmap_t cmap;
+		jp2_uuid_t uuid;
 	} data;
 
 } jp2_box_t;
diff -Naur jasper-1.900.1/src/libjasper/jp2/jp2_enc.c jasper-1.900.1.uuid/src/libjasper/jp2/jp2_enc.c
--- jasper-1.900.1/src/libjasper/jp2/jp2_enc.c	2007-01-19 15:43:05.000000000 -0600
+++ jasper-1.900.1.uuid/src/libjasper/jp2/jp2_enc.c	2007-03-06 07:49:58.000000000 -0600
@@ -5,6 +5,11 @@
  * All rights reserved.
  */
 
+/*
+ * Modified by Andrey Kiselev <dron@ak4719.spb.edu> to properly handle UUID
+ * box.
+ */
+
 /* __START_OF_JASPER_LICENSE__
  * 
  * JasPer License Version 2.0
@@ -86,7 +91,7 @@
 * Functions.
 \******************************************************************************/
 
-int jp2_encode(jas_image_t *image, jas_stream_t *out, char *optstr)
+int jp2_write_header(jas_image_t *image, jas_stream_t *out)
 {
 	jp2_box_t *box;
 	jp2_ftyp_t *ftyp;
@@ -97,8 +102,6 @@
 	long len;
 	uint_fast16_t cmptno;
 	jp2_colr_t *colr;
-	char buf[4096];
-	uint_fast32_t overhead;
 	jp2_cdefchan_t *cdefchanent;
 	jp2_cdef_t *cdef;
 	int i;
@@ -326,6 +329,26 @@
 	jas_stream_close(tmpstream);
 	tmpstream = 0;
 
+	return 0;
+	abort();
+
+error:
+
+	if (box) {
+		jp2_box_destroy(box);
+	}
+	if (tmpstream) {
+		jas_stream_close(tmpstream);
+	}
+	return -1;
+}
+
+int jp2_write_codestream(jas_image_t *image, jas_stream_t *out, char *optstr)
+{
+	jp2_box_t *box;
+	char buf[4096];
+	uint_fast32_t overhead;
+
 	/*
 	 * Output the contiguous code stream box.
 	 */
@@ -358,12 +381,34 @@
 	if (box) {
 		jp2_box_destroy(box);
 	}
-	if (tmpstream) {
-		jas_stream_close(tmpstream);
-	}
 	return -1;
 }
 
+int jp2_encode(jas_image_t *image, jas_stream_t *out, char *optstr)
+{
+	if (jp2_write_header(image, out) < 0)
+		return -1;
+	if (jp2_write_codestream(image, out, optstr) < 0)
+		return -1;
+
+	return 0;
+}
+
+int jp2_encode_uuid(jas_image_t *image, jas_stream_t *out,
+		    char *optstr, jp2_box_t *uuid)
+{
+	if (jp2_write_header(image, out) < 0)
+		return -1;
+	if (uuid) {
+		if (jp2_box_put(uuid, out))
+			return -1;
+	}
+	if (jp2_write_codestream(image, out, optstr) < 0)
+		return -1;
+
+	return 0;
+}
+
 static uint_fast32_t jp2_gettypeasoc(int colorspace, int ctype)
 {
 	int type;