Loading...
Searching...
No Matches
ojph_tile_comp.cpp
Go to the documentation of this file.
//***************************************************************************/
// This software is released under the 2-Clause BSD license, included
// below.
//
// Copyright (c) 2019, Aous Naman
// Copyright (c) 2019, Kakadu Software Pty Ltd, Australia
// Copyright (c) 2019, The University of New South Wales, Australia
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//***************************************************************************/
// This file is part of the OpenJPH software implementation.
// File: ojph_tile_comp.cpp
// Author: Aous Naman
// Date: 28 August 2019
//***************************************************************************/
#include <climits>
#include <cmath>
#include "ojph_mem.h"
#include "ojph_params.h"
#include "ojph_codestream_local.h"
#include "ojph_tile_comp.h"
#include "ojph_resolution.h"
namespace ojph {
namespace local
{
void tile_comp::pre_alloc(codestream *codestream, ui32 comp_num,
const rect& comp_rect,
const rect& recon_comp_rect)
{
mem_fixed_allocator* allocator = codestream->get_allocator();
//allocate a resolution
ui32 num_decomps;
num_decomps = codestream->get_coc(comp_num)->get_num_decompositions();
allocator->pre_alloc_obj<resolution>(1);
resolution::pre_alloc(codestream, comp_rect, recon_comp_rect, comp_num,
num_decomps);
}
void tile_comp::finalize_alloc(codestream *codestream, tile *parent,
ui32 comp_num, const rect& comp_rect,
const rect& recon_comp_rect)
{
mem_fixed_allocator* allocator = codestream->get_allocator();
//allocate a resolution
num_decomps = codestream->get_coc(comp_num)->get_num_decompositions();
comp_downsamp = codestream->get_siz()->get_downsampling(comp_num);
this->comp_rect = comp_rect;
this->parent_tile = parent;
this->comp_num = comp_num;
this->num_bytes = 0;
res = allocator->post_alloc_obj<resolution>(1);
res->finalize_alloc(codestream, comp_rect, recon_comp_rect, comp_num,
num_decomps, comp_downsamp, comp_downsamp, this,
NULL);
}
line_buf* tile_comp::get_line()
{
return res->get_line();
}
void tile_comp::push_line()
{
res->push_line();
}
line_buf* tile_comp::pull_line()
{
return res->pull_line();
}
ui32 tile_comp::prepare_precincts()
{
this->num_bytes = res->prepare_precinct();
return this->num_bytes;
}
void tile_comp::write_precincts(ui32 res_num, outfile_base *file)
{
assert(res_num <= num_decomps);
res_num = num_decomps - res_num; //how many levels to go down
resolution *r = res;
while (res_num > 0 && r != NULL)
{
r = r->next_resolution();
--res_num;
}
if (r) //resolution does not exist if r is NULL
r->write_precincts(file);
}
bool tile_comp::get_top_left_precinct(ui32 res_num, point &top_left)
{
int resolution_num = (int)num_decomps - (int)res_num;
resolution *r = res;
while (resolution_num > 0 && r != NULL)
{
r = r->next_resolution();
--resolution_num;
}
if (r) //resolution does not exist if r is NULL
return r->get_top_left_precinct(top_left);
else
return false;
}
void tile_comp::write_one_precinct(ui32 res_num, outfile_base *file)
{
int resolution_num = (int)num_decomps - (int)res_num;
resolution *r = res;
while (resolution_num > 0 && r != NULL)
{
r = r->next_resolution();
--resolution_num;
}
if (r) //resolution does not exist if r is NULL
r->write_one_precinct(file);
}
void tile_comp::parse_precincts(ui32 res_num, ui32& data_left,
infile_base *file)
{
assert(res_num <= num_decomps);
res_num = num_decomps - res_num; //how many levels to go down
resolution *r = res;
while (res_num > 0 && r != NULL)
{
r = r->next_resolution();
--res_num;
}
if (r) //resolution does not exist if r is NULL
r->parse_all_precincts(data_left, file);
}
void tile_comp::parse_one_precinct(ui32 res_num, ui32& data_left,
infile_base *file)
{
assert(res_num <= num_decomps);
res_num = num_decomps - res_num;
resolution *r = res;
while (res_num > 0 && r != NULL)
{
r = r->next_resolution();
--res_num;
}
if (r) //resolution does not exist if r is NULL
r->parse_one_precinct(data_left, file);
}
ui32 tile_comp::get_num_bytes(ui32 resolution_num) const
{
return res->get_num_bytes(resolution_num);
}
}
}
ojph::infile_base
Definition ojph_file.h:267
ojph::line_buf
Definition ojph_mem.h:161
ojph::local::codestream
Definition ojph_codestream_local.h:69
ojph::local::codestream::get_coc
const param_cod * get_coc(ui32 comp_num)
Definition ojph_codestream_local.h:89
ojph::local::codestream::get_siz
const param_siz * get_siz()
Definition ojph_codestream_local.h:83
ojph::local::codestream::get_allocator
mem_fixed_allocator * get_allocator()
Definition ojph_codestream_local.h:97
ojph::local::resolution
Definition ojph_resolution.h:62
ojph::local::resolution::get_top_left_precinct
bool get_top_left_precinct(point &top_left)
Definition ojph_resolution.cpp:975
ojph::local::resolution::parse_one_precinct
void parse_one_precinct(ui32 &data_left, infile_base *file)
Definition ojph_resolution.cpp:1020
ojph::local::resolution::write_precincts
void write_precincts(outfile_base *file)
Definition ojph_resolution.cpp:967
ojph::local::resolution::pre_alloc
static void pre_alloc(codestream *codestream, const rect &res_rect, const rect &recon_res_rect, ui32 comp_num, ui32 res_num)
Definition ojph_resolution.cpp:59
ojph::local::resolution::next_resolution
resolution * next_resolution()
Definition ojph_resolution.h:91
ojph::local::resolution::parse_all_precincts
void parse_all_precincts(ui32 &data_left, infile_base *file)
Definition ojph_resolution.cpp:1001
ojph::local::resolution::write_one_precinct
void write_one_precinct(outfile_base *file)
Definition ojph_resolution.cpp:987
ojph::local::tile_comp::get_line
line_buf * get_line()
Definition ojph_tile_comp.cpp:92
ojph::local::tile_comp::num_decomps
ui32 num_decomps
Definition ojph_tile_comp.h:95
ojph::local::tile_comp::parent_tile
tile * parent_tile
Definition ojph_tile_comp.h:91
ojph::local::tile_comp::get_top_left_precinct
bool get_top_left_precinct(ui32 res_num, point &top_left)
Definition ojph_tile_comp.cpp:132
ojph::local::tile_comp::num_bytes
ui32 num_bytes
Definition ojph_tile_comp.h:97
ojph::local::tile_comp::write_one_precinct
void write_one_precinct(ui32 res_num, outfile_base *file)
Definition ojph_tile_comp.cpp:148
ojph::local::tile_comp::pull_line
line_buf * pull_line()
Definition ojph_tile_comp.cpp:104
ojph::local::tile_comp::pre_alloc
static void pre_alloc(codestream *codestream, ui32 comp_num, const rect &comp_rect, const rect &recon_comp_rect)
Definition ojph_tile_comp.cpp:54
ojph::local::tile_comp::comp_rect
rect comp_rect
Definition ojph_tile_comp.h:93
ojph::local::tile_comp::comp_num
ui32 comp_num
Definition ojph_tile_comp.h:96
ojph::local::tile_comp::res
resolution * res
Definition ojph_tile_comp.h:92
ojph::local::tile_comp::finalize_alloc
void finalize_alloc(codestream *codestream, tile *parent, ui32 comp_num, const rect &comp_rect, const rect &recon_comp_rect)
Definition ojph_tile_comp.cpp:70
ojph::local::tile_comp::parse_one_precinct
void parse_one_precinct(ui32 res_num, ui32 &data_left, infile_base *file)
Definition ojph_tile_comp.cpp:179
ojph::local::tile_comp::push_line
void push_line()
Definition ojph_tile_comp.cpp:98
ojph::local::tile_comp::comp_downsamp
ojph::point comp_downsamp
Definition ojph_tile_comp.h:94
ojph::local::tile_comp::prepare_precincts
ui32 prepare_precincts()
Definition ojph_tile_comp.cpp:110
ojph::local::tile_comp::write_precincts
void write_precincts(ui32 res_num, outfile_base *file)
Definition ojph_tile_comp.cpp:117
ojph::local::tile_comp::get_num_bytes
ui32 get_num_bytes() const
Definition ojph_tile_comp.h:87
ojph::local::tile_comp::parse_precincts
void parse_precincts(ui32 res_num, ui32 &data_left, infile_base *file)
Definition ojph_tile_comp.cpp:162
ojph::local::tile
Definition ojph_tile.h:61
ojph::mem_fixed_allocator
Definition ojph_mem.h:59
ojph::mem_fixed_allocator::pre_alloc_obj
void pre_alloc_obj(size_t num_ele)
Definition ojph_mem.h:78
ojph::mem_fixed_allocator::post_alloc_obj
T * post_alloc_obj(size_t num_ele)
Definition ojph_mem.h:119
ojph::outfile_base
Definition ojph_file.h:75
ojph::local
Definition ojph_bitbuffer_read.h:52
ojph
Definition ojph_img_io.h:52
ojph::ui32
uint32_t ui32
Definition ojph_defs.h:54
ojph_codestream_local.h
ojph_mem.h
ojph_params.h
ojph_resolution.h
ojph_tile_comp.h
ojph::local::param_cod::get_num_decompositions
ui8 get_num_decompositions() const
Definition ojph_params_local.h:504
ojph::local::param_siz::get_downsampling
point get_downsampling(ui32 comp_num) const
Definition ojph_params_local.h:262
ojph::point
Definition ojph_base.h:58
ojph::rect
Definition ojph_base.h:65