1 /*
2
3 test5.c -- RasterLite2 Test Case
4
5 Author: Alessandro Furieri <a.furieri@lqt.it>
6
7 ------------------------------------------------------------------------------
8
9 Version: MPL 1.1/GPL 2.0/LGPL 2.1
10
11 The contents of this file are subject to the Mozilla Public License Version
12 1.1 (the "License"); you may not use this file except in compliance with
13 the License. You may obtain a copy of the License at
14 http://www.mozilla.org/MPL/
15
16 Software distributed under the License is distributed on an "AS IS" basis,
17 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
18 for the specific language governing rights and limitations under the
19 License.
20
21 The Original Code is the SpatiaLite library
22
23 The Initial Developer of the Original Code is Alessandro Furieri
24
25 Portions created by the Initial Developer are Copyright (C) 2013
26 the Initial Developer. All Rights Reserved.
27
28 Contributor(s):
29
30 Alternatively, the contents of this file may be used under the terms of
31 either the GNU General Public License Version 2 or later (the "GPL"), or
32 the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
33 in which case the provisions of the GPL or the LGPL are applicable instead
34 of those above. If you wish to allow use of your version of this file only
35 under the terms of either the GPL or the LGPL, and not to allow others to
36 use your version of this file under the terms of the MPL, indicate your
37 decision by deleting the provisions above and replace them with the notice
38 and other provisions required by the GPL or the LGPL. If you do not delete
39 the provisions above, a recipient may use your version of this file under
40 the terms of any one of the MPL, the GPL or the LGPL.
41 */
42 #include <stdlib.h>
43 #include <unistd.h>
44 #include <stdio.h>
45
46 #include "rasterlite2/rasterlite2.h"
47
48 static int
naturalEndian()49 naturalEndian ()
50 {
51 /* ensures to always encode in the natural endian order */
52 union cvt
53 {
54 unsigned char byte[4];
55 int int_value;
56 } convert;
57 convert.int_value = 1;
58 if (convert.byte[0] == 0)
59 return 0;
60 return 1;
61 }
62
63 static rl2PalettePtr
create_palette()64 create_palette ()
65 {
66 /* creating a "bicolor" palette */
67 rl2PalettePtr palette = rl2_create_palette (2);
68 if (palette == NULL)
69 goto error;
70 if (rl2_set_palette_color (palette, 0, 255, 255, 204) != RL2_OK)
71 goto error;
72 if (rl2_set_palette_color (palette, 1, 128, 204, 232) != RL2_OK)
73 goto error;
74 return palette;
75 error:
76 return NULL;
77 }
78
79 static rl2SectionPtr
create_bicolor()80 create_bicolor ()
81 {
82 /* creating a synthetic "bicolor" image */
83 rl2SectionPtr scn;
84 rl2RasterPtr rst;
85 rl2PalettePtr palette = create_palette ();
86 int row;
87 int col;
88 int bufsize = 1024 * 1024;
89 int mode = 0;
90 unsigned char *bufpix = malloc (bufsize);
91 unsigned char *p = bufpix;
92
93 if (bufpix == NULL)
94 return NULL;
95 if (palette == NULL)
96 goto error;
97
98 for (row = 0; row < 1024; row++)
99 {
100 for (col = 0; col < 1024; col++)
101 *p++ = 0;
102 }
103 p = bufpix;
104
105 for (row = 0; row < 256; row += 4)
106 {
107 int mode2 = mode;
108 for (col = 0; col < 1024; col += 4)
109 {
110 if (mode2)
111 {
112 *p++ = 1;
113 *p++ = 1;
114 *p++ = 1;
115 *p++ = 1;
116 mode2 = 0;
117 }
118 else
119 {
120 p += 4;
121 mode2 = 1;
122 }
123 }
124 mode2 = mode;
125 for (col = 0; col < 1024; col += 4)
126 {
127 if (mode2)
128 {
129 *p++ = 1;
130 *p++ = 1;
131 *p++ = 1;
132 *p++ = 1;
133 mode2 = 0;
134 }
135 else
136 {
137 p += 4;
138 mode2 = 1;
139 }
140 }
141 mode2 = mode;
142 for (col = 0; col < 1024; col += 4)
143 {
144 if (mode2)
145 {
146 *p++ = 1;
147 *p++ = 1;
148 *p++ = 1;
149 *p++ = 1;
150 mode2 = 0;
151 }
152 else
153 {
154 p += 4;
155 mode2 = 1;
156 }
157 }
158 mode2 = mode;
159 for (col = 0; col < 1024; col += 4)
160 {
161 if (mode2)
162 {
163 *p++ = 1;
164 *p++ = 1;
165 *p++ = 1;
166 *p++ = 1;
167 mode2 = 0;
168 }
169 else
170 {
171 p += 4;
172 mode2 = 1;
173 }
174 }
175 if (mode)
176 mode = 0;
177 else
178 mode = 1;
179 }
180
181 for (row = 256; row < 512; row += 8)
182 {
183 int mode2 = mode;
184 for (col = 0; col < 1024; col += 8)
185 {
186 if (mode2)
187 {
188 *p++ = 1;
189 *p++ = 1;
190 *p++ = 1;
191 *p++ = 1;
192 *p++ = 1;
193 *p++ = 1;
194 *p++ = 1;
195 *p++ = 1;
196 mode2 = 0;
197 }
198 else
199 {
200 p += 8;
201 mode2 = 1;
202 }
203 }
204 mode2 = mode;
205 for (col = 0; col < 1024; col += 8)
206 {
207 if (mode2)
208 {
209 *p++ = 1;
210 *p++ = 1;
211 *p++ = 1;
212 *p++ = 1;
213 *p++ = 1;
214 *p++ = 1;
215 *p++ = 1;
216 *p++ = 1;
217 mode2 = 0;
218 }
219 else
220 {
221 p += 8;
222 mode2 = 1;
223 }
224 }
225 mode2 = mode;
226 for (col = 0; col < 1024; col += 8)
227 {
228 if (mode2)
229 {
230 *p++ = 1;
231 *p++ = 1;
232 *p++ = 1;
233 *p++ = 1;
234 *p++ = 1;
235 *p++ = 1;
236 *p++ = 1;
237 *p++ = 1;
238 mode2 = 0;
239 }
240 else
241 {
242 p += 8;
243 mode2 = 1;
244 }
245 }
246 mode2 = mode;
247 for (col = 0; col < 1024; col += 8)
248 {
249 if (mode2)
250 {
251 *p++ = 1;
252 *p++ = 1;
253 *p++ = 1;
254 *p++ = 1;
255 *p++ = 1;
256 *p++ = 1;
257 *p++ = 1;
258 *p++ = 1;
259 mode2 = 0;
260 }
261 else
262 {
263 p += 8;
264 mode2 = 1;
265 }
266 }
267 for (col = 0; col < 1024; col += 8)
268 {
269 if (mode2)
270 {
271 *p++ = 1;
272 *p++ = 1;
273 *p++ = 1;
274 *p++ = 1;
275 *p++ = 1;
276 *p++ = 1;
277 *p++ = 1;
278 *p++ = 1;
279 mode2 = 0;
280 }
281 else
282 {
283 p += 8;
284 mode2 = 1;
285 }
286 }
287 mode2 = mode;
288 for (col = 0; col < 1024; col += 8)
289 {
290 if (mode2)
291 {
292 *p++ = 1;
293 *p++ = 1;
294 *p++ = 1;
295 *p++ = 1;
296 *p++ = 1;
297 *p++ = 1;
298 *p++ = 1;
299 *p++ = 1;
300 mode2 = 0;
301 }
302 else
303 {
304 p += 8;
305 mode2 = 1;
306 }
307 }
308 mode2 = mode;
309 for (col = 0; col < 1024; col += 8)
310 {
311 if (mode2)
312 {
313 *p++ = 1;
314 *p++ = 1;
315 *p++ = 1;
316 *p++ = 1;
317 *p++ = 1;
318 *p++ = 1;
319 *p++ = 1;
320 *p++ = 1;
321 mode2 = 0;
322 }
323 else
324 {
325 p += 8;
326 mode2 = 1;
327 }
328 }
329 mode2 = mode;
330 for (col = 0; col < 1024; col += 8)
331 {
332 if (mode2)
333 {
334 *p++ = 1;
335 *p++ = 1;
336 *p++ = 1;
337 *p++ = 1;
338 *p++ = 1;
339 *p++ = 1;
340 *p++ = 1;
341 *p++ = 1;
342 mode2 = 0;
343 }
344 else
345 {
346 p += 8;
347 mode2 = 1;
348 }
349 }
350 if (mode)
351 mode = 0;
352 else
353 mode = 1;
354 }
355
356 for (row = 512; row < 768; row++)
357 {
358 int mode2 = 1;
359 for (col = 0; col < 1024; col += 8)
360 {
361 if (mode2)
362 {
363 *p++ = 1;
364 *p++ = 1;
365 *p++ = 1;
366 *p++ = 1;
367 *p++ = 1;
368 *p++ = 1;
369 *p++ = 1;
370 *p++ = 1;
371 mode2 = 0;
372 }
373 else
374 {
375 p += 8;
376 mode2 = 1;
377 }
378 }
379 }
380
381 mode = 1;
382 for (row = 768; row < 1024; row += 8)
383 {
384 int x;
385 for (x = 0; x < 8; x++)
386 {
387 for (col = 0; col < 1024; col++)
388 {
389 if (mode)
390 *p++ = 1;
391 else
392 p++;
393 }
394 }
395 if (mode)
396 mode = 0;
397 else
398 mode = 1;
399 }
400
401 rst =
402 rl2_create_raster (1024, 1024, RL2_SAMPLE_1_BIT, RL2_PIXEL_PALETTE, 1,
403 bufpix, bufsize, palette, NULL, 0, NULL);
404 if (rst == NULL)
405 goto error;
406
407 scn = rl2_create_section ("bicolor", RL2_COMPRESSION_NONE,
408 RL2_TILESIZE_UNDEFINED, RL2_TILESIZE_UNDEFINED,
409 rst);
410 if (scn == NULL)
411 rl2_destroy_raster (rst);
412 return scn;
413 error:
414 free (bufpix);
415 if (palette != NULL)
416 rl2_destroy_palette (palette);
417 return NULL;
418 }
419
420 static int
test_bicolor(rl2SectionPtr img)421 test_bicolor (rl2SectionPtr img)
422 {
423 /* testing BICOLOR buffer functions */
424 unsigned char *buffer;
425 int buf_size;
426 int width = 1024;
427 unsigned char *p_data1;
428 unsigned char *p_data2;
429 unsigned char sample;
430 unsigned char sample_type;
431 unsigned char pixel_type;
432 unsigned char num_bands;
433 rl2PixelPtr pxl;
434 rl2RasterPtr rst;
435
436 rst = rl2_get_section_raster (img);
437 if (rst == NULL)
438 {
439 fprintf (stderr, "BICOLOR invalid raster pointer\n");
440 return 0;
441 }
442
443 if (rl2_raster_data_to_RGB (rst, &buffer, &buf_size) != RL2_OK)
444 {
445 fprintf (stderr, "Unable to get RGB data: BICOLOR\n");
446 return 0;
447 }
448 p_data1 = buffer + (20 * width * 3) + (20 * 3);
449 p_data2 = buffer + (720 * width * 3) + (530 * 3);
450 if (*(p_data1 + 0) != 255 || *(p_data1 + 1) != 255 || *(p_data1 + 2) != 204)
451 {
452 fprintf (stderr, "Unexpected RGB pixel #1: BICOLOR\n");
453 return 0;
454 }
455 if (*(p_data2 + 0) != 128 || *(p_data2 + 1) != 204 || *(p_data2 + 2) != 232)
456 {
457 fprintf (stderr, "Unexpected RGB pixel #2: BICOLOR\n");
458 return 0;
459 }
460 rl2_free (buffer);
461
462 if (rl2_raster_data_to_RGBA (rst, &buffer, &buf_size) != RL2_OK)
463 {
464 fprintf (stderr, "Unable to get RGBA data: BICOLOR\n");
465 return 0;
466 }
467 p_data1 = buffer + (20 * width * 4) + (20 * 4);
468 p_data2 = buffer + (720 * width * 4) + (530 * 4);
469 if (*(p_data1 + 0) != 255 || *(p_data1 + 1) != 255 || *(p_data1 + 2) != 204
470 || *(p_data1 + 3) != 255)
471 {
472 fprintf (stderr, "Unexpected RGBA pixel #1: BICOLOR\n");
473 return 0;
474 }
475 if (*(p_data2 + 0) != 128 || *(p_data2 + 1) != 204 || *(p_data2 + 2) != 232
476 || *(p_data2 + 3) != 255)
477 {
478 fprintf (stderr, "Unexpected RGBA pixel #2: BICOLOR\n");
479 return 0;
480 }
481 rl2_free (buffer);
482
483 if (rl2_raster_data_to_ARGB (rst, &buffer, &buf_size) != RL2_OK)
484 {
485 fprintf (stderr, "Unable to get ARGB data: BICOLOR\n");
486 return 0;
487 }
488 p_data1 = buffer + (20 * width * 4) + (20 * 4);
489 p_data2 = buffer + (720 * width * 4) + (530 * 4);
490 if (*(p_data1 + 0) != 255 || *(p_data1 + 1) != 255 || *(p_data1 + 2) != 255
491 || *(p_data1 + 3) != 204)
492 {
493 fprintf (stderr, "Unexpected ARGB pixel #1: BICOLOR\n");
494 return 0;
495 }
496 if (*(p_data2 + 0) != 255 || *(p_data2 + 1) != 128 || *(p_data2 + 2) != 204
497 || *(p_data2 + 3) != 232)
498 {
499 fprintf (stderr, "Unexpected ARGB pixel #2: BICOLOR\n");
500 return 0;
501 }
502 rl2_free (buffer);
503
504 if (rl2_raster_data_to_BGR (rst, &buffer, &buf_size) != RL2_OK)
505 {
506 fprintf (stderr, "Unable to get BGR data: BICOLOR\n");
507 return 0;
508 }
509 p_data1 = buffer + (20 * width * 3) + (20 * 3);
510 p_data2 = buffer + (720 * width * 3) + (530 * 3);
511 if (*(p_data1 + 0) != 204 || *(p_data1 + 1) != 255 || *(p_data1 + 2) != 255)
512 {
513 fprintf (stderr, "Unexpected BGR pixel #1: BICOLOR\n");
514 return 0;
515 }
516 if (*(p_data2 + 0) != 232 || *(p_data2 + 1) != 204 || *(p_data2 + 2) != 128)
517 {
518 fprintf (stderr, "Unexpected BGR pixel #2: BICOLOR\n");
519 return 0;
520 }
521 rl2_free (buffer);
522
523 if (rl2_raster_data_to_BGRA (rst, &buffer, &buf_size) != RL2_OK)
524 {
525 fprintf (stderr, "Unable to get BGRA data: BICOLOR\n");
526 return 0;
527 }
528 p_data1 = buffer + (20 * width * 4) + (20 * 4);
529 p_data2 = buffer + (720 * width * 4) + (530 * 4);
530 if (*(p_data1 + 0) != 204 || *(p_data1 + 1) != 255 || *(p_data1 + 2) != 255
531 || *(p_data1 + 3) != 255)
532 {
533 fprintf (stderr, "Unexpected BGRA pixel #1: BICOLOR\n");
534 return 0;
535 }
536 if (*(p_data2 + 0) != 232 || *(p_data2 + 1) != 204 || *(p_data2 + 2) != 128
537 || *(p_data2 + 3) != 255)
538 {
539 fprintf (stderr, "Unexpected BGRA pixel #2: BICOLOR\n");
540 return 0;
541 }
542 rl2_free (buffer);
543
544 if (rl2_raster_data_to_1bit (rst, &buffer, &buf_size) != RL2_OK)
545 {
546 fprintf (stderr, "Unable to get 1-BIT data: BICOLOR\n");
547 return 0;
548 }
549 p_data1 = buffer + (20 * width) + 20;
550 p_data2 = buffer + (720 * width) + 530;
551 if (*p_data1 != 0)
552 {
553 fprintf (stderr, "Unexpected 1-BIT pixel #1: BICOLOR\n");
554 return 0;
555 }
556 if (*p_data2 != 1)
557 {
558 fprintf (stderr, "Unexpected 1-BIT pixel #2: BICOLOR\n");
559 return 0;
560 }
561 rl2_free (buffer);
562
563 pxl = rl2_create_raster_pixel (rst);
564 if (pxl == NULL)
565 {
566 fprintf (stderr, "Unable to create Pixel for Raster: BICOLOR\n");
567 return 0;
568 }
569
570 if (rl2_get_raster_pixel (rst, pxl, 20, 20) != RL2_OK)
571 {
572 fprintf (stderr,
573 "Unable to get Pixel (20,20) from Raster: BICOLOR\n");
574 return 0;
575 }
576
577 if (rl2_get_pixel_type (pxl, &sample_type, &pixel_type, &num_bands) !=
578 RL2_OK)
579 {
580 fprintf (stderr, "Unable to create get Pixel Type: BICOLOR\n");
581 return 0;
582 }
583
584 if (sample_type != RL2_SAMPLE_1_BIT)
585 {
586 fprintf (stderr, "Unexpected Pixel SampleType: BICOLOR\n");
587 return 0;
588 }
589
590 if (pixel_type != RL2_PIXEL_PALETTE)
591 {
592 fprintf (stderr, "Unexpected Pixel Type: BICOLOR\n");
593 return 0;
594 }
595
596 if (num_bands != 1)
597 {
598 fprintf (stderr, "Unexpected Pixel # Bands: BICOLOR\n");
599 return 0;
600 }
601
602 if (rl2_get_pixel_sample_1bit (pxl, &sample) != RL2_OK)
603 {
604 fprintf (stderr, "Unexpected Pixel 1-BIT: BICOLOR\n");
605 return 0;
606 }
607
608 if (sample != 0)
609 {
610 fprintf (stderr,
611 "Unexpected Pixel 1-BIT Sample value %d: BICOLOR\n", sample);
612 return 0;
613 }
614
615 if (rl2_set_pixel_sample_1bit (pxl, sample) != RL2_OK)
616 {
617 fprintf (stderr, "Unexpected Pixel SetSample 1-BIT: BICOLOR\n");
618 return 0;
619 }
620
621 if (rl2_set_pixel_sample_1bit (pxl, 2) != RL2_ERROR)
622 {
623 fprintf (stderr,
624 "Unexpected Pixel SetSample 1-BIT (exceeding value): BICOLOR\n");
625 return 0;
626 }
627
628 if (rl2_set_raster_pixel (rst, pxl, 20, 20) != RL2_OK)
629 {
630 fprintf (stderr,
631 "Unable to set Pixel (20,20) into Raster: BICOLOR\n");
632 return 0;
633 }
634
635 rl2_destroy_pixel (pxl);
636
637 return 1;
638 }
639
640 int
main(int argc,char * argv[])641 main (int argc, char *argv[])
642 {
643 rl2SectionPtr img;
644 rl2RasterPtr raster;
645 rl2RasterStatisticsPtr stats;
646 unsigned char *blob_odd;
647 int blob_odd_sz;
648 unsigned char *blob_even;
649 int blob_even_sz;
650 unsigned char *blob_odd_zip;
651 int blob_odd_sz_zip;
652 unsigned char *blob_even_zip;
653 int blob_even_sz_zip;
654 unsigned char *blob_odd_lzma;
655 int blob_odd_sz_lzma;
656 unsigned char *blob_even_lzma;
657 int blob_even_sz_lzma;
658 unsigned char *blob_odd_png;
659 int blob_odd_sz_png;
660 unsigned char *blob_even_png;
661 int blob_even_sz_png;
662 unsigned char *blob_odd_gif;
663 int blob_odd_sz_gif;
664 unsigned char *blob_even_gif;
665 int blob_even_sz_gif;
666 int endian = naturalEndian ();
667 rl2PalettePtr palette;
668 rl2PalettePtr plt2;
669 unsigned char *blob_stat;
670 int blob_stat_size;
671
672 if (argc > 1 || argv[0] == NULL)
673 argc = 1; /* silencing stupid compiler warnings */
674
675 img = create_bicolor ();
676 if (img == NULL)
677 {
678 fprintf (stderr, "Unable to create image: bicolor\n");
679 return -1;
680 }
681
682 if (rl2_section_to_jpeg (img, "./bicolor.jpg", 70) != RL2_OK)
683 {
684 fprintf (stderr, "Unable to write: bicolor.jpg\n");
685 return -2;
686 }
687
688 if (rl2_section_to_png (img, "./bicolor.png") != RL2_OK)
689 {
690 fprintf (stderr, "Unable to write: bicolor.png\n");
691 return -3;
692 }
693
694 if (!test_bicolor (img))
695 return -4;
696
697 rl2_destroy_section (img);
698
699 unlink ("./bicolor.jpg");
700
701 img = rl2_section_from_png ("./bicolor.png");
702 if (img == NULL)
703 {
704 fprintf (stderr, "Unable to read: %s\n", "./bicolor.png");
705 return -5;
706 }
707
708 unlink ("./bicolor.png");
709
710 if (rl2_section_to_png (img, "./from_bicolor.png") != RL2_OK)
711 {
712 fprintf (stderr, "Unable to write: from_bicolor.png\n");
713 return -6;
714 }
715
716 unlink ("./from_bicolor.png");
717
718 raster = rl2_get_section_raster (img);
719 if (raster == NULL)
720 {
721 fprintf (stderr, "Unable to retrieve the raster pointer\n");
722 return -7;
723 }
724
725 if (rl2_raster_encode
726 (raster, RL2_COMPRESSION_NONE, &blob_odd, &blob_odd_sz, &blob_even,
727 &blob_even_sz, 0, endian) != RL2_OK)
728 {
729 fprintf (stderr, "Unable to Encode - uncompressed\n");
730 return -8;
731 }
732
733 if (rl2_raster_encode
734 (raster, RL2_COMPRESSION_DEFLATE, &blob_odd_zip, &blob_odd_sz_zip,
735 &blob_even_zip, &blob_even_sz_zip, 0, endian) == RL2_OK)
736 {
737 fprintf (stderr, "Unexpected result - compressed DEFLATE\n");
738 return -9;
739 }
740
741 if (rl2_raster_encode
742 (raster, RL2_COMPRESSION_LZMA, &blob_odd_lzma, &blob_odd_sz_lzma,
743 &blob_even_lzma, &blob_even_sz_lzma, 0, endian) == RL2_OK)
744 {
745 fprintf (stderr, "Unexpected result - compressed LZMA\n");
746 return -10;
747 }
748
749 if (rl2_raster_encode
750 (raster, RL2_COMPRESSION_PNG, &blob_odd_png, &blob_odd_sz_png,
751 &blob_even_png, &blob_even_sz_png, 0, endian) != RL2_OK)
752 {
753 fprintf (stderr, "Unable to Encode - compressed PNG\n");
754 return -11;
755 }
756
757 plt2 = rl2_clone_palette (rl2_get_raster_palette (raster));
758 stats =
759 rl2_get_raster_statistics (blob_odd_png, blob_odd_sz_png,
760 blob_even_png, blob_even_sz_png, plt2, NULL);
761 if (stats == NULL)
762 {
763 fprintf (stderr, "Unable to get Raster Statistics\n");
764 return -100;
765 }
766 if (rl2_serialize_dbms_raster_statistics
767 (stats, &blob_stat, &blob_stat_size) != RL2_OK)
768 {
769 fprintf (stderr, "Unable to serialize Raster Statistics\n");
770 return -101;
771 }
772 rl2_destroy_raster_statistics (stats);
773 stats = rl2_deserialize_dbms_raster_statistics (blob_stat, blob_stat_size);
774 if (stats == NULL)
775 {
776 fprintf (stderr, "Unable to deserialize Raster Statistics\n");
777 return -102;
778 }
779 free (blob_stat);
780 rl2_destroy_raster_statistics (stats);
781
782 if (rl2_raster_encode
783 (raster, RL2_COMPRESSION_GIF, &blob_odd_gif, &blob_odd_sz_gif,
784 &blob_even_gif, &blob_even_sz_gif, 0, endian) == RL2_OK)
785 {
786 fprintf (stderr, "Unexpected result - compressed GIF\n");
787 return -12;
788 }
789
790 rl2_destroy_section (img);
791
792 palette = create_palette ();
793 raster =
794 rl2_raster_decode (RL2_SCALE_1, blob_odd, blob_odd_sz, blob_even,
795 blob_even_sz, palette);
796 if (raster == NULL)
797 {
798 fprintf (stderr, "Unable to Decode 1:1 - uncompressed\n");
799 return -13;
800 }
801
802 img = rl2_create_section ("bicolor 1:1", RL2_COMPRESSION_NONE,
803 RL2_TILESIZE_UNDEFINED, RL2_TILESIZE_UNDEFINED,
804 raster);
805 if (img == NULL)
806 {
807 fprintf (stderr, "Unable to create a Section 1:1 - uncompressed\n");
808 return -14;
809 }
810
811 if (rl2_section_to_png (img, "./bicolor_1_1_uncompressed.png") != RL2_OK)
812 {
813 fprintf (stderr, "Unable to write: bicolor_1_1_uncompressed.png\n");
814 return -15;
815 }
816 rl2_destroy_section (img);
817
818 unlink ("./bicolor_1_1_uncompressed.png");
819
820 if (rl2_raster_decode (RL2_SCALE_2, blob_odd, blob_odd_sz, blob_even,
821 blob_even_sz, NULL) != NULL)
822 {
823 fprintf (stderr, "Unexpected result: Decode 1:2 - uncompressed\n");
824 return -16;
825 }
826
827 if (rl2_raster_decode (RL2_SCALE_4, blob_odd, blob_odd_sz, blob_even,
828 blob_even_sz, NULL) != NULL)
829 {
830 fprintf (stderr, "Unexpected result: Decode 1:4 - uncompressed\n");
831 return -17;
832 }
833
834 if (rl2_raster_decode (RL2_SCALE_8, blob_odd, blob_odd_sz, blob_even,
835 blob_even_sz, NULL) != NULL)
836 {
837 fprintf (stderr, "Unexpected result: Decode 1:8 - uncompressed\n");
838 return -18;
839 }
840 free (blob_odd);
841
842
843
844 raster =
845 rl2_raster_decode (RL2_SCALE_1, blob_odd_png, blob_odd_sz_png,
846 blob_even_png, blob_even_sz_png, NULL);
847 if (raster == NULL)
848 {
849 fprintf (stderr, "Unable to Decode 1:1 - png\n");
850 return -31;
851 }
852
853 img = rl2_create_section ("bicolor 1:1", RL2_COMPRESSION_NONE,
854 RL2_TILESIZE_UNDEFINED, RL2_TILESIZE_UNDEFINED,
855 raster);
856 if (img == NULL)
857 {
858 fprintf (stderr, "Unable to create a Section 1:1 - png\n");
859 return -32;
860 }
861
862 if (rl2_section_to_png (img, "./bicolor_1_1_png.png") != RL2_OK)
863 {
864 fprintf (stderr, "Unable to write: bicolor_1_1_png.png\n");
865 return -33;
866 }
867 rl2_destroy_section (img);
868
869 unlink ("./bicolor_1_1_png.png");
870
871 if (rl2_raster_decode
872 (RL2_SCALE_2, blob_odd_png, blob_odd_sz_png, blob_even_png,
873 blob_even_sz_png, NULL) != NULL)
874 {
875 fprintf (stderr, "Unexpected result: Decode 1:2 - png\n");
876 return -34;
877 }
878 free (blob_odd_png);
879
880 return 0;
881 }
882