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

📄 kdu_transcode.cpp

📁 该源码是JPEG2000的c++源代码,希望对研究JPEG2000标准以及编解码的朋友们有用.
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/*****************************************************************************/// File: kdu_transcode.cpp [scope = APPS/TRANSCODE]// 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:   Transcoding application, demonstrating many of the transcoding-orientedcapabilities of the Kakadu framework.  Supports most of the transcodingoperations which are appealing within the JPEG2000 framework, includingimage rotation.  Rate control by the transcoder is usually superior tothat obtained by pure file truncation, even with layer-progressivecode-stream organizations.******************************************************************************/// System includes#include <string.h>#include <stdlib.h>#include <stdio.h> // Want to use "sscanf".#include <fstream>#include <assert.h>// Kakadu core includes#include "kdu_elementary.h"#include "kdu_messaging.h"#include "kdu_params.h"#include "kdu_compressed.h"#include "kdu_block_coding.h"// Application includes#include "kdu_args.h"#include "kdu_file_io.h"#include "jp2.h"/* ========================================================================= *//*                      Pretty Printing Version of `cout'                    *//* ========================================================================= */static kdu_pretty_buf pretty_cout_buf(&std::cout);static std::ostream pretty_cout(&pretty_cout_buf);/* ========================================================================= *//*                           Internal Functions                              *//* ========================================================================= *//*****************************************************************************//* STATIC                        print_about                                 *//*****************************************************************************/static void  print_about(char *prog){  kdu_pretty_buf strbuf(&std::cout);  std::ostream out(&strbuf);  out << "Brief description of \"" << prog << "\"\n";  strbuf.set_master_indent(3);  out << "  The standard inherently lends itself to a wide variety of "         "transcoding operations.  This program offers the "         "following capabilities:\n";  strbuf.set_master_indent(7);  out << "-- reducing the resolution (i.e., the number of DWT levels);\n"         "-- reducing the number of image components;\n"         "-- changing the number of quality layers;\n"         "-- reducing the bit-rate;\n"         "-- re-sequencing of the packet progression in any tile;\n"         "-- introducing/discarding interleved tile-parts for any tile;\n"         "-- changing precinct dimensions to support better spatial "         "progressions;\n"         "-- introducing/discarding SOP (Start of Packet) markers;\n"         "-- introducing/discarding EPH (End of Packet Header) markers;\n"         "-- changing any of the six block coder mode switches; and\n"         "-- rotation in the transformed domain.\n";  strbuf.set_master_indent(3);  out << "In the future we plan to add compressed domain cropping to these "         "features.\n";  out << "\nThese capabilities are mostly realized by supplying the same "         "type of attribute specification on the command-line, which you "         "would use with the compressor.  Tile- and component-specific "         "forms of the various arguments may be used.\n";  out << "\nFor a list of arguments which may legitimately be supplied here, "         "use the \"-u\" or \"-usage\" (long version) arguments to request "         "a usage statement.\n";  exit(0);}/*****************************************************************************//* STATIC                        print_usage                                 *//*****************************************************************************/static void  print_usage(char *prog, bool comprehensive=false){  kdu_pretty_buf strbuf(&std::cout);  std::ostream out(&strbuf);  out << "Usage:\n  \"" << prog << " ...\n";  strbuf.set_master_indent(3);  out << "-i <compressed file in>\n";  if (comprehensive)    out << "\tCurrently accepts raw code-stream files and code-streams "             "wrapped in any JP2 compatible file format.  The file suffix "             "is currently used to identify the type of file which is being "             "supplied, where a \".jp2\" or \".jpx\" suffix (case "             "insensitive) is required if the file is to be treated as "             "anything other than a raw code-stream.\n";  out << "-o <compressed file out>\n";  if (comprehensive)    out << "\tOnly writes raw code-stream files at present, even if the "           "input was a JP2 file.\n";  out << "-reduce <discard levels>\n";  if (comprehensive)    out << "\tSet the number of highest resolution levels to be discarded.  "           "The image resolution is effectively divided by 2 to the power of "           "the number of discarded levels.\n";  out << "-components <num image components>\n";  if (comprehensive)    out << "\tSet the maximum number of image components to be included "           "in the output code-stream.\n";  out << "-skip_components <num image components>\n";  if (comprehensive)    out << "\tSet the number of initial image components to be discarded.\n";  out << "-rate <bits per pixel>\n";  if (comprehensive)    out << "\tMax output bit-rate, expressed in terms of the ratio between "           "the total number of compressed bits (including headers) and the "           "product of the largest horizontal and  vertical image component "           "dimensions.  Note that all of the original layers will be "           "included, many of which may be assigned empty packets, which "           "still occupy at least one byte each.  Apart from this small cost, "           "transcoding to a reduced rate usually produces superior results "           "to simply truncating the original code-stream to that rate, even "           "when it was layer progressive -- it also yields a fully compliant "           "code-stream, complete with all packets and an EOC marker.\n";  out << "-rotate <degrees>\n";  if (comprehensive)    out << "\tRotate by a multiple of 90 degrees.  JPEG2000 allows for "           "image rotation by multiples of 90 degrees without the need to "           "invert and redo the DWT (Discrete Wavelet Transform).  "           "While this represents a considerable saving, individual "           "code-blocks must still be transcoded.  While the distortion "           "and size of most code-streams will not be invariant under "           "rotation, once a compressed image has been rotated using "           "this option, all subsequent rotations will preserve "           "distortion and any set of rotations which sum to a multiple of "           "360 degrees will preserve compressed length.\n"        << "\tNote that subject to rotation, any tile-specific parameter "           "modifications supplied here refer to tiles in the output "           "code-stream, as opposed to the input code-stream.\n";  cod_params cod;  cod.describe_string(Corder,out,comprehensive);  cod.describe_string(Clayers,out,comprehensive);  cod.describe_string(Cprecincts,out,comprehensive);  cod.describe_string(Cuse_precincts,out,comprehensive);  cod.describe_string(Cuse_eph,out,comprehensive);  cod.describe_string(Cuse_sop,out,comprehensive);  cod.describe_string(Cmodes,out,comprehensive);  poc_params poc;  poc.describe_string(Porder,out,comprehensive);  out << "-fussy\n";  if (comprehensive)    out << "\tEncourage fussy input code-stream parsing, in which most "           "code-stream compliance failures will terminate execution, with "           "an appropriate error message.\n";  out << "-resilient\n";  if (comprehensive)    out << "\tEncourage error resilient processing, in which an attempt is "           "made to recover from errors in the input code-stream with minimal "           "degradation in reconstructed image quality.  The current "           "implementation should avoid execution failure so long as only "           "a single tile-part was used and no errors are found in the main "           "or tile header.  The implementation recognizes tile-part headers "           "only if the first 4 bytes of the marker segment are correct, "           "which makes it extremely unlikely that a code-stream with only "           "one tile-part will be mistaken for anything else.  Multiple "           "tiles or tile-parts can create numerous problems for an error "           "resilient decompressor; complete failure may occur if a "           "multi-tile-part code-stream is corrupted.\n";  out << "-resilient_sop\n";  if (comprehensive)    out << "\tSame as \"-resilient\" except that the error resilient code-"           "stream parsing algorithm is informed that it can expect SOP "           "markers to appear in front of every single packet, whenever "           "the relevant flag in the Scod style byte of the COD marker is "           "set.  The JPEG2000 standard interprets this flag as meaning "           "that SOP markers may appear; however, this does not give the "           "decompressor any idea where it can expect SOP markers "           "to appear.  In most cases, SOP markers, if used, will be placed "           "in front of every packet and knowing this a priori can "           "improve the performance of the error resilient parser.\n";  out << "-mem -- Report memory usage.\n";  out << "-s <switch file>\n";  if (comprehensive)    out << "\tSwitch to reading arguments from a file.  In the file, argument "           "strings are separated by whitespace characters, including spaces, "           "tabs and new-line characters.  Comments may be included by "           "introducing a `#' or a `%' character, either of which causes "           "the remainder of the line to be discarded.  Any number of "           "\"-s\" argument switch commands may be included on the command "           "line.\n";  out << "-record <file>\n";  if (comprehensive)    out << "\tRecord output code-stream parameters in a file, using the same "           "format which is accepted when specifying the parameters to the "           "compressor.\n";   out << "-quiet -- suppress informative messages.\n";  out << "-about -- print a brief description of this program.\n";  out << "-usage -- print a comprehensive usage statement.\n";  out << "-u -- print a brief usage statement.\"\n\n";  out.flush();  exit(0);}/*****************************************************************************//* STATIC                    check_parameter_args                            *//*****************************************************************************/static void  check_parameter_args(kdu_args &args){  char *string;  for (string=args.get_first(); string != NULL; string=args.advance(false))    {      char *delim = string;      while ((*delim != '\0') && (*delim != ':') && (*delim != '=') &&             (*delim != ' '))        delim++;      if ((*delim != ':') && (*delim != '='))        continue;      char save = *delim; *delim = '\0';      if (strcmp(string,Corder) &&          strcmp(string,Clayers) &&          strcmp(string,Cprecincts) &&          strcmp(string,Cuse_precincts) &&          strcmp(string,Cuse_eph) &&          strcmp(string,Cuse_sop) &&          strcmp(string,Cmodes) &&          strcmp(string,Porder))        {  *delim = save;          kdu_error e; e << "Attempting to modify a code-stream parameter "          "for which transcoding is not defined.  Offending argument is \""          << string << "\".  For more information see the usage statement."; }      *delim = save;    }}/*****************************************************************************//* STATIC                     parse_simple_args                              *//*****************************************************************************/

⌨️ 快捷键说明

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