/*
* This file is part of rasdaman community.
*
* Rasdaman community is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Rasdaman community is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with rasdaman community. If not, see .
*
* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
rasdaman GmbH.
*
* For more information please see
* or contact Peter Baumann via .
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "nitf.h"
#include "image.h"
#include "graphic.h"
#include "text.h"
#include "des.h"
#include "res.h"
#include "utilities.h"
using namespace std;
using namespace RasNITF;
nitf::nitf(){
isEmpty = true;
m_li = NULL;
m_ls = NULL;
m_lt = NULL;
m_ld = NULL;
m_lr = NULL;
m_udhd = NULL;
m_xhd = NULL;
m_images = NULL;
m_graphics = NULL;
m_texts = NULL;
m_des = NULL;
m_res = NULL;
n_numi=0;
}
/*
nitf::nitf(char* data){
}
*/
nitf::~nitf(){
if (m_li != NULL) {
delete m_li;
m_li = NULL;
}
if (m_ls != NULL) {
delete m_ls;
m_ls = NULL;
}
if (m_lt != NULL) {
delete m_lt;
m_lt = NULL;
}
if (m_ld != NULL) {
delete m_ld;
m_ld = NULL;
}
if (m_lr != NULL) {
delete m_lr;
m_lr = NULL;
}
if (m_udhd != NULL) {
delete m_udhd;
m_udhd = NULL;
}
if (m_xhd != NULL) {
delete m_xhd;
m_xhd = NULL;
}
if (m_images != NULL) {
delete[] m_images;
m_images = NULL;
}
if (m_graphics != NULL) {
delete[] m_graphics;
m_graphics = NULL;
}
if (m_texts != NULL) {
delete[] m_texts;
m_texts = NULL;
}
if (m_des != NULL) {
delete[] m_des;
m_des = NULL;
}
if (m_res != NULL) {
delete[] m_res;
m_res = NULL;
}
}
bool nitf::checkempty(){
return isEmpty;
}
void nitf::empty(){
if (!this->isEmpty){
if (m_li != NULL) {
delete m_li;
m_li = NULL;
}
if (m_ls != NULL) {
delete m_ls;
m_ls = NULL;
}
if (m_lt != NULL) {
delete m_lt;
m_lt = NULL;
}
if (m_ld != NULL) {
delete m_ld;
m_ld = NULL;
}
if (m_lr != NULL) {
delete m_lr;
m_lr = NULL;
}
if (m_udhd != NULL) {
delete m_udhd;
m_udhd = NULL;
}
if (m_xhd != NULL) {
delete m_xhd;
m_xhd = NULL;
}
if (m_images != NULL) {
delete[] m_images;
m_images = NULL;
}
if (m_graphics != NULL) {
delete[] m_graphics;
m_graphics = NULL;
}
if (m_texts != NULL) {
delete[] m_texts;
m_texts = NULL;
}
if (m_des != NULL) {
delete[] m_des;
m_des = NULL;
}
if (m_res != NULL) {
delete[] m_res;
m_res = NULL;
}
}
this->isEmpty = true;
}
void nitf::stats() const {
int adress=n_hl;
cout<<"Printing statistics for the NITF file in memmory\n";
cout<<"================================================\n";
cout<<"Filename:\t\t"< 0) {
charsread += read_verify2(hNITF, m_udhofl, 3);
m_udhd = new char[n_udhdl-3];
charsread += read_verify2(hNITF, m_udhd, n_udhdl-3);
}
// read XHDL
charsread += read_verify2(hNITF, m_xhdl, 5);
n_xhdl = charptrtoint(m_xhdl, 5);
// read XHOFL and XHD if necessary
if (n_xhdl > 0) {
charsread += read_verify2(hNITF, m_xhdlofl, 3);
m_xhd = new char[n_xhdl-3];
charsread += read_verify2(hNITF, m_xhd, n_xhdl-3);
}
if (((long)(hNITF.tellg()))!= n_hl){
cout<< "header length read not as specified" << endl;
cout< 0) {
m_images = new image[n_numi];
for(int i=0; i 0) {
m_graphics = new graphic[n_nums];
for(int i=0; i 0) {
m_texts = new text[n_numt];
for(int i=0; i 0) {
m_des = new des[n_numdes];
for(int i=0; i 0) {
m_res = new res[n_numres];
for(int i=0; iisEmpty = false;
return charsread;
}
int nitf::write_file(std::string filename){
int charswritten = 0;
ofstream fNITF(filename.c_str());
fNITF.write(m_fhdr, 9);
fNITF.write(m_clevel, 2);
fNITF.write(m_stype, 4);
fNITF.write(m_ostaid, 10);
fNITF.write(m_fdt, 14);
fNITF.write(m_ftitle, 80);
fNITF.write(m_fsclas, 1);
fNITF.write(m_fsclsy, 2);
fNITF.write(m_fscode, 11);
fNITF.write(m_fsctlh, 2);
fNITF.write(m_fsrel, 20);
fNITF.write(m_fsdctp, 2);
fNITF.write(m_fsdcdt, 8);
fNITF.write(m_fsdcxm, 4);
fNITF.write(m_fsdg, 1);
fNITF.write(m_fsdgdt, 8);
fNITF.write(m_fscltx, 43);
fNITF.write(m_fscatp, 1);
fNITF.write(m_fscaut, 40);
fNITF.write(m_fscrsn, 1);
fNITF.write(m_fssrdt, 8);
fNITF.write(m_fsctln, 15);
fNITF.write(m_fscop, 5);
fNITF.write(m_fscpys, 5);
fNITF.write(m_encryp, 1);
fNITF.write(m_fbkgc, 3);
fNITF.write(m_oname, 24);
fNITF.write(m_ophone, 18);
fNITF.write(m_fl, 12);
fNITF.write(m_hl, 6);
charswritten += 9 + 2 + 4 + 10 + 14 + 80 + 1+ 2 + 11 + 2 + 20 + 2 + 8 + 4 + 1 + 8 + 43 + 1 + 40 + 1 +8 + 15 + 5 + 5 + 1 + 3 + 24 + 18 + 12 + 6;
fNITF.write(m_numi, 3);
charswritten += 3;
if(n_numi > 0){
fNITF.write(m_li, n_numi * (6 + 10));
charswritten += n_numi * (6 + 10);
}
fNITF.write(m_nums, 3);
charswritten += 3;
if(n_nums > 0){
fNITF.write(m_ls, n_nums * (4 + 6));
charswritten += n_nums * (4 + 6);
}
fNITF.write(m_numx, 3);
fNITF.write(m_numt, 3);
charswritten += 6;
if(n_numt > 0) {
fNITF.write(m_lt, n_numt * (4 + 5));
charswritten += n_numt * (4 + 5);
}
fNITF.write(m_numdes, 3);
charswritten += 3;
if(n_numdes > 0) {
fNITF.write(m_ld, n_numdes * (4 + 9));
charswritten += n_numdes * (4 + 9);
}
fNITF.write(m_numres, 3);
charswritten += 3;
if(n_numres > 0) {
fNITF.write(m_lr, n_numdes * (4 + 7));
charswritten += n_numdes* (4 + 7);
}
fNITF.write(m_udhdl, 5);
if (n_udhdl > 0){
fNITF.write(m_udhofl, 3);
fNITF.write(m_udhd, n_udhdl - 3);
charswritten += n_udhdl;
}
fNITF.write(m_xhdl, 5);
if (n_xhdl > 0){
fNITF.write(m_xhdlofl, 3);
fNITF.write(m_xhd, n_xhdl - 3);
charswritten += n_xhdl;
}
for(int i=0; i< n_numi; i++){
m_images[i].write_file(fNITF);
}
for(int i=0; i< n_nums; i++){
m_graphics[i].write_file(fNITF);
}
for(int i=0; i< n_numt; i++){
m_texts[i].write_file(fNITF);
}
for(int i=0; i< n_numdes; i++){
m_des[i].write_file(fNITF);
}
for(int i=0; i< n_numres; i++){
m_res[i].write_file(fNITF);
}
return charswritten;
}
void nitf::image_to_pixel_sequential(int index) {
if( !isEmpty ) {
if( (index < 0) || (index > n_numi)) {
throw(74);
exit(3);
} else {
m_images[index].to_pixel_sequential();
}
}
}
long nitf::get_image_size(int image_index) const
{
return m_images[image_index].get_size();
}
int nitf::get_image_width(int image_index) const
{
return m_images[image_index].get_width();
}
int nitf::get_image_height(int image_index) const
{
return m_images[image_index].get_height();
}
long nitf::get_image_offset(int image_index) const
{
long offset = 0;
offset += n_hl;
for(int ctr = 0; ctr < image_index; ctr++ ) {
offset+= n_li[ctr] + n_lish[ctr];
}
offset += n_lish[image_index];
return offset;
}
bool nitf::isRGB(int image_index){
bool RGB = false;
if (m_images[image_index].get_irep() == " RGB") {
if (m_images[image_index].get_nbpp_bytes() == 1 ){
RGB = true;
} else {
// throw(74);
exit(1704);
}
}
return RGB;
}
bool nitf::isGRAY(int image_index){
bool GRAY = false;
if ((m_images[image_index].get_irep() == " MONO") && (m_images[image_index].get_pvtype() == "INT")) {
if (m_images[image_index].get_nbpp_bytes() == 1 ){
GRAY = true;
} else {
// throw(74);
exit(1704);
}
}
return GRAY;
}
bool nitf::isBOOL(int image_index){
bool isBOOL = false;
if ((m_images[image_index].get_irep() == " MONO") && (m_images[image_index].get_pvtype() == " B")) {
if (m_images[image_index].get_nbpp_bytes() == 1 ){
isBOOL = true;
} else {
// throw(74);
exit(1704);
}
}
return isBOOL;
}