66#include "gtest/gtest.h"
87static std::vector<ojph::ui8> encode_test_codestream()
111 dp[x] = (
ojph::si32)((x * 7 + y * 13 + ((x * y) >> 3)) & 0xFF);
112 line = cs.
exchange(line, next_comp);
116 std::vector<ojph::ui8> buf(out.
get_data(),
127static ojph::ui32 decode_lines(
const std::vector<ojph::ui8>& buf,
131 in.
open(buf.data(), buf.size());
154class truncated_decode :
public ::testing::Test
157 void SetUp()
override
162 full = encode_test_codestream();
163 ASSERT_GT(full.size(), NUM_CUTS * 64u)
164 <<
"the test codestream is too small to be meaningfully truncated";
167 void TearDown()
override
173 std::vector<ojph::ui8> truncate(
ojph::ui32 cut)
const
175 size_t len = full.size() * cut / NUM_CUTS;
176 return std::vector<ojph::ui8>(
177 full.begin(), full.begin() +
static_cast<std::ptrdiff_t
>(len));
180 std::vector<ojph::ui8> full;
186TEST_F(truncated_decode, complete_codestream_decodes_in_both_modes)
188 EXPECT_EQ(decode_lines(full,
false), IMAGE_HEIGHT);
189 EXPECT_EQ(decode_lines(full,
true), IMAGE_HEIGHT);
195TEST_F(truncated_decode, resilient_mode_decodes_every_truncation_length)
197 for (
ojph::ui32 cut = 1; cut < NUM_CUTS; ++cut)
199 std::vector<ojph::ui8> part = truncate(cut);
201 ASSERT_NO_THROW(num_lines = decode_lines(part,
true))
202 <<
"truncated to " << part.size() <<
" of " << full.size() <<
" bytes";
203 EXPECT_EQ(num_lines, IMAGE_HEIGHT)
204 <<
"truncated to " << part.size() <<
" of " << full.size() <<
" bytes";
213TEST_F(truncated_decode, non_resilient_mode_throws_on_detected_truncation)
216 for (
ojph::ui32 cut = 1; cut < NUM_CUTS; ++cut)
218 std::vector<ojph::ui8> part = truncate(cut);
219 bool detected =
false;
221 decode_lines(part,
false);
223 catch (
const std::runtime_error&) {
227 FAIL() <<
"the library must report errors as a std::runtime_error; "
228 <<
"truncated to " << part.size() <<
" of " << full.size() <<
" bytes";
235 EXPECT_EQ(decode_lines(part,
true), IMAGE_HEIGHT)
236 <<
"truncated to " << part.size() <<
" of " << full.size() <<
" bytes";
240 EXPECT_GT(num_detected, 0u)
241 <<
"no truncation of the test codestream was detected by the parser, so "
242 <<
"this test is no longer testing anything";
The object represent a codestream.
param_siz access_siz()
Returns the underlying SIZ marker segment object.
param_cod access_cod()
Returns the underlying COD marker segment object.
void close()
Call this function to close the underlying file; works for both encoding and decoding codestreams.
void enable_resilience()
This enables codestream resilience; that is, the library tries its best to decode the codestream,...
line_buf * exchange(line_buf *line, ui32 &next_component)
This call is used to send image data rows to the library. We expect to send one row from a single com...
void read_headers(infile_base *file)
This call reads the headers of a codestream. It is for a reading (or decoding) codestream,...
void write_headers(outfile_base *file, const comment_exchange *comments=NULL, ui32 num_comments=0)
Writes codestream headers when the codestream is used for writing. This function should be called aft...
void create()
This call is for a decoding (or reading) codestream. Call this function after calling restrict_input_...
void flush()
This is the last call to a writing (encoding) codestream. This will write encoded bitstream data to t...
line_buf * pull(ui32 &comp_num)
This call is to pull one row from the codestream, being decoded. The returned line_buf object holds o...
void open(const ui8 *data, size_t size)
mem_outfile stores encoded j2k codestreams in memory
si64 tell() override
Call this function to know the file size (i.e., number of bytes used to store the file).
void open(size_t initial_size=65536, bool clear_mem=false)
Call this function to open a memory file.
const ui8 * get_data()
Call this function to access memory file data.
void set_num_decomposition(ui32 num_decompositions)
void set_block_dims(ui32 width, ui32 height)
void set_reversible(bool reversible)
void set_component(ui32 comp_num, const point &downsampling, ui32 bit_depth, bool is_signed)
void set_num_components(ui32 num_comps)
ui32 get_recon_height(ui32 comp_num) const
void set_image_extent(point extent)
OJPH_EXPORT void set_message_level(OJPH_MSG_LEVEL level)
Sets the minimum severity of the message to be reported.