⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jp2_local.h

📁 该源码是JPEG2000的c++源代码,希望对研究JPEG2000标准以及编解码的朋友们有用.
💻 H
📖 第 1 页 / 共 2 页
字号:
/*****************************************************************************/// File: jp2.h [scope = APPS/JP2]// Version: Kakadu, V2.2.1// Author: David Taubman// Last Revised: 5 July, 2001/*****************************************************************************/// Copyright 2001, David Taubman, The University of New South Wales (UNSW)// The copyright owner is Unisearch Ltd, Australia (commercial arm of UNSW)// Neither this copyright statement, nor the licensing details below// may be removed from this file or dissociated from its contents./*****************************************************************************/// Licensee: Book Owner// License number: 99999// The Licensee has been granted a NON-COMMERCIAL license to the contents of// this source file, said Licensee being the owner of a copy of the book,// "JPEG2000: Image Compression Fundamentals, Standards and Practice," by// Taubman and Marcellin (Kluwer Academic Publishers, 2001).  A brief summary// of the license appears below.  This summary is not to be relied upon in// preference to the full text of the license agreement, which was accepted// upon breaking the seal of the compact disc accompanying the above-mentioned// book.// 1. The Licensee has the right to Non-Commercial Use of the Kakadu software,//    Version 2.2, including distribution of one or more Applications built//    using the software, provided such distribution is not for financial//    return.// 2. The Licensee has the right to personal use of the Kakadu software,//    Version 2.2.// 3. The Licensee has the right to distribute Reusable Code (including//    source code and dynamically or statically linked libraries) to a Third//    Party, provided the Third Party possesses a license to use the Kakadu//    software, Version 2.2, and provided such distribution is not for//    financial return./******************************************************************************Description:   Defines local classes used by the internal JP2 file format processingmachinery implemented in "jp2.cpp".  The internal object classes defined heregenerally parallel the externally visible interface object classes definedin the compressed-io header file, "jp2.h".  You should respect the localnature of this header file and not include it directly from an applicationor any other part of the Kakadu system (not in the APPS/JP2 scope).******************************************************************************/#ifndef JP2_LOCAL_H#define JP2_LOCAL_H#include <stdio.h> // The C I/O functions can be a lot faster than C++ ones.#include <assert.h>#include "jp2.h"// Defined hereclass j2_input_box;class j2_output_box;class j2_dimensions;class j2_palette;class j2_channels;class j2_icc_profile;class j2_colour;class j2_resolution;class j2_source;class j2_target;/*****************************************************************************//*                               j2_input_box                                *//*****************************************************************************/class j2_input_box {  public: // Member functions    j2_input_box()      { box_type = 0; file = NULL; super_box = NULL; }    ~j2_input_box()      { // Closes the box if necessary. */        close();      }    bool operator!()      { return (box_type == 0); }    bool exists()      { return (box_type != 0); }    j2_input_box &open(FILE *file)      {        assert(box_type == 0); // Must have been previously closed.        this->file = file; this->super_box = NULL;        read_header(); return *this;      }    j2_input_box &open(j2_input_box *super_box)      {        assert(box_type == 0); // Must have been previously closed.        this->file = NULL; this->super_box = super_box;        read_header(); return *this;      }      /* Both functions open a new input box, reading its length and         signature fields so that subsequent input, if any, will be taken from         the body of the box.  If the box is a sub-box, it takes its input         from the body of an existing `super_box'.  Otherwise, it takes its         input from the indicated `file' stream. */    bool close();      /* Skips over any outstanding bytes which have not been read from the         body of the box.  The function returns false if there were some         unread bytes, which may be an error or warning condition.  Otherwise,         it returns true.  Also returns true if the box has already been         closed.  Subsequent calls to `exists' will return false. */    kdu_uint32 get_box_type()      { return box_type; }      /* Returns the box_type, which is usually a 4 character code.  Returns         0 if the box could not be opened.  This is also the condition which         causes `exists' to return false. */    kdu_uint32 get_remaining_bytes()      /* Returns the number of body bytes which have not yet been read from         the box.  Returns 0xFFFFFFFF if the box has a rubber length or the         length is too large to be represented in 32 bits. */      {        if (box_type == 0)          return 0;        else          return (box_bytes==0)?0xFFFFFFFF:remaining_bytes;      }    int ignore(int num_bytes);      /* Skips over up to `num_bytes' of the box's body, returning the number         of bytes actually skipped. */    int read(kdu_byte *buf, int num_bytes);      /* Attempts to read the indicated number of bytes from the body of the         box, filling the supplied buffer with these bytes.  Returns the         actual number of bytes which were read, which may be smaller than         `num_bytes' if the end of the box (or surrounding file) is         encountered. */    bool read(kdu_uint32 &dword);      /* Reads a big-endian 4 byte word from the box, returning false if         the source is exhausted. */    bool read(kdu_uint16 &word);      /* Reads a big-endian 2 byte word from the box, returning false if         the source is exhausted. */    bool read(kdu_byte &byte)      { return (read(&byte,1) == 1); }      /* Reads a single byte from the box, returning false if the source         is exhausted. */  private: // Helper functions    void read_header();  private: // Data    kdu_uint32 box_type;    kdu_uint32 box_bytes; // 0 if box has rubber length or length too large.    kdu_uint32 remaining_bytes; // Unused if `box_bytes' = 0.    FILE *file;    j2_input_box *super_box;  };/*****************************************************************************//*                              j2_output_box                                *//*****************************************************************************/class j2_output_box {  public: // Member functions    j2_output_box()      { box_type = 0; rubber_length = output_failed = false;        super_box = NULL; file = NULL;        buffer_size = buffered_bytes = 0; buffer = NULL; }    ~j2_output_box()      { close(); }    j2_output_box &      open(FILE *file, kdu_uint32 box_type, bool rubber_length=false)      {        assert((this->box_type == 0) && (buffer == NULL));        this->box_type = box_type; this->rubber_length = rubber_length;        this->super_box = NULL; this->file = file;        buffer_size = buffered_bytes = 0; output_failed = false;        if (rubber_length) write_header();        return *this;      }    j2_output_box &      open(j2_output_box *super_box, kdu_uint32 box_type,           bool rubber_length=false)      {        assert((this->box_type == 0) && (buffer == NULL));        this->box_type = box_type; this->rubber_length = rubber_length;        this->super_box = super_box; this->file = NULL;        buffer_size = buffered_bytes = 0; output_failed = false;        if (rubber_length) write_header();        return *this;      }      /* Both functions open a new output box with the indicated         box_type (usually a 4 character code).  The second function is         for opening sub-boxes, whose output will be directed to the body         of the containing super-box.  If the `rubber_length' argument is         false, the contents of the box will be buffered so that the         final length of the box may be determined and written as the first         field of the box.  Otherwise, the box will pass its contents         directly through to the output as they appear.  Note that a box         may be given a rubber length after it is opened (see below). */    void set_rubber_length();      /* Informs the box that it can flush any buffered data and pass all         future body bytes directly to the output from now on.  This call is         legal only when the box is already open.  The box will         have a zero-valued length field.  This function is generally         invoked whenever a sub-box is created with rubber length or is         assigned rubber length by one of its own sub-boxes. */    bool close();      /* Flushes the contents of the box to the output.  If the box had         rubber length, there will be nothing to flush and this function         will return false, meaning that no further boxes may be opened.  The         function may also return false if the box contents cannot be         completely flushed to the output device for some reason (e.g., disk         full).  If the box has already been closed (or never opened), this         function returns true. */    bool write(kdu_byte *buf, int num_bytes);      /* Writes the indicated number of bytes to the body of the box, from         the supplied buffer.  Returns false if the output device is unable         to receive all of the supplied data (e.g., disk full). */    bool write(kdu_uint32 dword);      /* Writes a big-endian 32-bit unsigned integer to the body of the box,         returning false if the output device is unable to receive all of         the supplied data for some reason. */    bool write(kdu_uint16 word);      /* Writes a big-endian 16-bit unsigned integer to the body of the box,         returning false if the output device is unable to receive all of         the supplied data for some reason. */    bool write(kdu_byte byte)      { return write(&byte,1); }      /* Writes a single byte to the body of the box, returning false if the         output device is unable to receive all of the supplied data for some         reason. */  private: // Helper functions    void write_header();  private: // Data    kdu_uint32 box_type; // 0 if box does not exist or has been closed.    bool rubber_length;    FILE *file;    j2_output_box *super_box;    int buffer_size, buffered_bytes;    kdu_byte *buffer;    bool output_failed; // True if the output device failed to absorb all data  };/*****************************************************************************//*                               j2_dimensions                               *//*****************************************************************************/class j2_dimensions {  public: // Member functions    j2_dimensions()      { num_components = 0; bit_depths = NULL; }    ~j2_dimensions()      { if (bit_depths != NULL) delete[] bit_depths; }    void init(j2_input_box *ihrd_box);      /* Initializes the object from the information recorded in an image         header box.  Note that the construction might not be complete         (`finalize' may generate an error) if components have different         bit-depths or signed/unsigned characteristics (see below).  Note         also that the function closes the `ihdr_box' when done. */    void init(kdu_coords size, int num_components, bool unknown_space);      /* Does the work of the parallel `jp2_dimensions::init' function. */    void process_bpcc_box(j2_input_box *bpcc_box);      /* This function is called if a bits per component box is encountered         while parsing a JP2 file.  The function closes the box before         returning. */    void finalize();      /* Checks that the object has been completely initialized.  Generates         an appropriate error otherwise. */    void save_boxes(j2_output_box *super_box);      /* Creates an image header box and, if necessary, a bits per component         box, saving them as sub-boxes of the supplied `super_box'. */  private: // Data    friend class jp2_dimensions;    kdu_coords size;    int num_components;    bool colour_space_unknown, ipr_box_available;    int *bit_depths;  };  /* Notes:        The `bit_depths' array holds one element for each image component     with the magnitude identifying the actual number of bits used to     represent the samples.  Negative values mean that the relevant     component has a signed representation. *//*****************************************************************************//*                                 j2_palette                                *//*****************************************************************************/class j2_palette {  public: // Member functions    j2_palette()      { num_components = 0; num_entries = 0; bit_depths = NULL; luts = NULL; }    ~j2_palette()      {        if (bit_depths != NULL) delete[] bit_depths;        if (luts != NULL)          {            for (int c=0; c < num_components; c++)              delete[] luts[c];            delete[] luts;          }      }    void init(j2_input_box *pclr_box);      /* Initializes the object from the information recorded in a palette         box.  Note that the function closes the `pclr_box' when done. */    void init(int num_components, int num_entries);      /* Does the work of the parallel `jp2_palette::init' function. */    void finalize();      /* Checks that the object has been completely initialized.  Generates         an appropriate error otherwise. */    void save_box(j2_output_box *super_box);      /* Creates a palette box and saves it as a sub-box of the supplied         `super-box'.  Does nothing if no palette information has been set. */  private: // Data    friend class jp2_palette;    int num_components;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -