test_sparse_array.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  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.
  6. *
  7. * Copyright (c) 2017, IntoPix SA <contact@intopix.com>
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  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.
  18. *
  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.
  30. */
  31. #undef NDEBUG
  32. #include "opj_includes.h"
  33. int main()
  34. {
  35. OPJ_UINT32 i, j, w, h;
  36. OPJ_INT32 buffer[ 99 * 101 ];
  37. OPJ_BOOL ret;
  38. opj_sparse_array_int32_t* sa;
  39. sa = opj_sparse_array_int32_create(0, 1, 1, 1);
  40. assert(sa == NULL);
  41. opj_sparse_array_int32_free(sa);
  42. sa = opj_sparse_array_int32_create(1, 0, 1, 1);
  43. assert(sa == NULL);
  44. sa = opj_sparse_array_int32_create(1, 1, 0, 1);
  45. assert(sa == NULL);
  46. sa = opj_sparse_array_int32_create(1, 1, 1, 0);
  47. assert(sa == NULL);
  48. sa = opj_sparse_array_int32_create(99, 101, ~0U, ~0U);
  49. assert(sa == NULL);
  50. sa = opj_sparse_array_int32_create(99, 101, 15, 17);
  51. opj_sparse_array_int32_free(sa);
  52. sa = opj_sparse_array_int32_create(99, 101, 15, 17);
  53. ret = opj_sparse_array_int32_read(sa, 0, 0, 0, 1, buffer, 1, 1, OPJ_FALSE);
  54. assert(!ret);
  55. ret = opj_sparse_array_int32_read(sa, 0, 0, 1, 0, buffer, 1, 1, OPJ_FALSE);
  56. assert(!ret);
  57. ret = opj_sparse_array_int32_read(sa, 0, 0, 100, 1, buffer, 1, 1, OPJ_FALSE);
  58. assert(!ret);
  59. ret = opj_sparse_array_int32_read(sa, 0, 0, 1, 102, buffer, 1, 1, OPJ_FALSE);
  60. assert(!ret);
  61. ret = opj_sparse_array_int32_read(sa, 1, 0, 0, 1, buffer, 1, 1, OPJ_FALSE);
  62. assert(!ret);
  63. ret = opj_sparse_array_int32_read(sa, 0, 1, 1, 0, buffer, 1, 1, OPJ_FALSE);
  64. assert(!ret);
  65. ret = opj_sparse_array_int32_read(sa, 99, 101, 99, 101, buffer, 1, 1,
  66. OPJ_FALSE);
  67. assert(!ret);
  68. buffer[0] = 1;
  69. ret = opj_sparse_array_int32_read(sa, 0, 0, 1, 1, buffer, 1, 1, OPJ_FALSE);
  70. assert(ret);
  71. assert(buffer[0] == 0);
  72. memset(buffer, 0xFF, sizeof(buffer));
  73. ret = opj_sparse_array_int32_read(sa, 0, 0, 99, 101, buffer, 1, 99, OPJ_FALSE);
  74. assert(ret);
  75. for (i = 0; i < 99 * 101; i++) {
  76. assert(buffer[i] == 0);
  77. }
  78. buffer[0] = 1;
  79. ret = opj_sparse_array_int32_write(sa, 4, 5, 4 + 1, 5 + 1, buffer, 1, 1,
  80. OPJ_FALSE);
  81. assert(ret);
  82. buffer[0] = 2;
  83. ret = opj_sparse_array_int32_write(sa, 4, 5, 4 + 1, 5 + 1, buffer, 1, 1,
  84. OPJ_FALSE);
  85. assert(ret);
  86. buffer[0] = 0;
  87. buffer[1] = 0xFF;
  88. ret = opj_sparse_array_int32_read(sa, 4, 5, 4 + 1, 5 + 1, buffer, 1, 1,
  89. OPJ_FALSE);
  90. assert(ret);
  91. assert(buffer[0] == 2);
  92. assert(buffer[1] == 0xFF);
  93. buffer[0] = 0xFF;
  94. buffer[1] = 0xFF;
  95. buffer[2] = 0xFF;
  96. ret = opj_sparse_array_int32_read(sa, 4, 5, 4 + 1, 5 + 2, buffer, 0, 1,
  97. OPJ_FALSE);
  98. assert(ret);
  99. assert(buffer[0] == 2);
  100. assert(buffer[1] == 0);
  101. assert(buffer[2] == 0xFF);
  102. buffer[0] = 3;
  103. ret = opj_sparse_array_int32_write(sa, 4, 5, 4 + 1, 5 + 1, buffer, 0, 1,
  104. OPJ_FALSE);
  105. assert(ret);
  106. buffer[0] = 0;
  107. buffer[1] = 0xFF;
  108. ret = opj_sparse_array_int32_read(sa, 4, 5, 4 + 1, 5 + 1, buffer, 1, 1,
  109. OPJ_FALSE);
  110. assert(ret);
  111. assert(buffer[0] == 3);
  112. assert(buffer[1] == 0xFF);
  113. w = 15 + 1;
  114. h = 17 + 1;
  115. memset(buffer, 0xFF, sizeof(buffer));
  116. ret = opj_sparse_array_int32_read(sa, 2, 1, 2 + w, 1 + h, buffer, 1, w,
  117. OPJ_FALSE);
  118. assert(ret);
  119. for (j = 0; j < h; j++) {
  120. for (i = 0; i < w; i++) {
  121. if (i == 4 - 2 && j == 5 - 1) {
  122. assert(buffer[ j * w + i ] == 3);
  123. } else {
  124. assert(buffer[ j * w + i ] == 0);
  125. }
  126. }
  127. }
  128. opj_sparse_array_int32_free(sa);
  129. sa = opj_sparse_array_int32_create(99, 101, 15, 17);
  130. memset(buffer, 0xFF, sizeof(buffer));
  131. ret = opj_sparse_array_int32_read(sa, 0, 0, 2, 1, buffer, 2, 4, OPJ_FALSE);
  132. assert(ret);
  133. assert(buffer[0] == 0);
  134. assert(buffer[1] == -1);
  135. assert(buffer[2] == 0);
  136. buffer[0] = 1;
  137. buffer[2] = 3;
  138. ret = opj_sparse_array_int32_write(sa, 0, 0, 2, 1, buffer, 2, 4, OPJ_FALSE);
  139. assert(ret);
  140. memset(buffer, 0xFF, sizeof(buffer));
  141. ret = opj_sparse_array_int32_read(sa, 0, 0, 2, 1, buffer, 2, 4, OPJ_FALSE);
  142. assert(ret);
  143. assert(buffer[0] == 1);
  144. assert(buffer[1] == -1);
  145. assert(buffer[2] == 3);
  146. opj_sparse_array_int32_free(sa);
  147. return 0;
  148. }