2 * The copyright in this software is being made available under the 2-clauses
3 * BSD License, included below. This software may be subject to other third
4 * party and contributor rights, including patent rights, and no such rights
5 * are granted under this license.
7 * Copyright (c) 2017, IntoPix SA <contact@intopix.com>
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
34 #include "opj_includes.h"
38 OPJ_UINT32 i, j, w, h;
39 OPJ_INT32 buffer[ 99 * 101 ];
41 opj_sparse_array_int32_t* sa;
43 sa = opj_sparse_array_int32_create(0, 1, 1, 1);
45 opj_sparse_array_int32_free(sa);
47 sa = opj_sparse_array_int32_create(1, 0, 1, 1);
50 sa = opj_sparse_array_int32_create(1, 1, 0, 1);
53 sa = opj_sparse_array_int32_create(1, 1, 1, 0);
56 sa = opj_sparse_array_int32_create(99, 101, ~0U, ~0U);
59 sa = opj_sparse_array_int32_create(99, 101, 15, 17);
60 opj_sparse_array_int32_free(sa);
62 sa = opj_sparse_array_int32_create(99, 101, 15, 17);
63 ret = opj_sparse_array_int32_read(sa, 0, 0, 0, 1, buffer, 1, 1, OPJ_FALSE);
65 ret = opj_sparse_array_int32_read(sa, 0, 0, 1, 0, buffer, 1, 1, OPJ_FALSE);
67 ret = opj_sparse_array_int32_read(sa, 0, 0, 100, 1, buffer, 1, 1, OPJ_FALSE);
69 ret = opj_sparse_array_int32_read(sa, 0, 0, 1, 102, buffer, 1, 1, OPJ_FALSE);
71 ret = opj_sparse_array_int32_read(sa, 1, 0, 0, 1, buffer, 1, 1, OPJ_FALSE);
73 ret = opj_sparse_array_int32_read(sa, 0, 1, 1, 0, buffer, 1, 1, OPJ_FALSE);
75 ret = opj_sparse_array_int32_read(sa, 99, 101, 99, 101, buffer, 1, 1,
80 ret = opj_sparse_array_int32_read(sa, 0, 0, 1, 1, buffer, 1, 1, OPJ_FALSE);
82 assert(buffer[0] == 0);
84 memset(buffer, 0xFF, sizeof(buffer));
85 ret = opj_sparse_array_int32_read(sa, 0, 0, 99, 101, buffer, 1, 99, OPJ_FALSE);
87 for (i = 0; i < 99 * 101; i++) {
88 assert(buffer[i] == 0);
92 ret = opj_sparse_array_int32_write(sa, 4, 5, 4 + 1, 5 + 1, buffer, 1, 1,
96 ret = opj_sparse_array_int32_write(sa, 4, 5, 4 + 1, 5 + 1, buffer, 1, 1,
102 ret = opj_sparse_array_int32_read(sa, 4, 5, 4 + 1, 5 + 1, buffer, 1, 1,
105 assert(buffer[0] == 2);
106 assert(buffer[1] == 0xFF);
110 memset(buffer, 0xFF, sizeof(buffer));
111 ret = opj_sparse_array_int32_read(sa, 2, 1, 2 + w, 1 + h, buffer, 1, w,
114 for (j = 0; j < h; j++) {
115 for (i = 0; i < w; i++) {
116 if (i == 4 - 2 && j == 5 - 1) {
117 assert(buffer[ j * w + i ] == 2);
119 assert(buffer[ j * w + i ] == 0);
124 opj_sparse_array_int32_free(sa);
127 sa = opj_sparse_array_int32_create(99, 101, 15, 17);
128 memset(buffer, 0xFF, sizeof(buffer));
129 ret = opj_sparse_array_int32_read(sa, 0, 0, 2, 1, buffer, 2, 4, OPJ_FALSE);
131 assert(buffer[0] == 0);
132 assert(buffer[1] == -1);
133 assert(buffer[2] == 0);
137 ret = opj_sparse_array_int32_write(sa, 0, 0, 2, 1, buffer, 2, 4, OPJ_FALSE);
140 memset(buffer, 0xFF, sizeof(buffer));
141 ret = opj_sparse_array_int32_read(sa, 0, 0, 2, 1, buffer, 2, 4, OPJ_FALSE);
143 assert(buffer[0] == 1);
144 assert(buffer[1] == -1);
145 assert(buffer[2] == 3);
147 opj_sparse_array_int32_free(sa);