📄 kdu_image.h
字号:
/*****************************************************************************/// File: kdu_image.h [scope = APPS/IMAGE-IO]// Version: Kakadu, V2.2// Author: David Taubman// Last Revised: 20 June, 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: Not central to the Kakadu framework, this file defines generic imagefile I/O interfaces, which can be used to isolate file-based applications fromthe details of particular image file formats. Supports both bottom-up and top-down image file organizations withcomparable ease.******************************************************************************/#ifndef KDU_IMAGE#define KDU_IMAGE#include <assert.h>#include <stdlib.h> // To get `abs'#include "kdu_elementary.h"#include "kdu_params.h"// Defined here:class kdu_image_dims;struct kdu_rgb8_palette;class kdu_image_in_base;class kdu_image_in;class kdu_image_out_base;class kdu_image_out;// Defined elsewhere.class kdu_line_buf;class siz_params;/*****************************************************************************//* kdu_image_dims *//*****************************************************************************/class kdu_image_dims { public: // Member functions kdu_image_dims() { num_components = max_components = 0; data = NULL; } ~kdu_image_dims() { if (data != NULL) delete[] data; } void add_component(int height, int width, int bit_depth, bool is_signed) { assert(bit_depth > 0); if (num_components == max_components) { max_components += 10; int *tdata=new int[max_components*3]; for (int i=0; i < 3*num_components; i++) tdata[i] = data[i]; if (data != NULL) delete[] data; data = tdata; } data[num_components*3+0] = height; data[num_components*3+1] = width; data[num_components*3+2] = (is_signed)?(-bit_depth):bit_depth; num_components++; } int get_num_components() { return num_components; } int get_height(int comp_idx) { assert((comp_idx >= 0) && (comp_idx < num_components)); return data[3*comp_idx+0]; } int get_width(int comp_idx) { assert((comp_idx >= 0) && (comp_idx < num_components)); return data[3*comp_idx+1]; } int get_bit_depth(int comp_idx) { assert((comp_idx >= 0) && (comp_idx < num_components)); return abs(data[3*comp_idx+2]); } bool get_signed(int comp_idx) { assert((comp_idx >= 0) && (comp_idx < num_components)); return (data[3*comp_idx+2] < 0); } private: // Data int num_components; int max_components; int *data; }; /* Notes: The `data' array holds 3 integers for each component. The first integer is the height; the second is the width; the third has a magnitude which is equal to the bit-depth and a sign which is negative for signed data and positive for unsigned data. *//*****************************************************************************//* kdu_rgb8_palette *//*****************************************************************************/struct kdu_rgb8_palette { public: // Member functions kdu_rgb8_palette() { input_bits = output_bits = source_component = 0; } bool exists() { return (input_bits > 0) && (output_bits > 0); } bool operator!() { return !exists(); } bool is_monochrome() { for (int n=0; n < (1<<input_bits); n++) if ((red[n] != green[n]) || (red[n] != blue[n])) return false; return true; } void rearrange(kdu_byte *map); /* Searches for a permutation of the palette entries which will optimize neighbourhood properties. Specifically, tries to minimize the sum of the distances between adjacent palette entries where distance is assessed as the sum of the absolute values of the colour component differences. This is nothing other than the well-known travelling salesman problem, which is known to be NP-complete. Consequently, the solution will generally be sub-optimal. The algorithm deliberately starts with the original palette order and tries to incrementally improve upon it, so that in the event that the palette already has good neighbourhood properties (e.g., a previously optimized palette, a "heat" map or something like that), the function will execute quickly and without damaging the original palette's properties. The permutation is written into the supplied `map' array, which is understood as a lookup table whose inputs are the original palette indices and whose outputs are the new palette indices. */ public: // Data int input_bits; int output_bits; int source_component; kdu_int32 red[256]; kdu_int32 green[256]; kdu_int32 blue[256]; }; /* Notes: This simple structure may be used to convey information about an RGB colour palette, indexed by up to 8 bit component sample values. If the index has more than 8 bits, it is probably better to compress the de-palettized colour samples rather than the palette index. Accordingly, `input_bits' must be no larger than 8. The `source_component' field is set to the index (starting from 0) of the image component which carries the palette information. The `output_bits' field identifies the bit-depth of the palette colour values in the `red', `green' and `blue' arrays. The palette entries are expected to be unsigned quantities (storing them in a signed format simplifies interaction with the JP2 file manager's `jp2_palette' object. Accordingly, `output_bits' may not exceed 31. *//*****************************************************************************//* kdu_image_in *//*****************************************************************************/class kdu_image_in_base { /* Pure virtual base class. Provides an interface to derived classes which each support reading of a specific file type. */ public: // Single interface function. virtual ~kdu_image_in_base() {} virtual bool get(int comp_idx, kdu_line_buf &line, int x_tnum) = 0; };
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -