Init
35
src/.gitattributes
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
# All text files are by default (unless some specific pattern
|
||||
# overrides below) treated as LF in repository and native (LF on Unix
|
||||
# and CRLF on Windows) in the working directory.
|
||||
* text=auto
|
||||
|
||||
# All bash shell scripts must uniformly have LF endings.
|
||||
*.sh eof=lf
|
||||
*.sh.in eof=lf
|
||||
|
||||
# git has its own heuristics for detecting text versus binary files
|
||||
# but just to make sure it doesn't misclassify a file as text when
|
||||
# it is binary, use specific rules below.
|
||||
|
||||
# Various formats for Lena images
|
||||
*.img -text
|
||||
*.pgm -text
|
||||
|
||||
# Binary graphical formats in the www subdirectory tree
|
||||
*.gif -text
|
||||
*.jpg -text
|
||||
|
||||
# Binary graphical format in lib/nistcd/*.cgm
|
||||
*.cgm -text
|
||||
|
||||
# Atari 68xxx CPX file (the original binary format in data/*.map)
|
||||
*.map -text
|
||||
|
||||
# Shapefile binary formats in the data subdirectory tree
|
||||
*.dbf -text
|
||||
*.prj -text
|
||||
*.shp -text
|
||||
*.shx -text
|
||||
|
||||
# Hershey binary font files in data subdirectory
|
||||
*.fnt -text
|
31
src/.gitignore
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
# For emacs there are many more ignore patterns available from
|
||||
# https://github.com/github/gitignore/blob/master/Global/Emacs.gitignore,
|
||||
# but I think that is overkill, and these are the only three patterns I
|
||||
# routinely encounter when using emacs as an editor rather than an
|
||||
# OS. :-)
|
||||
# Those whose emacs use creates more auto-generated
|
||||
# files than this should probably being doing a global
|
||||
# config for themselves instead of a change to this file.
|
||||
*~
|
||||
\#*\#
|
||||
.\#*
|
||||
|
||||
# For Python there are many more ignore patterns available from
|
||||
# https://github.com/github/gitignore/blob/master/Python.gitignore
|
||||
# if needed, but so far I find this pattern is enough when using
|
||||
# python from another directory (such as the separate build directory
|
||||
# you should be using).
|
||||
*.py[cod]
|
||||
|
||||
# In case the user wants to use this specific separate build tree
|
||||
# within the source tree.
|
||||
build/
|
||||
|
||||
# Other ignore patterns which have historically been in this
|
||||
# file but which are currently undocumented.
|
||||
*.flc
|
||||
tmp/
|
||||
|
||||
# Ignore Mac OS X generated file/directory attribute storage files
|
||||
\.DS_Store
|
||||
\._\.DS_Store
|
351
src/agn.hpp
Normal file
@ -0,0 +1,351 @@
|
||||
#ifndef agn_hpp
|
||||
#define agn_hpp
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <cmath>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <list>
|
||||
#include <cctype>
|
||||
#include <cstdlib>
|
||||
#include <set>
|
||||
#include <cmath>
|
||||
|
||||
namespace agn {
|
||||
|
||||
const bool debug = true;
|
||||
|
||||
// General constants
|
||||
const double PI=3.14159265358979323846;
|
||||
const double PLANCK_CONST=4.135668e-15; // in eV * s
|
||||
const double BOLTZMANN_CONST=0.00008617332385; // in eV / K
|
||||
const double RYDBERG_CONST=1.0973731568539e7; // in 1 / m
|
||||
const double RYDBERG_UNIT_EV=13.60569252; // in eV
|
||||
const double RYDBERG_UNIT_ANGSTROM=1e10/RYDBERG_CONST; // in A
|
||||
|
||||
// Some useful containers and functions.
|
||||
typedef std::map<double,double> table1d;
|
||||
typedef table1d::iterator iterator1d;
|
||||
std::string format_table1d(table1d);
|
||||
|
||||
typedef std::map<double,table1d> table2d;
|
||||
typedef table2d::iterator iterator2d;
|
||||
typedef std::pair<double,double> coord2d;
|
||||
typedef std::list<coord2d> gridcoordlist;
|
||||
|
||||
struct cloudy_line_data {
|
||||
double radiated_energy,eq_width;
|
||||
int index;
|
||||
bool has_duplicates;
|
||||
};
|
||||
|
||||
typedef std::map<std::string,cloudy_line_data> cloudy_line_output;
|
||||
|
||||
struct cloudy_result {
|
||||
std::string header, footer;
|
||||
std::list<std::string> emergent_line_raw_text;
|
||||
std::list<std::string> cautions;
|
||||
cloudy_line_output emergent_line_intensity;
|
||||
int iterations;
|
||||
double phi,hden,colden;
|
||||
cloudy_result():
|
||||
header(""),
|
||||
footer(""),
|
||||
emergent_line_raw_text(),
|
||||
cautions(),
|
||||
iterations(0),
|
||||
phi(0),
|
||||
hden(0),
|
||||
colden(0)
|
||||
{}
|
||||
};
|
||||
|
||||
typedef std::map<coord2d,cloudy_result> cloudy_grid;
|
||||
// Easiest to read the entire grid from the file at once.
|
||||
cloudy_grid read_cloudy_grid(std::ifstream&);
|
||||
// Operator<< prints general info about the run result.
|
||||
std::ostream& operator<< (std::ostream&, cloudy_result);
|
||||
// Seeks an instream to the line after the first occurrence of seek_string.
|
||||
void seek_to(std::string,std::istream&);
|
||||
|
||||
|
||||
} // end namespace agn
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Definitions
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void agn::seek_to(std::string seek_string,std::istream& stream) {
|
||||
std::string test_str="";
|
||||
while (test_str.find(seek_string) == std::string::npos)
|
||||
getline(stream,test_str);
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string agn::format_table1d(agn::table1d table) {
|
||||
std::stringstream output;
|
||||
output
|
||||
<< std::scientific
|
||||
<< std::setprecision(5);
|
||||
agn::table1d::iterator x=table.begin();
|
||||
while(x!=table.end()) {
|
||||
output
|
||||
<< x->first
|
||||
<< "\t"
|
||||
<< x->second
|
||||
<< "\n";
|
||||
x++;
|
||||
}
|
||||
return output.str();
|
||||
}
|
||||
|
||||
std::ostream& agn::operator<< (std::ostream& outstream, cloudy_result output) {
|
||||
outstream.width(5);
|
||||
outstream
|
||||
<< std::fixed
|
||||
<< std::setprecision(2)
|
||||
<< output.hden
|
||||
<< " x "
|
||||
<< output.phi
|
||||
<< " (colden "
|
||||
<< std::fixed
|
||||
<< std::setprecision(0)
|
||||
<< output.colden
|
||||
<< "): "
|
||||
<< output.emergent_line_intensity.size()
|
||||
<< " emission lines, "
|
||||
<< output.cautions.size()
|
||||
<< " cautions present.";
|
||||
return outstream;
|
||||
}
|
||||
|
||||
std::ifstream& operator>> (std::ifstream& inputfile,agn::cloudy_grid& grid) {
|
||||
grid = agn::read_cloudy_grid(inputfile);
|
||||
return inputfile;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
agn::cloudy_grid agn::read_cloudy_grid(std::ifstream& inputfile) {
|
||||
if(agn::debug) std::cout
|
||||
<< "Constructing cloudy output grid from file.\n";
|
||||
inputfile.clear();
|
||||
inputfile.seekg(0);
|
||||
std::string inputline;
|
||||
int line_num=0;
|
||||
getline(inputfile,inputline);
|
||||
std::string curstr = inputline.substr(0,23);
|
||||
std::string seek_string = "Producing grid output.";
|
||||
int pos = curstr.find(seek_string);
|
||||
while(line_num < 1000) {
|
||||
line_num++;
|
||||
getline(inputfile,inputline);
|
||||
curstr = inputline.substr(0,30);
|
||||
pos = inputline.find(seek_string);
|
||||
if (pos != std::string::npos) break;
|
||||
}
|
||||
if(agn::debug) std::cout
|
||||
<< "Collecting grid meta data starting on line "
|
||||
<< line_num
|
||||
<< std::endl;
|
||||
agn::gridcoordlist coordlist;
|
||||
std::pair<double,double> xy (0,0);
|
||||
seek_string="**************************************************";
|
||||
while(!inputfile.eof()) {
|
||||
while (inputline.find(seek_string) == std::string::npos)
|
||||
getline(inputfile,inputline);
|
||||
while(inputfile.peek() == ' ') inputfile.get(); // Skip blank space
|
||||
// Break for first grid
|
||||
if (inputline.find("GRID_DELIMIT") != std::string::npos) break;
|
||||
char nextchar = inputfile.peek();
|
||||
//bool hascoords = nextchar != '*' && nextchar != ' ' && nextchar != '\n';
|
||||
bool hascoords = isalnum(nextchar);
|
||||
if (hascoords) {
|
||||
//if(agn::debug) std::cout << "Has coords.\n";
|
||||
while (!isdigit(inputfile.peek())) inputfile.get();
|
||||
inputfile >> xy.first;
|
||||
while (!isdigit(inputfile.peek())) inputfile.get();
|
||||
inputfile >> xy.second;
|
||||
std::pair<double,double> newentry (xy);
|
||||
coordlist.push_back(newentry);
|
||||
getline(inputfile,inputline);
|
||||
}
|
||||
else {
|
||||
getline(inputfile,inputline);
|
||||
while (inputline.find(seek_string) == std::string::npos)
|
||||
getline(inputfile,inputline);
|
||||
}
|
||||
}
|
||||
if(agn::debug) std::cout
|
||||
<< "Reached first grid. "
|
||||
<< coordlist.size()
|
||||
<< " coordinate pairs found.\n";
|
||||
agn::cloudy_grid grid;
|
||||
agn::gridcoordlist::iterator coords = coordlist.begin();
|
||||
while(grid.size() < coordlist.size()) {
|
||||
agn::cloudy_result point;
|
||||
point.hden = coords->first;
|
||||
point.phi = coords->second;
|
||||
|
||||
if(agn::debug) std::cout
|
||||
<< "Grabbing header and cautions.";
|
||||
seek_string = "Intrinsic line intensities";
|
||||
std::string header="";
|
||||
std::list<std::string> cautions;
|
||||
while (inputline.find(seek_string) == std::string::npos) {
|
||||
getline(inputfile,inputline);
|
||||
header.append(inputline);
|
||||
header.append("\n");
|
||||
if(inputline[1] == 'C' && inputline[2] == '-') cautions.push_back(inputline);
|
||||
}
|
||||
point.header = header;
|
||||
point.cautions = cautions;
|
||||
std::stringstream headerstr;
|
||||
headerstr << header;
|
||||
std::string headerword="";
|
||||
headerstr.clear();
|
||||
headerstr.seekg(0);
|
||||
if(agn::debug) std::cout
|
||||
<< " Grabbing iterations.";
|
||||
int iterations;
|
||||
while(!headerstr.eof()) {
|
||||
headerstr >> headerword;
|
||||
if(headerword == "Iteration") {
|
||||
headerstr >> iterations;
|
||||
break;
|
||||
}
|
||||
}
|
||||
point.iterations = iterations;
|
||||
headerstr.clear();
|
||||
headerstr.seekg(0);
|
||||
if(agn::debug) std::cout
|
||||
<< " Grabbing colden.";
|
||||
double colden;
|
||||
while(!headerstr.eof()) {
|
||||
headerstr >> headerword;
|
||||
if(headerword == "column") {
|
||||
headerstr >> headerword;
|
||||
if(headerword == "density") {
|
||||
headerstr >> colden;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
point.colden = colden;
|
||||
if(agn::debug) std::cout
|
||||
<< " Grabbing emission lines.";
|
||||
agn::seek_to("Emergent line intensities",inputfile);
|
||||
std::list<std::string> emergent_line_raw_text;
|
||||
getline(inputfile,inputline);
|
||||
while (inputline != "") {
|
||||
if(inputline.find("..") != std::string::npos) {
|
||||
getline(inputfile,inputline);
|
||||
continue;
|
||||
}
|
||||
emergent_line_raw_text.push_back(inputline);
|
||||
getline(inputfile,inputline);
|
||||
}
|
||||
point.emergent_line_raw_text.swap(emergent_line_raw_text);
|
||||
std::list<std::string>::iterator linetext_it=point.emergent_line_raw_text.begin();
|
||||
std::list<std::string> duplicate_labels;
|
||||
int index=0;
|
||||
while(linetext_it != point.emergent_line_raw_text.end()) {
|
||||
std::string label=(*linetext_it).substr(1,13);
|
||||
agn::cloudy_line_data data;
|
||||
data.index = ++index;
|
||||
std::stringstream values;
|
||||
data.radiated_energy = atof((*linetext_it).substr(17,5).c_str());
|
||||
data.eq_width = atof((*linetext_it).substr(22,11).c_str());
|
||||
if(point.emergent_line_intensity.count(label) == 0) {
|
||||
data.has_duplicates = false;
|
||||
point.emergent_line_intensity[label] = data;
|
||||
}
|
||||
else {
|
||||
duplicate_labels.push_back(label);
|
||||
data.has_duplicates = true;
|
||||
point.emergent_line_intensity[label].has_duplicates = true;
|
||||
int j=1;
|
||||
while(true) {
|
||||
std::stringstream newlabel;
|
||||
newlabel << label;
|
||||
newlabel << " j=" << j;
|
||||
if(point.emergent_line_intensity.count(newlabel.str()) != 0) {
|
||||
j++;
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
point.emergent_line_intensity[newlabel.str()] = data;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
linetext_it++;
|
||||
}
|
||||
if(agn::debug) std::cout
|
||||
<< " Grabbing footer.";
|
||||
while (inputline == "")
|
||||
getline(inputfile,inputline);
|
||||
std::string footer="";
|
||||
seek_string="GRID_DELIMIT";
|
||||
while (inputline.find(seek_string) == std::string::npos){
|
||||
footer.append(inputline);
|
||||
footer.append("\n");
|
||||
getline(inputfile,inputline);
|
||||
}
|
||||
if(agn::debug) std::cout
|
||||
<< "\nAdding point to grid: "
|
||||
<< point
|
||||
<< std::endl;
|
||||
grid[*coords] = point;
|
||||
coords++;
|
||||
}
|
||||
if(agn::debug) std::cout
|
||||
<< "Grid captured. "
|
||||
<< grid.size()
|
||||
<< " points compiled.\n";
|
||||
return grid;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
33
src/convert_sed_ryd_to_ev.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
|
||||
// A program to convert a cloudy incident continuum's photon
|
||||
// energy unit from Rydberg to eV. Photon energy needs to be
|
||||
// in the first column.
|
||||
|
||||
// ./convert_rydberg_to_eV <continuum_file>
|
||||
|
||||
#include "agn.hpp"
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
std::stringstream output_filename;
|
||||
output_filename << argv[1];
|
||||
output_filename << ".ineV";
|
||||
std::ofstream fileout (output_filename.str().c_str(), std::ofstream::out);
|
||||
|
||||
std::ifstream filein (argv[1], std::ifstream::in);
|
||||
agn::sed_table output_table = agn::read_and_convert_sed_table(filein);
|
||||
|
||||
std::cout << "Found "
|
||||
<< output_table.value.size()
|
||||
<< " photon indices with "
|
||||
;
|
||||
if (output_table.header.empty()) std::cout << "no file header.";
|
||||
else std::cout << "a file header.";
|
||||
std::cout << "\n";
|
||||
|
||||
// Write to new file
|
||||
fileout << agn::format_sed_table(output_table);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
52
src/create_fort_files.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
#include "agn.hpp"
|
||||
#include "spectral_lines.hpp"
|
||||
|
||||
|
||||
int main(int argc, char const *argv[]) {
|
||||
std::ifstream cloudy_result_file;
|
||||
cloudy_result_file.open(argv[1]);
|
||||
|
||||
std::cout
|
||||
<< "Reading cloudy grid from "
|
||||
<< argv[1]
|
||||
<< ".\n";
|
||||
agn::cloudy_grid grid = agn::read_cloudy_grid(cloudy_result_file);
|
||||
|
||||
std::cout
|
||||
<< "Reading line list from "
|
||||
<< argv[2]
|
||||
<< ".\n";
|
||||
std::ifstream line_list_file;
|
||||
line_list_file.open(argv[2]);
|
||||
agn::line_list lines_to_print = agn::read_line_list(line_list_file);
|
||||
std::cout
|
||||
<< "Compiling table2ds for "
|
||||
<< lines_to_print.size()
|
||||
<< " emission lines.\n";
|
||||
std::list<agn::eqwidth_table> tables = agn::compile_eqwidth_tables(grid,lines_to_print,1215.00);
|
||||
|
||||
std::cout
|
||||
<< "Printing "
|
||||
<< tables.size()
|
||||
<< " tables to fortfiles.\n";
|
||||
std::list<agn::eqwidth_table>::iterator table_it = tables.begin();
|
||||
int fortfilenum=11;
|
||||
while(table_it != tables.end()) {
|
||||
std::ofstream outfile;
|
||||
std::stringstream filename;
|
||||
filename << "fort.";
|
||||
filename << fortfilenum;
|
||||
outfile.open(filename.str().c_str());
|
||||
outfile << *table_it;
|
||||
outfile.close();
|
||||
table_it++;
|
||||
fortfilenum++;
|
||||
}
|
||||
|
||||
std::cout << "Done.\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
191
src/generate_sed.cpp
Normal file
@ -0,0 +1,191 @@
|
||||
#include "agn.hpp"
|
||||
|
||||
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
|
||||
std::cout
|
||||
<< "Setting up environment.\n";
|
||||
|
||||
bool debug=true;
|
||||
|
||||
// Create 2d table using n bins, linear values of SED. The
|
||||
// agn em source class has a function for this. A
|
||||
// std::map<double,double> represents the table.
|
||||
int n = 1000;
|
||||
agn::sed_table SED;
|
||||
|
||||
const char* table_filename = "agn_source_table";
|
||||
const char* debug_filename = "agn_source_debug";
|
||||
const char* cloudyscript_filename = "agn_source_cloudyscript";
|
||||
|
||||
std::ofstream table_file( table_filename,
|
||||
std::ofstream::out
|
||||
);
|
||||
std::ofstream debug_file( debug_filename,
|
||||
std::ofstream::out
|
||||
);
|
||||
std::ofstream cloudyscript_file(cloudyscript_filename,
|
||||
std::ofstream::out
|
||||
);
|
||||
|
||||
if(debug) std::cout
|
||||
<< "Debug mode.\n";
|
||||
|
||||
|
||||
std::cout
|
||||
<< "Creating agn sed object.\n";
|
||||
|
||||
// agn em source spectrum arguments
|
||||
double T=4e6,
|
||||
alpha_ox = -1.20,
|
||||
alpha_x = -0.670,
|
||||
alpha_uv = -1.30,
|
||||
cutoff_uv_rydberg = .25,
|
||||
cutoff_xray_rydberg = .1,
|
||||
log_radius_in_cm=16.7272;;
|
||||
|
||||
agn::sed_pow_law agnsource(
|
||||
T,
|
||||
alpha_ox,
|
||||
alpha_x,
|
||||
alpha_uv,
|
||||
cutoff_uv_rydberg,
|
||||
cutoff_xray_rydberg,
|
||||
log_radius_in_cm
|
||||
);
|
||||
|
||||
if(debug) debug_file
|
||||
<< "cutoff_uv_eV: "
|
||||
<< agnsource._cutoff_uv_eV
|
||||
<< "\n"
|
||||
<< "cutoff_xray_eV: "
|
||||
<< agnsource._cutoff_xray_eV
|
||||
<< "\n"
|
||||
<< "xray coefficient: "
|
||||
<< agnsource._xray_coefficient
|
||||
<< "\n\n";
|
||||
|
||||
|
||||
|
||||
std::cout
|
||||
<< "Evaluating relative spectral intensity for "
|
||||
<< n
|
||||
<< " photon energy bins.\n";
|
||||
|
||||
SED = agnsource.histogram_table(n);
|
||||
|
||||
std::cout
|
||||
<< "Printing SED table to file "
|
||||
<< table_filename
|
||||
<< "\n";
|
||||
|
||||
table_file << agn::format_sed_table(SED);
|
||||
|
||||
std::cout
|
||||
<< "Printing CLOUDY interpolate command syntax to file "
|
||||
<< cloudyscript_filename
|
||||
<< "\n";
|
||||
|
||||
cloudyscript_file << agn::cloudy_interpolate_str(SED);
|
||||
|
||||
std::cout
|
||||
<< "Closing files. Goodbye.\n";
|
||||
|
||||
debug_file.close();
|
||||
cloudyscript_file.close();
|
||||
table_file.close();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
double agn::hnu_at(int i,int n) {
|
||||
double relative_coord=(double)(i)/n;
|
||||
double x_coord = relative_coord*CONT_WIDTH_X + CONT_MIN_X;
|
||||
return pow(10,x_coord);
|
||||
}
|
||||
|
||||
agn::sed_table agn::sed_pow_law::histogram_table(int n){
|
||||
agn::sed_table output;
|
||||
double max=0,min=1,hnu;
|
||||
for(int i=0; i<n; i++) {
|
||||
hnu = hnu_at(i,n);
|
||||
output.value[hnu] = this->sed(hnu);
|
||||
if (output.value[hnu] > max) max = output.value[hnu];
|
||||
if (output.value[hnu] < min) min = output.value[hnu];
|
||||
}
|
||||
// Add a final point at 100 KeV
|
||||
hnu = 1e5;
|
||||
output.value[hnu] = this->sed(hnu);
|
||||
return output;
|
||||
}
|
||||
|
||||
double agn::sed_pow_law::sed(double hnu) {
|
||||
double magnitude=0.0;
|
||||
magnitude += this->eval_uv(hnu);
|
||||
magnitude += this->eval_xray(hnu);
|
||||
if (magnitude < agn::CONT_MIN_VAL) return agn::CONT_MIN_VAL;
|
||||
return magnitude;
|
||||
}
|
||||
double agn::sed_pow_law::eval_uv(double hnu) {
|
||||
double bigbump_kT = _T
|
||||
* agn::BOLTZMANN_CONST;
|
||||
double magnitude = pow(hnu,(1+_alpha_uv))
|
||||
* exp(-(hnu)/bigbump_kT)
|
||||
* exp(-(_cutoff_uv_eV/hnu))
|
||||
* _scaling_factor;
|
||||
if (magnitude < agn::CONT_MIN_VAL) return agn::CONT_MIN_VAL;
|
||||
return magnitude;
|
||||
}
|
||||
double agn::sed_pow_law::eval_xray(double hnu) {
|
||||
return _xray_coefficient
|
||||
* pow(hnu/2000,1+_alpha_x)
|
||||
* exp(-_cutoff_xray_eV/hnu)
|
||||
* _scaling_factor;
|
||||
}
|
||||
|
||||
double agn::sed_pow_law::SED_at_2KeV() {
|
||||
double ELe_at_2500A_no_scale = eval_uv(IN_EV_2500A)
|
||||
/ _scaling_factor;
|
||||
double energy_ratio = 2000/IN_EV_2500A;
|
||||
// Returns EL[e] at 2 KeV
|
||||
return ELe_at_2500A_no_scale
|
||||
* pow(energy_ratio,_alpha_ox + 1);
|
||||
}
|
||||
|
||||
agn::sed_pow_law::sed_pow_law (
|
||||
double T,
|
||||
double alpha_ox,
|
||||
double alpha_x,
|
||||
double alpha_uv,
|
||||
double cutoff_uv_rydberg,
|
||||
double cutoff_xray_rydberg,
|
||||
double log_radius_in_cm,
|
||||
double scaling_factor
|
||||
):
|
||||
_T(T),
|
||||
_alpha_ox(alpha_ox),
|
||||
_alpha_x(alpha_x),
|
||||
_alpha_uv(alpha_uv),
|
||||
_cutoff_uv_rydberg(cutoff_uv_rydberg),
|
||||
_cutoff_xray_rydberg(cutoff_xray_rydberg),
|
||||
_log_radius_in_cm(log_radius_in_cm),
|
||||
_scaling_factor(scaling_factor)
|
||||
{
|
||||
_cutoff_uv_eV = cutoff_uv_rydberg*RYDBERG_UNIT_EV;
|
||||
_cutoff_xray_eV = cutoff_xray_rydberg*RYDBERG_UNIT_EV;
|
||||
_radius_in_cm = pow(10,log_radius_in_cm);
|
||||
_radius_in_cm_squared = _radius_in_cm*_radius_in_cm;
|
||||
_xray_coefficient = agn::sed_pow_law::SED_at_2KeV();
|
||||
}
|
361
src/interpolation_fix.cpp
Normal file
@ -0,0 +1,361 @@
|
||||
#include "agn.hpp"
|
||||
#include "spectral_lines.hpp"
|
||||
#include "spline.h"
|
||||
|
||||
bool print_histogram=true;
|
||||
|
||||
int main(int argc, char const *argv[]) {
|
||||
std::ifstream eqwidth_table_file;
|
||||
eqwidth_table_file.open(argv[1]);
|
||||
agn::eqwidth_table jagged_table = agn::read_eqwidth_table(eqwidth_table_file);
|
||||
eqwidth_table_file.close();
|
||||
|
||||
std::cout
|
||||
<< "Interpolation Fix - "
|
||||
<< jagged_table.header[0]
|
||||
<< "\n";
|
||||
|
||||
std::cout << "Finding outliers.\n";
|
||||
agn::gridcoordlist outliers = agn::find_outliers(jagged_table);
|
||||
//agn::gridcoordlist outliers = agn::known_outliers();
|
||||
|
||||
std::cout << "Replacing outliers with interpolated values.\n";
|
||||
agn::eqwidth_table smooth_table = agn::smooth(jagged_table,outliers);
|
||||
|
||||
// Output debug info
|
||||
agn::gridcoordlist::iterator outlier_it = outliers.begin();
|
||||
while(outlier_it != outliers.end()) {
|
||||
std::cout
|
||||
<< std::setprecision(2)
|
||||
<< std::fixed
|
||||
<< "Supposed smooth at: "
|
||||
<< outlier_it->first
|
||||
<< ", "
|
||||
<< outlier_it->second
|
||||
<< "\n"
|
||||
<< std::scientific
|
||||
<< "Old value: "
|
||||
<< jagged_table.value[outlier_it->first][outlier_it->second]
|
||||
<< "\t"
|
||||
<< "New value: "
|
||||
<< smooth_table.value[outlier_it->first][outlier_it->second]
|
||||
<< "\n";
|
||||
outlier_it++;
|
||||
}
|
||||
std::ofstream smoothed_table_file;
|
||||
smoothed_table_file.open("smoothed_eqwidth_table");
|
||||
smoothed_table_file << agn::format_eqwidth_table(smooth_table);
|
||||
smoothed_table_file.close();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
agn::eqwidth_table agn::smooth(agn::eqwidth_table & jagged_table,agn::gridcoordlist coordlist) {
|
||||
if(agn::debug) std::cout
|
||||
<< "Received Coordinate list with "
|
||||
<< coordlist.size()
|
||||
<< " items.\n";
|
||||
|
||||
agn::eqwidth_table smooth_table = agn::eqwidth_table(jagged_table);
|
||||
agn::gridcoordlist::iterator coord_it = coordlist.begin();
|
||||
while(coord_it != coordlist.end() ) {
|
||||
double x = coord_it->first;
|
||||
double y = coord_it->second;
|
||||
if(agn::debug) std::cout
|
||||
<< "Smoothing at hden="
|
||||
<< x
|
||||
<< ", phi="
|
||||
<< y
|
||||
<< ":\t";
|
||||
agn::table1d slice = agn::table1d(smooth_table.value[x]);
|
||||
|
||||
double oldx = y;
|
||||
double oldy = slice[oldx];
|
||||
|
||||
std::vector<double> X;
|
||||
std::vector<double> Y;
|
||||
|
||||
// Omit any points in the outlier list.
|
||||
std::set<double> omissions;
|
||||
agn::gridcoordlist::iterator outlier_it = coordlist.begin();
|
||||
while ( outlier_it != coordlist.end() ) {
|
||||
if ( (*outlier_it).first == (*coord_it).first ) {
|
||||
omissions.insert((*outlier_it).second);
|
||||
}
|
||||
outlier_it++;
|
||||
}
|
||||
|
||||
agn::table1d::iterator slit = slice.begin();
|
||||
while ( slit != slice.end() ) {
|
||||
std::set<double>::iterator omissions_it = omissions.begin();
|
||||
while ( omissions_it != omissions.end() ) {
|
||||
if ( slit->first == *omissions_it) {
|
||||
slit++;
|
||||
continue;
|
||||
}
|
||||
omissions_it++;
|
||||
}
|
||||
X.push_back(slit->first);
|
||||
Y.push_back(slit->second);
|
||||
slit++;
|
||||
}
|
||||
|
||||
agn::Spline<double,double> interpolator(X,Y);
|
||||
|
||||
slit = slice.find(y);
|
||||
|
||||
double newx = slit->first;
|
||||
double newy = interpolator[newx];
|
||||
|
||||
if ( newx != oldx ) {
|
||||
std::cerr << "Problem smoothing.\n";
|
||||
coord_it++;
|
||||
continue;
|
||||
}
|
||||
|
||||
smooth_table.value[x][y] = newy;
|
||||
|
||||
if ( agn::debug ) {
|
||||
std::cout
|
||||
<< std::scientific
|
||||
<< "Smoothed: "
|
||||
<< newx
|
||||
<< ", "
|
||||
<< oldy
|
||||
<< " -> "
|
||||
<< newy
|
||||
<< "\n";
|
||||
}
|
||||
|
||||
coord_it++;
|
||||
}
|
||||
|
||||
if(agn::debug) std::cout << "\n";
|
||||
return smooth_table;
|
||||
}
|
||||
|
||||
agn::gridcoordlist agn::known_outliers() {
|
||||
agn::gridcoordlist colden23_181515_diverged_points;
|
||||
colden23_181515_diverged_points.push_front(std::make_pair(10.25,20.0 ));
|
||||
colden23_181515_diverged_points.push_front(std::make_pair(10.5,20.25 ));
|
||||
colden23_181515_diverged_points.push_front(std::make_pair(11.25,20.75));
|
||||
colden23_181515_diverged_points.push_front(std::make_pair(11.5,21.0 ));
|
||||
colden23_181515_diverged_points.push_front(std::make_pair(11.5,22.0 ));
|
||||
colden23_181515_diverged_points.push_front(std::make_pair(11.75,21.25));
|
||||
colden23_181515_diverged_points.push_front(std::make_pair(12.0,21.5 ));
|
||||
colden23_181515_diverged_points.push_front(std::make_pair(12.5,22.0 ));
|
||||
colden23_181515_diverged_points.push_front(std::make_pair(12.5,22.25 ));
|
||||
colden23_181515_diverged_points.push_front(std::make_pair(9.75,19.75 ));
|
||||
return colden23_181515_diverged_points;
|
||||
}
|
||||
|
||||
agn::gridcoordlist agn::find_outliers(agn::eqwidth_table jagged_table) {
|
||||
if (agn::debug) std::cout
|
||||
<< "Scanning for outliers.\n";
|
||||
agn::gridcoordlist outliers;
|
||||
|
||||
// The distribution is
|
||||
// parameterised by x=log(jagged_table.hden) and
|
||||
// y=log(jagged_table.eqwidth).
|
||||
|
||||
agn::iterator2d hden_it = jagged_table.value.begin();
|
||||
while ( hden_it != jagged_table.value.end() ) {
|
||||
agn::table1d slice = hden_it->second;
|
||||
if( agn::debug ) std::cout
|
||||
<< "\nhden= "
|
||||
<< (hden_it->first)
|
||||
<< ": ";
|
||||
|
||||
// Crawl, checking slope, until a positive slope is found.
|
||||
agn::table1d::iterator phi_it = slice.begin();
|
||||
double x1,x2,y1,y2,slope;
|
||||
std::vector<double> ref_curve_x,ref_curve_y,curve_back_x,curve_back_y;
|
||||
double anomalies_start_x,anomalies_end_x;
|
||||
x1 = phi_it->first;
|
||||
y1 = log10(phi_it->second);
|
||||
ref_curve_x.push_back(x1);
|
||||
ref_curve_y.push_back(y1);
|
||||
phi_it++;
|
||||
bool beginning_rise = true;
|
||||
while ( phi_it != slice.end() ) {
|
||||
x2 = phi_it->first;
|
||||
y2 = log10(phi_it->second);
|
||||
slope = (y2 - y1)/(x2 - x1);
|
||||
if (slope > -0.05 ) {
|
||||
if (agn::debug) std::cout
|
||||
<< "Found anomaly(x="
|
||||
<< x1
|
||||
<< ";slope="
|
||||
<< slope
|
||||
<< "), ";
|
||||
if ( beginning_rise ) {
|
||||
if (agn::debug) std::cout
|
||||
<< "Found left-wise rise, ";
|
||||
while ( slope > -0.05 ) {
|
||||
x1 = phi_it->first;
|
||||
y1 = log10(phi_it->second);
|
||||
phi_it++;
|
||||
if ( phi_it == slice.end() ) break;
|
||||
x2 = phi_it->first;
|
||||
y2 = log10(phi_it->second);
|
||||
slope = (y2 - y1)/(x2 - x1);
|
||||
}
|
||||
ref_curve_x.clear();
|
||||
ref_curve_y.clear();
|
||||
ref_curve_x.push_back(x1);
|
||||
ref_curve_y.push_back(y1);
|
||||
}
|
||||
else {
|
||||
ref_curve_x.pop_back();
|
||||
ref_curve_y.pop_back();
|
||||
phi_it++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( slope < -0.05 && ( slice.find(x1) != slice.begin())) beginning_rise = false;
|
||||
x1 = x2;
|
||||
y1 = y2;
|
||||
ref_curve_x.push_back(x1);
|
||||
ref_curve_y.push_back(y1);
|
||||
phi_it++;
|
||||
}
|
||||
|
||||
if ( phi_it == slice.end() ) {
|
||||
if (agn::debug) std::cout
|
||||
<< "Clean";
|
||||
hden_it++;
|
||||
continue;
|
||||
}
|
||||
|
||||
x1 = phi_it->first;
|
||||
y1 = log10(phi_it->second);
|
||||
curve_back_x.push_back(x1);
|
||||
curve_back_y.push_back(y1);
|
||||
phi_it++;
|
||||
while ( phi_it != slice.end() ) {
|
||||
x2 = phi_it->first;
|
||||
y2 = log10(phi_it->second);
|
||||
slope = (y2 - y1)/(x2 - x1);
|
||||
if (slope > 0 ) {
|
||||
curve_back_x.clear();
|
||||
curve_back_y.clear();
|
||||
}
|
||||
if ( y2 <= EQWIDTH_MIN_VAL_LOG ) {
|
||||
break;
|
||||
}
|
||||
x1 = x2;
|
||||
y1 = y2;
|
||||
curve_back_x.push_back(x1);
|
||||
curve_back_y.push_back(y1);
|
||||
phi_it++;
|
||||
}
|
||||
|
||||
if ( curve_back_x.size() < 2 ) {
|
||||
if(agn::debug) std::cout
|
||||
<< "Found too few end points for spline ("
|
||||
<< curve_back_x.size()
|
||||
<< ")";
|
||||
hden_it++;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (ref_curve_x.size() > 2) {
|
||||
ref_curve_x.erase(ref_curve_x.begin());
|
||||
ref_curve_y.erase(ref_curve_y.begin());
|
||||
ref_curve_x.pop_back();
|
||||
ref_curve_y.pop_back();
|
||||
}
|
||||
if (curve_back_x.size() > 2) {
|
||||
curve_back_x.erase(curve_back_x.begin());
|
||||
curve_back_y.erase(curve_back_y.begin());
|
||||
}
|
||||
anomalies_start_x = *ref_curve_x.rbegin();
|
||||
anomalies_end_x = *curve_back_x.begin();
|
||||
|
||||
if (agn::debug) std::cout
|
||||
<< "Anomalous region between x coords "
|
||||
<< anomalies_start_x
|
||||
<< " and "
|
||||
<< anomalies_end_x
|
||||
<< ", ";
|
||||
|
||||
std::vector<double>::iterator curve_back_x_it = curve_back_x.begin();
|
||||
std::vector<double>::iterator curve_back_y_it = curve_back_y.begin();
|
||||
while ( curve_back_x_it != curve_back_x.end() &&
|
||||
curve_back_y_it != curve_back_y.end() ) {
|
||||
ref_curve_x.push_back(*curve_back_x_it);
|
||||
ref_curve_y.push_back(*curve_back_y_it);
|
||||
curve_back_x_it++;
|
||||
curve_back_y_it++;
|
||||
}
|
||||
|
||||
if (agn::debug) std::cout
|
||||
<< "Creating Spline with "
|
||||
<< ref_curve_x.size()
|
||||
<< " points, ";
|
||||
|
||||
// Creating spline from vectors
|
||||
agn::Spline<double,double> testing_spline(ref_curve_x,ref_curve_y);
|
||||
|
||||
// Calculate sigma from the reference curve.
|
||||
std::vector<double>::iterator ref_curve_y_it = ref_curve_y.begin();
|
||||
double sigma = 0;
|
||||
double mean = 0;
|
||||
int num = ref_curve_y.size();
|
||||
double sum = 0;
|
||||
double threshold = 0;
|
||||
while ( ref_curve_y_it != ref_curve_y.end() ) {
|
||||
mean += *ref_curve_y_it;
|
||||
ref_curve_y_it++;
|
||||
}
|
||||
mean /= num;
|
||||
ref_curve_y_it = ref_curve_y.begin();
|
||||
while ( ref_curve_y_it != ref_curve_y.end() ) {
|
||||
sum += pow(*ref_curve_y_it - mean,2);
|
||||
ref_curve_y_it++;
|
||||
}
|
||||
sigma = sqrt(sum / num);
|
||||
|
||||
// Interpolate all values in anomalies_x range and add to list when value is outside threshold.
|
||||
//threshold = sigma*SIGMA_THRESHOLD_MULTIPLIER;
|
||||
//if (agn::debug) std::cout
|
||||
// << "using sigma(n="
|
||||
// << num
|
||||
// << ")="
|
||||
// << sigma
|
||||
// << " and threshold="
|
||||
// << threshold
|
||||
// << ", ";
|
||||
phi_it = slice.find(anomalies_start_x);
|
||||
while (phi_it != (++(slice.find(anomalies_end_x)))) {
|
||||
y1 = log10(phi_it->second);
|
||||
x1 = phi_it->first;
|
||||
y2 = testing_spline[x1];
|
||||
//threshold = RATIO_THRESHOLD_MULTIPLIER * (y2 - EQWIDTH_MIN_VAL_LOG);
|
||||
threshold = 2*log(1 + RATIO_THRESHOLD_MULTIPLIER);
|
||||
double absdiff = sqrt(pow(y2 - y1,2));
|
||||
if(agn::debug) std::cout
|
||||
<< "Checking "
|
||||
<< "x="
|
||||
<< x1
|
||||
<< "("
|
||||
<< absdiff
|
||||
<< " > "
|
||||
<< threshold
|
||||
<< "), ";
|
||||
if ( absdiff > threshold) {
|
||||
if(agn::debug) std::cout
|
||||
<< "MARKED, ";
|
||||
std::pair<double,double> outlier = std::make_pair(hden_it->first,phi_it->first);
|
||||
outliers.push_back(outlier);
|
||||
}
|
||||
phi_it++;
|
||||
}
|
||||
if(agn::debug) std::cout << "\n";
|
||||
hden_it++;
|
||||
}
|
||||
|
||||
if (agn::debug) std::cout << "\n";
|
||||
return outliers;
|
||||
}
|
4
src/png++-0.2.5/AUTHORS
Normal file
@ -0,0 +1,4 @@
|
||||
png++ is written by Alexander Shulgin (alex dot shulgin at gmail dot com)
|
||||
Copyright (C) 2007,2008
|
||||
|
||||
When writing to me be sure to put png++: in the subject :-)
|
13
src/png++-0.2.5/BUGS
Normal file
@ -0,0 +1,13 @@
|
||||
This file lists known bugs and limitations in png++:
|
||||
|
||||
- Lacks support for output transformations
|
||||
|
||||
- Lacks support for optional/unknown chunks in PNG data stream
|
||||
|
||||
- Documentation sucks
|
||||
|
||||
|
||||
To report bugs, please use Savannah bug tracker:
|
||||
http://savannah.nongnu.org/bugs/?group=pngpp&func=additem
|
||||
|
||||
Do not forget to check if the bug was already filed. :-)
|
25
src/png++-0.2.5/COPYING
Normal file
@ -0,0 +1,25 @@
|
||||
Copying png++ is subject to the following license:
|
||||
|
||||
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.
|
||||
|
||||
3. The name of the author may not be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
29
src/png++-0.2.5/ChangeLog
Normal file
@ -0,0 +1,29 @@
|
||||
2009-06-21 Alex Shulgin
|
||||
|
||||
* config.hpp: Added support for FreeBSD (detect endianness).
|
||||
Patch by <c.petrik.sosa@gmail.com>.
|
||||
|
||||
png++-0.2.3 19 Oct 2008
|
||||
|
||||
Fixed numerous `already defined' errors due to require_color_space
|
||||
implementation. Added `config.hpp'. Fixed `strerror' usage.
|
||||
Minor docs fixes.
|
||||
|
||||
png++-0.2.1 08 Dec 2007
|
||||
|
||||
Added support for tRNS chunk. Added non-std IO streams support.
|
||||
Fixed 16-bit endianness problems. Improved test script.
|
||||
|
||||
png++-0.2.0 08 Jul 2007
|
||||
|
||||
Major internal code refactoring. Added support for non-8-bit
|
||||
data, row-by-row IO, added docs, test suite and more. Fixed some
|
||||
bugs including interlace handling.
|
||||
|
||||
png++-0.1.1 07 Apr 2007
|
||||
|
||||
Added appropriate copyright notices.
|
||||
|
||||
png++-0.1.0 04 Feb 2007
|
||||
|
||||
Initial release.
|
1304
src/png++-0.2.5/Doxyfile
Normal file
81
src/png++-0.2.5/INSTALL
Normal file
@ -0,0 +1,81 @@
|
||||
General
|
||||
=======
|
||||
|
||||
PNG++ comes as a set of header files and does not require compilation
|
||||
to be installed. For the same reason there are no binary packages for
|
||||
png++.
|
||||
|
||||
|
||||
Prerequisites
|
||||
=============
|
||||
|
||||
- png++ is known to work with libpng-1.2.x (probably, the 1.4.x
|
||||
flavour will work too)
|
||||
|
||||
- png++ compiles with g++-4.1. Other version should work well too,
|
||||
but I have not tested.
|
||||
|
||||
- png++ relies on GNU make for compiling tests and examples; in
|
||||
particular it uses "remaking makefiles" feature.
|
||||
|
||||
- Documentation is produced using doxygen (http://www.doxygen.org/).
|
||||
|
||||
|
||||
Installation
|
||||
============
|
||||
|
||||
Follow these instructions in order to install png++:
|
||||
|
||||
- Unpack source package:
|
||||
|
||||
$ tar -zxf png++-0.2.x.tar.gz -C ~/src
|
||||
|
||||
- Go to your brand new png++ sources directory:
|
||||
|
||||
$ cd ~/src/png++-0.2.x
|
||||
|
||||
- Issue make to test how it's doing:
|
||||
|
||||
$ make
|
||||
|
||||
This will compile examples in the example/ directory.
|
||||
|
||||
As always, CFLAGS and LDFLAGS could be used to adjust compilation. In
|
||||
addition, you might want to specify custom libpng-config. Use
|
||||
LIBPNG_CONFIG variable for that purpose, like this:
|
||||
|
||||
$ make LIBPNG_CONFIG=~/bin/libpng-config
|
||||
|
||||
If everything goes well, try:
|
||||
|
||||
$ make test
|
||||
|
||||
(or "make check" which is the same as above). This will run the test
|
||||
suite. If tests do not produce error messages then probably all is
|
||||
OK.
|
||||
|
||||
- Now you can create documentation (optional). Use
|
||||
|
||||
$ make docs
|
||||
|
||||
to run doxygen in the sources directory.
|
||||
|
||||
- Now it is time to become root and install png++ into your system:
|
||||
|
||||
# make install
|
||||
|
||||
It's OK to issue "make install" under ordinary user permissions if you
|
||||
want to install png++ into your home directory. Run the following
|
||||
command:
|
||||
|
||||
$ make install PREFIX=$HOME
|
||||
|
||||
This will copy png++ header files to ~/include/png++ and documentation
|
||||
files to ~/share/doc/png++-0.2.x (if the docs were built).
|
||||
|
||||
Without a PREFIX png++ installs to /usr/local
|
||||
|
||||
|
||||
Happy hacking!
|
||||
--
|
||||
Alex Shulgin <alex.shulgin@gmail.com>
|
148
src/png++-0.2.5/Makefile
Normal file
@ -0,0 +1,148 @@
|
||||
#
|
||||
# Copyright (C) 2007,2008 Alex Shulgin
|
||||
#
|
||||
# This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
# software; the exact copying conditions are as follows:
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 3. The name of the author may not be used to endorse or promote products
|
||||
# derived from this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
#
|
||||
|
||||
# don't forget to update version before releasing!
|
||||
version := 0.2.5
|
||||
|
||||
ifndef PREFIX
|
||||
PREFIX := /usr/local
|
||||
endif
|
||||
|
||||
ifdef MINGW
|
||||
bin_suffix := .exe
|
||||
endif
|
||||
|
||||
make_cflags := -Wall $(CFLAGS) -I$(PREFIX)/include
|
||||
make_ldflags := $(LDFLAGS) -L$(PREFIX)/lib
|
||||
|
||||
ifndef NDEBUG
|
||||
make_cflags := $(make_cflags) -g
|
||||
make_ldflags := $(make_ldflags) -g
|
||||
endif
|
||||
|
||||
ifndef LIBPNG_CONFIG
|
||||
LIBPNG_CONFIG := libpng-config
|
||||
endif
|
||||
|
||||
build_files := Makefile Doxyfile
|
||||
doc_files := AUTHORS BUGS ChangeLog COPYING INSTALL NEWS README TODO
|
||||
headers := *.hpp
|
||||
sources :=
|
||||
|
||||
dist_dir := png++-$(version)
|
||||
dist_package := png++-$(version).tar.gz
|
||||
dist_files := $(build_files) $(doc_files) \
|
||||
$(headers) $(sources)
|
||||
dist_subdirs := example test
|
||||
|
||||
all: examples
|
||||
|
||||
install: install-headers install-docs
|
||||
|
||||
uninstall: uninstall-headers uninstall-docs
|
||||
|
||||
install-headers:
|
||||
mkdir -p $(PREFIX)/include/png++
|
||||
cp *.hpp $(PREFIX)/include/png++
|
||||
|
||||
uninstall-headers:
|
||||
rm -rf $(PREFIX)/include/png++
|
||||
|
||||
dist: dist-mkdir dist-copy-files dist-package
|
||||
|
||||
dist-mkdir:
|
||||
rm -rf $(dist_dir)
|
||||
mkdir $(dist_dir)
|
||||
|
||||
dist-copy-files:
|
||||
cp $(dist_files) $(dist_dir)
|
||||
for i in $(dist_subdirs); do \
|
||||
$(MAKE) dist-copy-files -C $$i $(MAKEFLAGS) \
|
||||
dist_dir=`pwd`/$(dist_dir); \
|
||||
done
|
||||
|
||||
dist-package:
|
||||
rm -f $(dist_package)
|
||||
tar -zcf $(dist_package) $(dist_dir) --exclude=.svn --exclude='*~'
|
||||
rm -rf $(dist_dir)
|
||||
|
||||
clean: test-clean examples-clean
|
||||
# rm -f $(targets)
|
||||
|
||||
thorough-clean: clean docs-clean
|
||||
|
||||
check: test
|
||||
|
||||
test:
|
||||
$(MAKE) test -C test $(MAKEFLAGS) PNGPP=`pwd`
|
||||
|
||||
test-clean:
|
||||
$(MAKE) clean -C test $(MAKEFLAGS)
|
||||
|
||||
test-compile-headers: *.hpp
|
||||
for i in *.hpp; do \
|
||||
echo '#include "'$$i'"' >$$i.cpp \
|
||||
&& g++ -c $$i.cpp $(make_cflags) `$(LIBPNG_CONFIG) --cflags`; \
|
||||
done
|
||||
rm -f *.hpp.o *.hpp.cpp
|
||||
|
||||
docs:
|
||||
doxygen
|
||||
|
||||
docs-clean:
|
||||
rm -rf doc
|
||||
|
||||
install-docs:
|
||||
if [ -d doc ]; then \
|
||||
dir=$(PREFIX)/share/doc/$(dist_dir); \
|
||||
rm -rf $$dir; \
|
||||
mkdir -p $$dir \
|
||||
&& cp -r $(doc_files) doc/html $$dir; \
|
||||
cd $(PREFIX)/share/doc; \
|
||||
[ -L png++ ] && rm png++; \
|
||||
[ -d png++ ] || ln -s $(dist_dir) png++; \
|
||||
fi
|
||||
|
||||
uninstall-docs:
|
||||
rm -rf $(PREFIX)/share/doc/$(dist_dir) $(PREFIX)/share/doc/png++
|
||||
|
||||
examples:
|
||||
$(MAKE) -C example $(MAKEFLAGS)
|
||||
|
||||
examples-clean:
|
||||
$(MAKE) clean -C example $(MAKEFLAGS)
|
||||
|
||||
.PHONY: all install \
|
||||
dist dist-mkdir dist-copy-files dist-package \
|
||||
clean thorough-clean \
|
||||
check test test-clean test-compile-headers \
|
||||
docs docs-clean \
|
||||
examples examples-clean
|
54
src/png++-0.2.5/NEWS
Normal file
@ -0,0 +1,54 @@
|
||||
Version 0.2.5:
|
||||
|
||||
- Fixed compatibility with newer libpng versions (>= 1.4)
|
||||
|
||||
- Fixed compilation on FreeBSD.
|
||||
|
||||
- Fixed tRNS handling with transformations.
|
||||
|
||||
- Added IO transformation debugging facility.
|
||||
|
||||
- Better organized test suite.
|
||||
|
||||
Version 0.2.3:
|
||||
|
||||
- Fixed numerous `already defined' errors due to require_color_space
|
||||
implementation.
|
||||
|
||||
- Added `config.hpp'.
|
||||
|
||||
- Fixed `strerror' usage.
|
||||
|
||||
- Minor docs fixes.
|
||||
|
||||
|
||||
Version 0.2.1:
|
||||
|
||||
- Added support for tRNS chunk.
|
||||
|
||||
- Added non-std IO streams support.
|
||||
|
||||
- Fixed 16-bit endianness problems.
|
||||
|
||||
- Improved test script.
|
||||
|
||||
|
||||
Version 0.2.0:
|
||||
|
||||
- Added support for 16-bit data (RGB, RGBA, Grayscale and Gray+Alpha
|
||||
color types)
|
||||
|
||||
- Added support for packed 1-, 2- or 4-bit pixels (Grayscale and
|
||||
Indexed colors)
|
||||
|
||||
- Fixed interlace handling code which was severely broken
|
||||
|
||||
- Added possibility to process images without reading the entire
|
||||
image into memory
|
||||
|
||||
- Internals are refactored while the client interface is mostly
|
||||
unchanged
|
||||
|
||||
- Added intensive test suite
|
||||
|
||||
- Added documentation
|
20
src/png++-0.2.5/TODO
Normal file
@ -0,0 +1,20 @@
|
||||
? add output transformations
|
||||
+ support for non-8bit data
|
||||
+ stream exceptions: badbit only
|
||||
+ adjust png::image for non-memory back end buffer + row-by-row io
|
||||
+ use doxygen
|
||||
- add optional and unknown chunks handling
|
||||
+ change bit_depth to size_t
|
||||
+ move tests sources to test/, examples to examples/
|
||||
+ extract common code from generator/consumer
|
||||
+ update pixel traits to detect channels count
|
||||
+ unify template parameters naming
|
||||
+ make sure all headers compile on their own
|
||||
+ add compilation dependency detection
|
||||
+ add pixel_buffer/image::operator[]
|
||||
+ improve docs and README
|
||||
? endianness in expand_8_to_16()
|
||||
- unify error messages (capitalization, etc.)
|
||||
+ move stream template parameter from class to function level in
|
||||
generator and consumer
|
||||
+ make all tests run even if any of them fails
|
65
src/png++-0.2.5/color.hpp
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
#ifndef PNGPP_COLOR_HPP_INCLUDED
|
||||
#define PNGPP_COLOR_HPP_INCLUDED
|
||||
|
||||
#include "types.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief PNG color struct extension. Adds constructors.
|
||||
*/
|
||||
struct color
|
||||
: png_color
|
||||
{
|
||||
explicit color(byte r = 0, byte g = 0, byte b = 0)
|
||||
{
|
||||
this->red = r;
|
||||
this->green = g;
|
||||
this->blue = b;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Initializes color with a copy of png_color object.
|
||||
*/
|
||||
color(png_color const& other)
|
||||
{
|
||||
this->red = other.red;
|
||||
this->green = other.green;
|
||||
this->blue = other.blue;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_COLOR_HPP_INCLUDED
|
61
src/png++-0.2.5/config.hpp
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (C) 2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
#ifndef PNGPP_CONFIG_HPP_INCLUDED
|
||||
#define PNGPP_CONFIG_HPP_INCLUDED
|
||||
|
||||
// Endianness test
|
||||
#if defined(__GLIBC__)
|
||||
|
||||
#include <endian.h>
|
||||
|
||||
#elif defined(__WIN32)
|
||||
|
||||
#define __LITTLE_ENDIAN 1234
|
||||
#define __BIG_ENDIAN 4321
|
||||
#define __BYTE_ORDER __LITTLE_ENDIAN
|
||||
|
||||
#elif defined(__APPLE__)
|
||||
|
||||
#include <machine/endian.h>
|
||||
#include <sys/_endian.h>
|
||||
|
||||
#elif defined(__FreeBSD__)
|
||||
|
||||
#include <machine/endian.h>
|
||||
#include <sys/endian.h>
|
||||
|
||||
#else
|
||||
|
||||
#error Byte-order could not be detected.
|
||||
|
||||
#endif
|
||||
|
||||
#endif // PNGPP_CONFIG_HPP_INCLUDED
|
257
src/png++-0.2.5/consumer.hpp
Normal file
@ -0,0 +1,257 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
#ifndef PNGPP_CONSUMER_HPP_INCLUDED
|
||||
#define PNGPP_CONSUMER_HPP_INCLUDED
|
||||
|
||||
#include <cassert>
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
#include <istream>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "error.hpp"
|
||||
#include "streaming_base.hpp"
|
||||
#include "reader.hpp"
|
||||
#include "pixel_buffer.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief Pixel consumer class template.
|
||||
*
|
||||
* Used as a base class for custom pixel consumer classes as well
|
||||
* as inside image class implementation to read pixels into the
|
||||
* pixel buffer.
|
||||
*
|
||||
* Encapsulates PNG %image reading procedure. In order to create
|
||||
* a custom pixel %consumer use CRTP trick:
|
||||
*
|
||||
* \code
|
||||
* class pixel_consumer
|
||||
* : public png::consumer< pixel, pixel_consumer >
|
||||
* {
|
||||
* ...
|
||||
* };
|
||||
* \endcode
|
||||
*
|
||||
* Your pixel %consumer class should implement \c get_next_row()
|
||||
* method and \c reset() method (optional). Their signatures are
|
||||
* as follows:
|
||||
*
|
||||
* \code
|
||||
* png::byte* get_next_row(size_t pos);
|
||||
* void reset(size_t pass);
|
||||
* \endcode
|
||||
*
|
||||
* The \c get_next_row() method is called every time a new row of
|
||||
* %image data is available to the reader. The position of the row
|
||||
* being read is passed as \c pos parameter. The \c pos takes
|
||||
* values from \c 0 to \c <image_height>-1 inclusively. The
|
||||
* method should return the starting address of a row buffer
|
||||
* capable of storing appropriate amount of pixels (i.e. the width
|
||||
* of the %image being read). The address should be casted to
|
||||
* png::byte* pointer type using \c reinterpret_cast<> or a
|
||||
* C-style cast.
|
||||
*
|
||||
* The optional \c reset() method is called every time the new
|
||||
* pass of interlaced %image processing starts. The number of
|
||||
* interlace pass is avaiable as the only parameter of the method.
|
||||
* For non-interlaced images the method is called once prior to
|
||||
* any calls to \c get_next_row(). The value of \c 0 is passed
|
||||
* for the \c pass number.
|
||||
*
|
||||
* An optional template parameter \c info_holder encapsulates
|
||||
* image_info storage policy. Using def_image_info_holder results
|
||||
* in image_info object stored as a sub-object of the consumer
|
||||
* class. You may specify image_info_ref_holder in order to use a
|
||||
* reference to the externally stored image_info object. This way
|
||||
* you will have to construct the consumer object passing the
|
||||
* reference to image_info object.
|
||||
*
|
||||
* Also, you might want implement an %info holder object yourself
|
||||
* to fine-tune your code. In any case, you can access the
|
||||
* image_info object from your %consumer class methods using the
|
||||
* following code:
|
||||
*
|
||||
* \code
|
||||
* png::image_info& info = m_info_holder.get_info();
|
||||
* \endcode
|
||||
*
|
||||
* An optional \c bool template parameter \c interlacing_supported
|
||||
* specifies whether reading interlacing images is supported by
|
||||
* your %consumer class. It defaults to \c false. An attempt to
|
||||
* read an interlaced %image will result in discarding pixels
|
||||
* obtained at all the interlacing passes except the last one.
|
||||
*
|
||||
* In order to fully support interlacing specify \c true for \c
|
||||
* interlacing_supported parameter and implement \c reset()
|
||||
* method.
|
||||
*
|
||||
* \see image, generator
|
||||
*/
|
||||
template< typename pixel,
|
||||
class pixcon,
|
||||
class info_holder = def_image_info_holder,
|
||||
bool interlacing_supported = false >
|
||||
class consumer
|
||||
: public streaming_base< pixel, info_holder >
|
||||
{
|
||||
public:
|
||||
typedef pixel_traits< pixel > traits;
|
||||
|
||||
/**
|
||||
* \brief The default io transformation: does nothing.
|
||||
*/
|
||||
struct transform_identity
|
||||
{
|
||||
void operator()(io_base&) const {}
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Reads an image from the stream using default io
|
||||
* transformation.
|
||||
*/
|
||||
template< typename istream >
|
||||
void read(istream& stream)
|
||||
{
|
||||
read(stream, transform_identity());
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Reads an image from the stream using custom io
|
||||
* transformation.
|
||||
*
|
||||
* Essentially, this method constructs a reader object and
|
||||
* instructs it to read the image from the stream. It handles
|
||||
* IO transformation, as well as interlaced image reading.
|
||||
*/
|
||||
template< typename istream, class transformation >
|
||||
void read(istream& stream, transformation const& transform)
|
||||
{
|
||||
reader< istream > rd(stream);
|
||||
rd.read_info();
|
||||
transform(rd);
|
||||
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
if (pixel_traits< pixel >::get_bit_depth() == 16)
|
||||
{
|
||||
#ifdef PNG_READ_SWAP_SUPPORTED
|
||||
rd.set_swap();
|
||||
#else
|
||||
throw error("Cannot read 16-bit image:"
|
||||
" recompile with PNG_READ_SWAP_SUPPORTED.");
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
// interlace handling _must_ be set up prior to info update
|
||||
size_t pass_count;
|
||||
if (rd.get_interlace_type() != interlace_none)
|
||||
{
|
||||
#ifdef PNG_READ_INTERLACING_SUPPORTED
|
||||
pass_count = rd.set_interlace_handling();
|
||||
#else
|
||||
throw error("Cannot read interlaced image:"
|
||||
" interlace handling disabled.");
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
pass_count = 1;
|
||||
}
|
||||
|
||||
rd.update_info();
|
||||
if (rd.get_color_type() != traits::get_color_type()
|
||||
|| rd.get_bit_depth() != traits::get_bit_depth())
|
||||
{
|
||||
throw std::logic_error("color type and/or bit depth mismatch"
|
||||
" in png::consumer::read()");
|
||||
}
|
||||
|
||||
this->get_info() = rd.get_image_info();
|
||||
|
||||
pixcon* pixel_con = static_cast< pixcon* >(this);
|
||||
if (pass_count > 1 && !interlacing_supported)
|
||||
{
|
||||
skip_interlaced_rows(rd, pass_count);
|
||||
pass_count = 1;
|
||||
}
|
||||
read_rows(rd, pass_count, pixel_con);
|
||||
|
||||
rd.read_end_info();
|
||||
}
|
||||
|
||||
protected:
|
||||
typedef streaming_base< pixel, info_holder > base;
|
||||
|
||||
/**
|
||||
* \brief Constructs a consumer object using passed image_info
|
||||
* object to store image information.
|
||||
*/
|
||||
explicit consumer(image_info& info)
|
||||
: base(info)
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
template< typename istream >
|
||||
void skip_interlaced_rows(reader< istream >& rd, size_t pass_count)
|
||||
{
|
||||
typedef std::vector< pixel > row;
|
||||
typedef row_traits< row > row_traits_type;
|
||||
row dummy_row(this->get_info().get_width());
|
||||
for (size_t pass = 1; pass < pass_count; ++pass)
|
||||
{
|
||||
rd.read_row(reinterpret_cast< byte* >
|
||||
(row_traits_type::get_data(dummy_row)));
|
||||
}
|
||||
}
|
||||
|
||||
template< typename istream >
|
||||
void read_rows(reader< istream >& rd, size_t pass_count,
|
||||
pixcon* pixel_con)
|
||||
{
|
||||
for (size_t pass = 0; pass < pass_count; ++pass)
|
||||
{
|
||||
pixel_con->reset(pass);
|
||||
|
||||
for (size_t pos = 0; pos < this->get_info().get_height(); ++pos)
|
||||
{
|
||||
rd.read_row(pixel_con->get_next_row(pos));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_CONSUMER_HPP_INCLUDED
|
338
src/png++-0.2.5/convert_color_space.hpp
Normal file
@ -0,0 +1,338 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
#ifndef PNGPP_CONVERT_COLOR_SPACE_HPP_INCLUDED
|
||||
#define PNGPP_CONVERT_COLOR_SPACE_HPP_INCLUDED
|
||||
|
||||
#include "error.hpp"
|
||||
#include "rgb_pixel.hpp"
|
||||
#include "rgba_pixel.hpp"
|
||||
#include "gray_pixel.hpp"
|
||||
#include "ga_pixel.hpp"
|
||||
#include "index_pixel.hpp"
|
||||
#include "reader.hpp"
|
||||
#include "writer.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief IO transformation class template. Converts %image %color
|
||||
* space.
|
||||
*/
|
||||
template< typename pixel >
|
||||
struct convert_color_space_impl
|
||||
{
|
||||
typedef pixel_traits< pixel > traits;
|
||||
typedef typename traits::component_type component_type;
|
||||
typedef basic_alpha_pixel_traits< component_type > alpha_traits;
|
||||
|
||||
template< class reader >
|
||||
void operator()(reader& io) const
|
||||
{
|
||||
handle_16(io);
|
||||
handle_alpha(io, alpha_traits::get_alpha_filler());
|
||||
handle_palette(io);
|
||||
handle_rgb(io);
|
||||
handle_gray(io);
|
||||
|
||||
io.set_color_type(traits::get_color_type());
|
||||
io.set_bit_depth(traits::get_bit_depth());
|
||||
}
|
||||
|
||||
protected:
|
||||
static void expand_8_to_16(png_struct*, png_row_info* row_info,
|
||||
byte* row)
|
||||
{
|
||||
#ifdef DEBUG_EXPAND_8_16
|
||||
printf("row: width=%d, bytes=%d, channels=%d\n",
|
||||
row_info->width, row_info->rowbytes, row_info->channels);
|
||||
printf("<= ");
|
||||
dump_row(row, row_info->rowbytes);
|
||||
#endif
|
||||
for (size_t i = row_info->rowbytes; i-- > 0; )
|
||||
{
|
||||
row[2*i + 1] = row[i];
|
||||
row[2*i + 0] = 0;
|
||||
}
|
||||
#ifdef DEBUG_EXPAND_8_16
|
||||
printf("=> ");
|
||||
dump_row(row, 2*row_info->rowbytes);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef DEBUG_EXPAND_8_16
|
||||
static void dump_row(byte const* row, size_t width)
|
||||
{
|
||||
printf("{");
|
||||
for (size_t i = 0; i < width; ++i)
|
||||
{
|
||||
printf(" %02x,", row[i]);
|
||||
}
|
||||
printf(" }\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
template< class reader >
|
||||
static void handle_16(reader& io)
|
||||
{
|
||||
if (io.get_bit_depth() == 16 && traits::get_bit_depth() == 8)
|
||||
{
|
||||
#ifdef PNG_READ_16_TO_8_SUPPORTED
|
||||
io.set_strip_16();
|
||||
#else
|
||||
throw error("expected 8-bit data but found 16-bit;"
|
||||
" recompile with PNG_READ_16_TO_8_SUPPORTED");
|
||||
#endif
|
||||
}
|
||||
if (io.get_bit_depth() != 16 && traits::get_bit_depth() == 16)
|
||||
{
|
||||
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
|
||||
io.set_read_user_transform(expand_8_to_16);
|
||||
io.set_user_transform_info(NULL, 16,
|
||||
traits::get_channels());
|
||||
#else
|
||||
throw error("expected 16-bit data but found 8-bit;"
|
||||
" recompile with"
|
||||
" PNG_READ_USER_TRANSFORM_SUPPORTED");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
template< class reader >
|
||||
static void handle_alpha(reader& io, uint_32 filler)
|
||||
{
|
||||
bool src_alpha = (io.get_color_type() & color_mask_alpha);
|
||||
bool src_tRNS = io.has_chunk(chunk_tRNS);
|
||||
bool dst_alpha = traits::get_color_type() & color_mask_alpha;
|
||||
if ((src_alpha || src_tRNS) && !dst_alpha)
|
||||
{
|
||||
#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
|
||||
io.set_strip_alpha();
|
||||
#else
|
||||
throw error("alpha channel unexpected;"
|
||||
" recompile with"
|
||||
" PNG_READ_STRIP_ALPHA_SUPPORTED");
|
||||
#endif
|
||||
}
|
||||
if (!src_alpha && dst_alpha)
|
||||
{
|
||||
#if defined(PNG_tRNS_SUPPORTED) && defined(PNG_READ_EXPAND_SUPPORTED)
|
||||
if (src_tRNS)
|
||||
{
|
||||
io.set_tRNS_to_alpha();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_READ_FILLER_SUPPORTED) && !defined(PNG_1_0_X)
|
||||
io.set_add_alpha(filler, filler_after);
|
||||
#else
|
||||
throw error("expected alpha channel but none found;"
|
||||
" recompile with PNG_READ_FILLER_SUPPORTED"
|
||||
" and be sure to use libpng > 1.0.x");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
template< class reader >
|
||||
static void handle_palette(reader& io)
|
||||
{
|
||||
if (io.get_color_type() == color_type_palette)
|
||||
{
|
||||
#ifdef PNG_READ_EXPAND_SUPPORTED
|
||||
io.set_palette_to_rgb();
|
||||
|
||||
if (traits::get_color_type() != color_type_palette)
|
||||
{
|
||||
io.get_info().drop_palette();
|
||||
}
|
||||
#else
|
||||
throw error("indexed colors unexpected;"
|
||||
" recompile with PNG_READ_EXPAND_SUPPORTED");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
template< class reader >
|
||||
static void handle_rgb(reader& io)
|
||||
{
|
||||
bool src_rgb =
|
||||
io.get_color_type() & (color_mask_rgb | color_mask_palette);
|
||||
bool dst_rgb = traits::get_color_type() & color_mask_rgb;
|
||||
if (src_rgb && !dst_rgb)
|
||||
{
|
||||
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
|
||||
io.set_rgb_to_gray(/*rgb_to_gray_error*/);
|
||||
#else
|
||||
throw error("grayscale data expected;"
|
||||
" recompile with"
|
||||
" PNG_READ_RGB_TO_GRAY_SUPPORTED");
|
||||
#endif
|
||||
}
|
||||
if (!src_rgb && dst_rgb)
|
||||
{
|
||||
#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
|
||||
io.set_gray_to_rgb();
|
||||
#else
|
||||
throw error("expected RGB data;"
|
||||
" recompile with"
|
||||
" PNG_READ_GRAY_TO_RGB_SUPPORTED");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
template< class reader >
|
||||
static void handle_gray(reader& io)
|
||||
{
|
||||
if ((io.get_color_type() & ~color_mask_alpha)
|
||||
== color_type_gray)
|
||||
{
|
||||
if (io.get_bit_depth() < 8 && traits::get_bit_depth() >= 8)
|
||||
{
|
||||
#ifdef PNG_READ_EXPAND_SUPPORTED
|
||||
io.set_gray_1_2_4_to_8();
|
||||
#else
|
||||
throw error("convert_color_space: expected 8-bit data;"
|
||||
" recompile with"
|
||||
" PNG_READ_EXPAND_SUPPORTED");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detal
|
||||
|
||||
/**
|
||||
* \brief IO transformation class template. Converts %image %color
|
||||
* space.
|
||||
*
|
||||
* This IO transformation class template is used to convert %color
|
||||
* space of the source %image to the %color space of the target
|
||||
* %image. An error with human-readable description is thrown
|
||||
* when the %color space could not be converted. Often, this
|
||||
* means that you have to recompile libpng with some more
|
||||
* conversion options turned on.
|
||||
*
|
||||
* Not implemented--see specializations.
|
||||
*
|
||||
* \see image, image::read
|
||||
*/
|
||||
template< typename pixel >
|
||||
struct convert_color_space
|
||||
{
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Converts %image %color space. A specialization for
|
||||
* rgb_pixel type.
|
||||
*/
|
||||
template<>
|
||||
struct convert_color_space< rgb_pixel >
|
||||
: detail::convert_color_space_impl< rgb_pixel >
|
||||
{
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Converts %image %color space. A specialization for
|
||||
* rgb_pixel_16 type.
|
||||
*/
|
||||
template<>
|
||||
struct convert_color_space< rgb_pixel_16 >
|
||||
: detail::convert_color_space_impl< rgb_pixel_16 >
|
||||
{
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Converts %image %color space. A specialization for
|
||||
* rgba_pixel type.
|
||||
*/
|
||||
template<>
|
||||
struct convert_color_space< rgba_pixel >
|
||||
: detail::convert_color_space_impl< rgba_pixel >
|
||||
{
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Converts %image %color space. A specialization for
|
||||
* rgba_pixel_16 type.
|
||||
*/
|
||||
template<>
|
||||
struct convert_color_space< rgba_pixel_16 >
|
||||
: detail::convert_color_space_impl< rgba_pixel_16 >
|
||||
{
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Converts %image %color space. A specialization for
|
||||
* gray_pixel type.
|
||||
*/
|
||||
template<>
|
||||
struct convert_color_space< gray_pixel >
|
||||
: detail::convert_color_space_impl< gray_pixel >
|
||||
{
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Converts %image %color space. A specialization for
|
||||
* gray_pixel_16 type.
|
||||
*/
|
||||
template<>
|
||||
struct convert_color_space< gray_pixel_16 >
|
||||
: detail::convert_color_space_impl< gray_pixel_16 >
|
||||
{
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Converts %image %color space. A specialization for
|
||||
* ga_pixel type.
|
||||
*/
|
||||
template<>
|
||||
struct convert_color_space< ga_pixel >
|
||||
: detail::convert_color_space_impl< ga_pixel >
|
||||
{
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Converts %image %color space. A specialization for
|
||||
* ga_pixel_16 type.
|
||||
*/
|
||||
template<>
|
||||
struct convert_color_space< ga_pixel_16 >
|
||||
: detail::convert_color_space_impl< ga_pixel_16 >
|
||||
{
|
||||
};
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_CONVERT_COLOR_SPACE_HPP_INCLUDED
|
436
src/png++-0.2.5/dbf_api.html
Normal file
@ -0,0 +1,436 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Attribute (.DBF) API</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Attribute (.DBF) API</h1>
|
||||
|
||||
The Attribute (DBF) API uses DBFHandle to represent a handle for access
|
||||
to one .dbf file. The contents of the DBFHandle are visible (see shapefil.h)
|
||||
but should be ignored by the application. It is intended that all information
|
||||
be accessed by API functions. Note that there should be exactly one record
|
||||
in the .dbf file for each shape in the .shp/.shx files. This constraint
|
||||
must be maintained by the application.<p>
|
||||
|
||||
<!-------------------------------------------------------------------------->
|
||||
|
||||
<h2>DBFOpen()</h2>
|
||||
|
||||
<pre>
|
||||
DBFHandle DBFOpen( const char * pszDBFFile, const char * pszAccess );
|
||||
|
||||
pszDBFFile: The name of the xBase (.dbf) file to access.
|
||||
|
||||
pszAccess: The fopen() style access string. At this time only
|
||||
"rb" (read-only binary) and "rb+" (read/write binary)
|
||||
should be used.
|
||||
</pre>
|
||||
|
||||
The DBFOpen() function should be used to establish access to an existing
|
||||
xBase format table file. The returned DBFHandle is passed to other
|
||||
access functions, and DBFClose() should be invoked to recover resources, and
|
||||
flush changes to disk when complete. The DBFCreate() function should
|
||||
called to create new xBase files. As a convenience, DBFOpen() can be
|
||||
called with the name of a .shp or .shx file, and it will figure out the
|
||||
name of the related .dbf file.<p>
|
||||
|
||||
<!-------------------------------------------------------------------------->
|
||||
|
||||
<h2>DBFCreate()</h2>
|
||||
|
||||
<pre>
|
||||
DBFHandle DBFCreate( const char * pszDBFFile );
|
||||
|
||||
pszDBFFile: The name of the xBase (.dbf) file to create.
|
||||
</pre>
|
||||
|
||||
The DBFCreate() function creates a new xBase format file with the given
|
||||
name, and returns an access handle that can be used with other DBF functions.
|
||||
The newly created file will have no fields, and no records. Fields should
|
||||
be added with DBFAddField() before any records add written.
|
||||
|
||||
<!-------------------------------------------------------------------------->
|
||||
|
||||
<h2>DBFGetFieldCount()</h2>
|
||||
|
||||
<pre>
|
||||
int DBFGetFieldCount( DBFHandle hDBF );
|
||||
|
||||
hDBF: The access handle for the file to be queried, as returned
|
||||
by DBFOpen(), or DBFCreate().
|
||||
</pre>
|
||||
|
||||
The DBFGetFieldCount() function returns the number of fields currently
|
||||
defined for the indicated xBase file.
|
||||
|
||||
<!-------------------------------------------------------------------------->
|
||||
|
||||
<h2>DBFGetRecordCount()</h2>
|
||||
|
||||
<pre>
|
||||
int DBFGetRecordCount( DBFHandle hDBF );
|
||||
|
||||
hDBF: The access handle for the file to be queried, as returned by
|
||||
DBFOpen(), or DBFCreate().
|
||||
</pre>
|
||||
|
||||
The DBFGetRecordCount() function returns the number of records that
|
||||
exist on the xBase file currently. Note that with shape files one xBase
|
||||
record exists for each shape in the .shp/.shx files.<p>
|
||||
|
||||
<!-------------------------------------------------------------------------->
|
||||
|
||||
<h2>DBFGetFieldIndex()</h2>
|
||||
|
||||
<pre>
|
||||
int DBFGetFieldIndex( DBFHandle hDBF, const char *pszFieldName );
|
||||
|
||||
hDBF: The access handle for the file to be queried, as returned by
|
||||
DBFOpen(), or DBFCreate().
|
||||
|
||||
pszFieldName: Name of the field to search for.
|
||||
</pre>
|
||||
|
||||
Returns the index of the field matching this name, or -1 on failure. The
|
||||
comparison is case insensitive. However, lengths must match exactly.<p>
|
||||
|
||||
<!-------------------------------------------------------------------------->
|
||||
|
||||
<h2>DBFGetFieldInfo()</h2>
|
||||
|
||||
<pre>
|
||||
DBFFieldType DBFGetFieldInfo( DBFHandle hDBF, int iField, char * pszFieldName,
|
||||
int * pnWidth, int * pnDecimals );
|
||||
|
||||
hDBF: The access handle for the file to be queried, as returned by
|
||||
DBFOpen(), or DBFCreate().
|
||||
|
||||
iField: The field to be queried. This should be a number between
|
||||
0 and n-1, where n is the number fields on the file, as
|
||||
returned by DBFGetFieldCount().
|
||||
|
||||
pszFieldName: If this pointer is not NULL the name of the requested field
|
||||
will be written to this location. The pszFieldName buffer
|
||||
should be at least 12 character is size in order to hold
|
||||
the longest possible field name of 11 characters plus a
|
||||
terminating zero character.
|
||||
|
||||
pnWidth: If this pointer is not NULL, the width of the requested field
|
||||
will be returned in the int pointed to by pnWidth. This is
|
||||
the width in characters.
|
||||
|
||||
pnDecimals: If this pointer is not NULL, the number of decimal places
|
||||
precision defined for the field will be returned. This is
|
||||
zero for integer fields, or non-numeric fields.
|
||||
</pre>
|
||||
|
||||
The DBFGetFieldInfo() returns the type of the requested field, which is
|
||||
one of the DBFFieldType enumerated values. As well, the field name, and
|
||||
field width information can optionally be returned. The field type returned
|
||||
does not correspond one to one with the xBase field types. For instance
|
||||
the xBase field type for Date will just be returned as being FTInteger. <p>
|
||||
|
||||
<pre>
|
||||
typedef enum {
|
||||
FTString, /* fixed length string field */
|
||||
FTInteger, /* numeric field with no decimals */
|
||||
FTDouble, /* numeric field with decimals */
|
||||
FTLogical, /* logical field. */
|
||||
FTInvalid /* not a recognised field type */
|
||||
} DBFFieldType;
|
||||
</pre>
|
||||
|
||||
<!-------------------------------------------------------------------------->
|
||||
|
||||
<h2>DBFAddField()</h2>
|
||||
|
||||
<pre>
|
||||
int DBFAddField( DBFHandle hDBF, const char * pszFieldName,
|
||||
DBFFieldType eType, int nWidth, int nDecimals );
|
||||
|
||||
hDBF: The access handle for the file to be updated, as returned by
|
||||
DBFOpen(), or DBFCreate().
|
||||
|
||||
pszFieldName: The name of the new field. At most 11 character will be used.
|
||||
In order to use the xBase file in some packages it may be
|
||||
necessary to avoid some special characters in the field names
|
||||
such as spaces, or arithmetic operators.
|
||||
|
||||
eType: One of FTString, FTInteger or FTDouble in order to establish
|
||||
the type of the new field. Note that some valid xBase field
|
||||
types cannot be created such as date fields.
|
||||
|
||||
nWidth: The width of the field to be created. For FTString fields this
|
||||
establishes the maximum length of string that can be stored.
|
||||
For FTInteger this establishes the number of digits of the
|
||||
largest number that can
|
||||
be represented. For FTDouble fields this in combination
|
||||
with the nDecimals value establish the size, and precision
|
||||
of the created field.
|
||||
|
||||
nDecimals: The number of decimal places to reserve for FTDouble fields.
|
||||
For all other field types this should be zero. For instance
|
||||
with nWidth=7, and nDecimals=3 numbers would be formatted
|
||||
similarly to `123.456'.
|
||||
</pre>
|
||||
|
||||
The DBFAddField() function is used to add new fields to an existing xBase
|
||||
file opened with DBFOpen(), or created with DBFCreate(). Note that fields
|
||||
can only be added to xBase files with no records, though this is limitation
|
||||
of this API, not of the file format.<p>
|
||||
|
||||
The DBFAddField() return value is the field number of the new field, or
|
||||
-1 if the addition of the field failed.<p>
|
||||
|
||||
<!-------------------------------------------------------------------------->
|
||||
|
||||
<h2>DBFReadIntegerAttribute()</h2>
|
||||
|
||||
<pre>
|
||||
int DBFReadIntegerAttribute( DBFHandle hDBF, int iShape, int iField );
|
||||
|
||||
hDBF: The access handle for the file to be queried, as returned by
|
||||
DBFOpen(), or DBFCreate().
|
||||
|
||||
iShape: The record number (shape number) from which the field value
|
||||
should be read.
|
||||
|
||||
iField: The field within the selected record that should be read.
|
||||
</pre>
|
||||
|
||||
The DBFReadIntegerAttribute() will read the value of one field and return
|
||||
it as an integer. This can be used even with FTString fields, though the
|
||||
returned value will be zero if not interpretable as a number.<p>
|
||||
|
||||
<!-------------------------------------------------------------------------->
|
||||
|
||||
<h2>DBFReadDoubleAttribute()</h2>
|
||||
|
||||
<pre>
|
||||
double DBFReadDoubleAttribute( DBFHandle hDBF, int iShape, int iField );
|
||||
|
||||
hDBF: The access handle for the file to be queried, as returned by
|
||||
DBFOpen(), or DBFCreate().
|
||||
|
||||
iShape: The record number (shape number) from which the field value
|
||||
should be read.
|
||||
|
||||
iField: The field within the selected record that should be read.
|
||||
</pre>
|
||||
|
||||
The DBFReadDoubleAttribute() will read the value of one field and return
|
||||
it as a double. This can be used even with FTString fields, though the
|
||||
returned value will be zero if not interpretable as a number.<p>
|
||||
|
||||
<!-------------------------------------------------------------------------->
|
||||
|
||||
<h2>DBFReadStringAttribute()</h2>
|
||||
|
||||
<pre>
|
||||
const char *DBFReadStringAttribute( DBFHandle hDBF, int iShape, int iField );
|
||||
|
||||
hDBF: The access handle for the file to be queried, as returned by
|
||||
DBFOpen(), or DBFCreate().
|
||||
|
||||
iShape: The record number (shape number) from which the field value
|
||||
should be read.
|
||||
|
||||
iField: The field within the selected record that should be read.
|
||||
</pre>
|
||||
|
||||
The DBFReadStringAttribute() will read the value of one field and return
|
||||
it as a string. This function may be used on any field type (including
|
||||
FTInteger and FTDouble) and will return the string representation stored
|
||||
in the .dbf file. The returned pointer is to an internal buffer
|
||||
which is only valid untill the next DBF function call. It's contents may
|
||||
be copied with normal string functions such as strcpy(), or strdup(). If
|
||||
the TRIM_DBF_WHITESPACE macro is defined in shapefil.h (it is by default)
|
||||
then all leading and trailing space (ASCII 32) characters will be stripped
|
||||
before the string is returned.<p>
|
||||
|
||||
<!-------------------------------------------------------------------------->
|
||||
|
||||
<h2>DBFIsAttributeNULL()</h2>
|
||||
|
||||
<pre>
|
||||
int DBFIsAttributeNULL( DBFHandle hDBF, int iShape, int iField );
|
||||
|
||||
hDBF: The access handle for the file to be queried, as returned by
|
||||
DBFOpen(), or DBFCreate().
|
||||
|
||||
iShape: The record number (shape number) from which the field value
|
||||
should be read.
|
||||
|
||||
iField: The field within the selected record that should be read.
|
||||
</pre>
|
||||
|
||||
This function will return TRUE if the indicated field is NULL valued
|
||||
otherwise FALSE. Note that NULL fields are represented in the .dbf file
|
||||
as having all spaces in the field. Reading NULL fields will result in
|
||||
a value of 0.0 or an empty string with the other DBFRead*Attribute()
|
||||
functions.<p>
|
||||
|
||||
<!-------------------------------------------------------------------------->
|
||||
|
||||
<h2>DBFWriteIntegerAttribute</h2>
|
||||
|
||||
<pre>
|
||||
int DBFWriteIntegerAttribute( DBFHandle hDBF, int iShape, int iField,
|
||||
int nFieldValue );
|
||||
|
||||
hDBF: The access handle for the file to be written, as returned by
|
||||
DBFOpen(), or DBFCreate().
|
||||
|
||||
iShape: The record number (shape number) to which the field value
|
||||
should be written.
|
||||
|
||||
iField: The field within the selected record that should be written.
|
||||
|
||||
nFieldValue: The integer value that should be written.
|
||||
</pre>
|
||||
|
||||
The DBFWriteIntegerAttribute() function is used to write a value to a numeric
|
||||
field (FTInteger, or FTDouble). If the write succeeds the value TRUE will
|
||||
be returned, otherwise FALSE will be returned. If the value is too large to
|
||||
fit in the field, it will be truncated and FALSE returned.<p>
|
||||
|
||||
<!-------------------------------------------------------------------------->
|
||||
|
||||
<h2>DBFWriteDoubleAttribute()</h2>
|
||||
|
||||
<pre>
|
||||
int DBFWriteDoubleAttribute( DBFHandle hDBF, int iShape, int iField,
|
||||
double dFieldValue );
|
||||
|
||||
hDBF: The access handle for the file to be written, as returned by
|
||||
DBFOpen(), or DBFCreate().
|
||||
|
||||
iShape: The record number (shape number) to which the field value
|
||||
should be written.
|
||||
|
||||
iField: The field within the selected record that should be written.
|
||||
|
||||
dFieldValue: The floating point value that should be written.
|
||||
</pre>
|
||||
|
||||
The DBFWriteDoubleAttribute() function is used to write a value to a numeric
|
||||
field (FTInteger, or FTDouble). If the write succeeds the value TRUE will
|
||||
be returned, otherwise FALSE will be returned. If the value is too large to
|
||||
fit in the field, it will be truncated and FALSE returned.<p>
|
||||
|
||||
<!-------------------------------------------------------------------------->
|
||||
|
||||
<h2>DBFWriteStringAttribute()</h2>
|
||||
|
||||
<pre>
|
||||
int DBFWriteStringAttribute( DBFHandle hDBF, int iShape, int iField,
|
||||
const char * pszFieldValue );
|
||||
|
||||
hDBF: The access handle for the file to be written, as returned by
|
||||
DBFOpen(), or DBFCreate().
|
||||
|
||||
iShape: The record number (shape number) to which the field value
|
||||
should be written.
|
||||
|
||||
iField: The field within the selected record that should be written.
|
||||
|
||||
pszFieldValue: The string to be written to the field.
|
||||
</pre>
|
||||
|
||||
The DBFWriteStringAttribute() function is used to write a value to a string
|
||||
field (FString). If the write succeeds the value TRUE willbe returned,
|
||||
otherwise FALSE will be returned. If the value is too large to
|
||||
fit in the field, it will be truncated and FALSE returned.<p>
|
||||
|
||||
<!-------------------------------------------------------------------------->
|
||||
|
||||
<h2>DBFWriteNULLAttribute()</h2>
|
||||
|
||||
<pre>
|
||||
int DBFWriteNULLAttribute( DBFHandle hDBF, int iShape, int iField );
|
||||
|
||||
hDBF: The access handle for the file to be written, as returned by
|
||||
DBFOpen(), or DBFCreate().
|
||||
|
||||
iShape: The record number (shape number) to which the field value
|
||||
should be written.
|
||||
|
||||
iField: The field within the selected record that should be written.
|
||||
</pre>
|
||||
|
||||
The DBFWriteNULLAttribute() function is used to clear the indicated field
|
||||
to a NULL value. In the .dbf file this is represented by setting the entire
|
||||
field to spaces. If the write succeeds the value TRUE willbe returned,
|
||||
otherwise FALSE will be returned.<p>
|
||||
|
||||
<!-------------------------------------------------------------------------->
|
||||
|
||||
<h2>DBFClose()</h2>
|
||||
|
||||
<pre>
|
||||
void DBFClose( DBFHandle hDBF );
|
||||
|
||||
hDBF: The access handle for the file to be closed.
|
||||
</pre>
|
||||
|
||||
The DBFClose() function will close the indicated xBase file (opened with
|
||||
DBFOpen(), or DBFCreate()), flushing out all information to the file on
|
||||
disk, and recovering any resources associated with having the file open.
|
||||
The file handle (hDBF) should not be used again with the DBF API after
|
||||
calling DBFClose().<p>
|
||||
|
||||
<!-------------------------------------------------------------------------->
|
||||
|
||||
<h2>DBFIsRecordDeleted()</h2>
|
||||
|
||||
<pre>
|
||||
int DBFIsRecordDeleted( DBFHandle hDBF, int iShape );
|
||||
|
||||
hDBF: The access handle for the file to be checked.
|
||||
iShape: The record index to check.
|
||||
</pre>
|
||||
|
||||
Returns TRUE (non-zero) if the record is marked for deletion, otherwise
|
||||
it returns FALSE.<p>
|
||||
|
||||
<!-------------------------------------------------------------------------->
|
||||
|
||||
<h2>DBFMarkRecordDeleted()</h2>
|
||||
|
||||
<pre>
|
||||
int DBFMarkRecordDeleted( DBFHandle hDBF, int iShape, int bIsDeleted );
|
||||
|
||||
hDBF: The access handle for the file.
|
||||
iShape: The record index to update.
|
||||
bIsDeleted: TRUE to mark record deleted, or FALSE to undelete it.
|
||||
</pre>
|
||||
|
||||
Returns TRUE on success, or FALSE on error.<p>
|
||||
|
||||
<!-------------------------------------------------------------------------->
|
||||
|
||||
<h2>DBFGetNativeFieldType()</h2>
|
||||
|
||||
<pre>
|
||||
char DBFGetNativeFieldType( DBFHandle hDBF, int iField );
|
||||
|
||||
hDBF: The access handle for the file.
|
||||
iField: The field index to query.
|
||||
|
||||
</pre>
|
||||
|
||||
This function returns the DBF type code of the indicated field. It will
|
||||
be one of:<p>
|
||||
|
||||
<ul>
|
||||
<li> 'C' (String)
|
||||
<li> 'D' (Date)
|
||||
<li> 'F' (Float)
|
||||
<li> 'N' (Numeric, with or without decimal)
|
||||
<li> 'L' (Logical)
|
||||
<li> 'M' (Memo: 10 digits .DBT block ptr)
|
||||
<li> ' ' (field out of range)
|
||||
</ul>
|
||||
|
||||
</body>
|
||||
</html>
|
74
src/png++-0.2.5/end_info.hpp
Normal file
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
#ifndef PNGPP_END_INFO_HPP_INCLUDED
|
||||
#define PNGPP_END_INFO_HPP_INCLUDED
|
||||
|
||||
#include "info_base.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief Internal class to hold PNG ending %info.
|
||||
*
|
||||
* \see info, info_base
|
||||
*/
|
||||
class end_info
|
||||
: public info_base
|
||||
{
|
||||
public:
|
||||
end_info(io_base& io, png_struct* png)
|
||||
: info_base(io, png)
|
||||
{
|
||||
}
|
||||
|
||||
void destroy()
|
||||
{
|
||||
assert(m_info);
|
||||
png_destroy_info_struct(m_png, & m_info);
|
||||
}
|
||||
|
||||
void read()
|
||||
{
|
||||
png_read_end(m_png, m_info);
|
||||
}
|
||||
|
||||
void write() const
|
||||
{
|
||||
png_write_end(m_png, m_info);
|
||||
}
|
||||
|
||||
// TODO: add methods to read/write text comments etc.
|
||||
};
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_END_INFO_HPP_INCLUDED
|
84
src/png++-0.2.5/error.hpp
Normal file
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
#ifndef PNGPP_ERROR_HPP_INCLUDED
|
||||
#define PNGPP_ERROR_HPP_INCLUDED
|
||||
|
||||
#include <stdexcept>
|
||||
#include <cerrno>
|
||||
#include <cstdlib>
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief Exception class to represent runtime errors related to
|
||||
* png++ operation.
|
||||
*/
|
||||
class error
|
||||
: public std::runtime_error
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* \param message error description
|
||||
*/
|
||||
explicit error(std::string const& message)
|
||||
: std::runtime_error(message)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Exception class to represent standard library errors
|
||||
* (generally IO).
|
||||
*
|
||||
* \see reader, writer
|
||||
*/
|
||||
class std_error
|
||||
: public std::runtime_error
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructs an std_error object. The \a message string is
|
||||
* appended with <tt>": "</tt> and the error description as
|
||||
* returned by \c strerror(\a error).
|
||||
*
|
||||
* \param message error description
|
||||
* \param error error number
|
||||
*/
|
||||
explicit std_error(std::string const& message, int error = errno)
|
||||
: std::runtime_error((message + ": ") + strerror(error))
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_ERROR_HPP_INCLUDED
|
82
src/png++-0.2.5/example/Makefile
Normal file
@ -0,0 +1,82 @@
|
||||
#
|
||||
# Copyright (C) 2007,2008 Alex Shulgin
|
||||
#
|
||||
# This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
# software; the exact copying conditions are as follows:
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 3. The name of the author may not be used to endorse or promote products
|
||||
# derived from this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
#
|
||||
ifndef PREFIX
|
||||
PREFIX := /usr/local
|
||||
endif
|
||||
|
||||
ifndef PNGPP
|
||||
PNGPP := ..
|
||||
endif
|
||||
|
||||
make_cflags := -Wall $(CFLAGS) -I$(PREFIX)/include -I$(PNGPP)
|
||||
make_ldflags := $(LDFLAGS) -L$(PREFIX)/lib
|
||||
|
||||
ifndef NDEBUG
|
||||
make_cflags := $(make_cflags) -g
|
||||
make_ldflags := $(make_ldflags) -g
|
||||
endif
|
||||
|
||||
ifndef LIBPNG_CONFIG
|
||||
LIBPNG_CONFIG := libpng-config
|
||||
endif
|
||||
|
||||
sources := pixel_generator.cpp
|
||||
|
||||
deps := $(sources:.cpp=.dep)
|
||||
objects := $(sources:.cpp=.o)
|
||||
targets := $(sources:.cpp=$(bin_suffix))
|
||||
|
||||
all: $(deps) $(targets)
|
||||
|
||||
dist-copy-files:
|
||||
mkdir $(dist_dir)/example
|
||||
cp $(sources) Makefile $(dist_dir)/example
|
||||
|
||||
clean: clean-deps
|
||||
rm -f $(targets) $(objects)
|
||||
|
||||
.PHONY: all dist-copy-files clean clean-deps
|
||||
|
||||
%$(bin_suffix): %.o
|
||||
g++ -o $@ $< $(make_ldflags) `$(LIBPNG_CONFIG) --ldflags`
|
||||
|
||||
%.o: %.cpp
|
||||
g++ -c -o $@ $< $(make_cflags) `$(LIBPNG_CONFIG) --cflags`
|
||||
|
||||
|
||||
%.dep: %.cpp
|
||||
g++ -M $(CPPFLAGS) $(make_cflags) $< -o- | \
|
||||
sed 's/\($*\)\.o[ :]*/\1.o $@ : /g' > $@
|
||||
|
||||
clean-deps:
|
||||
rm -f $(deps)
|
||||
|
||||
include $(deps)
|
82
src/png++-0.2.5/example/pixel_generator.cpp
Normal file
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
|
||||
#include <png.hpp>
|
||||
|
||||
class pixel_generator
|
||||
: public png::generator< png::gray_pixel_1, pixel_generator >
|
||||
{
|
||||
public:
|
||||
pixel_generator(size_t width, size_t height)
|
||||
: png::generator< png::gray_pixel_1, pixel_generator >(width, height),
|
||||
m_row(width)
|
||||
{
|
||||
for (size_t i = 0; i < m_row.size(); ++i)
|
||||
{
|
||||
m_row[i] = i > m_row.size() / 2 ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
png::byte* get_next_row(size_t /*pos*/)
|
||||
{
|
||||
size_t i = std::rand() % m_row.size();
|
||||
size_t j = std::rand() % m_row.size();
|
||||
png::gray_pixel_1 t = m_row[i];
|
||||
m_row[i] = m_row[j];
|
||||
m_row[j] = t;
|
||||
return reinterpret_cast< png::byte* >(row_traits::get_data(m_row));
|
||||
}
|
||||
|
||||
private:
|
||||
typedef png::packed_pixel_row< png::gray_pixel_1 > row;
|
||||
typedef png::row_traits< row > row_traits;
|
||||
row m_row;
|
||||
};
|
||||
|
||||
int
|
||||
main()
|
||||
try
|
||||
{
|
||||
size_t const width = 32;
|
||||
size_t const height = 512;
|
||||
|
||||
std::ofstream file("generated.png", std::ios::binary);
|
||||
pixel_generator generator(width, height);
|
||||
generator.write(file);
|
||||
}
|
||||
catch (std::exception const& error)
|
||||
{
|
||||
std::cerr << "pixel_generator: " << error.what() << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
86
src/png++-0.2.5/ga_pixel.hpp
Normal file
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
#ifndef PNGPP_GA_PIXEL_HPP_INCLUDED
|
||||
#define PNGPP_GA_PIXEL_HPP_INCLUDED
|
||||
|
||||
#include <limits>
|
||||
|
||||
#include "types.hpp"
|
||||
#include "pixel_traits.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief Basic Gray+Alpha pixel type.
|
||||
*/
|
||||
template< typename T >
|
||||
struct basic_ga_pixel
|
||||
{
|
||||
typedef pixel_traits< basic_ga_pixel< T > > traits;
|
||||
|
||||
/**
|
||||
* \brief Constructs basic_ga_pixel object from \a value and
|
||||
* \a alpha components passed as parameters. Alpha defaults
|
||||
* to full opacity.
|
||||
*/
|
||||
basic_ga_pixel(T value = 0, T alpha = traits::get_alpha_filler())
|
||||
: value(value), alpha(alpha)
|
||||
{
|
||||
}
|
||||
|
||||
T value;
|
||||
T alpha;
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief The 8-bit Gray+Alpha pixel type.
|
||||
*/
|
||||
typedef basic_ga_pixel< byte > ga_pixel;
|
||||
|
||||
/**
|
||||
* \brief The 16-bit Gray+Alpha pixel type.
|
||||
*/
|
||||
typedef basic_ga_pixel< uint_16 > ga_pixel_16;
|
||||
|
||||
/**
|
||||
* \brief Pixel traits specialization for basic_ga_pixel.
|
||||
*/
|
||||
template< typename T >
|
||||
struct pixel_traits< basic_ga_pixel< T > >
|
||||
: basic_pixel_traits< basic_ga_pixel< T >, T, color_type_ga >,
|
||||
basic_alpha_pixel_traits< T >
|
||||
{
|
||||
};
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_GA_PIXEL_HPP_INCLUDED
|
207
src/png++-0.2.5/generator.hpp
Normal file
@ -0,0 +1,207 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
#ifndef PNGPP_GENERATOR_HPP_INCLUDED
|
||||
#define PNGPP_GENERATOR_HPP_INCLUDED
|
||||
|
||||
#include <cassert>
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "error.hpp"
|
||||
#include "streaming_base.hpp"
|
||||
#include "writer.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief Pixel generator class template.
|
||||
*
|
||||
* Used as a base class for custom pixel generator classes as well
|
||||
* as inside image class implementation to write pixels from the
|
||||
* pixel buffer.
|
||||
*
|
||||
* A usage example can be found in \c example/pixel_generator.cpp.
|
||||
*
|
||||
* Encapsulates PNG %image writing procedure. In order to create
|
||||
* a custom pixel %generator use CRTP trick:
|
||||
*
|
||||
* \code
|
||||
* class pixel_generator
|
||||
* : public png::generator< pixel, pixel_generator >
|
||||
* {
|
||||
* ...
|
||||
* };
|
||||
* \endcode
|
||||
*
|
||||
* Your pixel %generator class should implement \c get_next_row()
|
||||
* method and \c reset() method (optional). Their signatures are
|
||||
* as follows:
|
||||
*
|
||||
* \code
|
||||
* png::byte* get_next_row(size_t pos);
|
||||
* void reset(size_t pass);
|
||||
* \endcode
|
||||
*
|
||||
* The \c get_next_row() method is called every time a new row of
|
||||
* %image data is needed by the writer. The position of the row
|
||||
* being written is passed as \c pos parameter. The \c pos takes
|
||||
* values from \c 0 to \c <image_height>-1 inclusively. The
|
||||
* method should return the starting address of a row buffer
|
||||
* storing an appropriate amount of pixels (i.e. the width of the
|
||||
* %image being written). The address should be casted to
|
||||
* png::byte* pointer type using \c reinterpret_cast<> or a
|
||||
* C-style cast.
|
||||
*
|
||||
* The optional \c reset() method is called every time the new
|
||||
* pass of interlaced %image processing starts. The number of
|
||||
* interlace pass is avaiable as the only parameter of the method.
|
||||
* For non-interlaced images the method is called once prior to
|
||||
* any calls to \c get_next_row(). The value of \c 0 is passed
|
||||
* for the \c pass number. You do not have to implement this
|
||||
* method unless you are going to support interlaced %image
|
||||
* generation.
|
||||
*
|
||||
* An optional template parameter \c info_holder encapsulated
|
||||
* image_info storage policy. Please refer to consumer class
|
||||
* documentation for the detailed description of this parameter.
|
||||
*
|
||||
* An optional \c bool template parameter \c interlacing_supported
|
||||
* specifies whether writing interlacing images is supported by
|
||||
* your %generator class. It defaults to \c false. An attempt to
|
||||
* write an interlaced %image will result in throwing
|
||||
* \c std::logic_error.
|
||||
*
|
||||
* In order to fully support interlacing specify \c true for \c
|
||||
* interlacing_supported parameter and implement \c reset()
|
||||
* method. You _must_ generate the same pixels for every pass to
|
||||
* get the correct PNG %image output.
|
||||
*
|
||||
* \see image, consumer
|
||||
*/
|
||||
template< typename pixel,
|
||||
class pixgen,
|
||||
class info_holder = def_image_info_holder,
|
||||
bool interlacing_supported = false >
|
||||
class generator
|
||||
: public streaming_base< pixel, info_holder >
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* \brief Writes an image to the stream.
|
||||
*
|
||||
* Essentially, this method constructs a writer object and
|
||||
* instructs it to write the image to the stream. It handles
|
||||
* writing interlaced images as long as your generator class
|
||||
* supports this.
|
||||
*/
|
||||
template< typename ostream >
|
||||
void write(ostream& stream)
|
||||
{
|
||||
writer< ostream > wr(stream);
|
||||
wr.set_image_info(this->get_info());
|
||||
wr.write_info();
|
||||
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
if (pixel_traits< pixel >::get_bit_depth() == 16)
|
||||
{
|
||||
#ifdef PNG_WRITE_SWAP_SUPPORTED
|
||||
wr.set_swap();
|
||||
#else
|
||||
throw error("Cannot write 16-bit image:"
|
||||
" recompile with PNG_WRITE_SWAP_SUPPORTED.");
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
size_t pass_count;
|
||||
if (this->get_info().get_interlace_type() != interlace_none)
|
||||
{
|
||||
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
|
||||
if (interlacing_supported)
|
||||
{
|
||||
pass_count = wr.set_interlace_handling();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::logic_error("Cannot write interlaced image:"
|
||||
" generator does not support it.");
|
||||
}
|
||||
#else
|
||||
throw error("Cannot write interlaced image:"
|
||||
" interlace handling disabled.");
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
pass_count = 1;
|
||||
}
|
||||
pixgen* pixel_gen = static_cast< pixgen* >(this);
|
||||
for (size_t pass = 0; pass < pass_count; ++pass)
|
||||
{
|
||||
pixel_gen->reset(pass);
|
||||
|
||||
for (size_t pos = 0; pos < this->get_info().get_height(); ++pos)
|
||||
{
|
||||
wr.write_row(pixel_gen->get_next_row(pos));
|
||||
}
|
||||
}
|
||||
|
||||
wr.write_end_info();
|
||||
}
|
||||
|
||||
protected:
|
||||
typedef streaming_base< pixel, info_holder > base;
|
||||
|
||||
/**
|
||||
* \brief Constructs a generator object using passed image_info
|
||||
* object to store image information.
|
||||
*/
|
||||
explicit generator(image_info& info)
|
||||
: base(info)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Constructs a generator object prepared to generate
|
||||
* an image of specified width and height.
|
||||
*/
|
||||
generator(size_t width, size_t height)
|
||||
: base(width, height)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_GENERATOR_HPP_INCLUDED
|
111
src/png++-0.2.5/gray_pixel.hpp
Normal file
@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
#ifndef PNGPP_GRAY_PIXEL_HPP_INCLUDED
|
||||
#define PNGPP_GRAY_PIXEL_HPP_INCLUDED
|
||||
|
||||
#include "types.hpp"
|
||||
#include "packed_pixel.hpp"
|
||||
#include "pixel_traits.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief The 8-bit Grayscale pixel type.
|
||||
*/
|
||||
typedef byte gray_pixel;
|
||||
|
||||
/**
|
||||
* \brief The 16-bit Grayscale pixel type.
|
||||
*/
|
||||
typedef uint_16 gray_pixel_16;
|
||||
|
||||
/**
|
||||
* \brief The packed gray pixel class template. The available
|
||||
* specializations are for 1-, 2- and 4-bit pixels.
|
||||
*/
|
||||
template< size_t bits >
|
||||
class packed_gray_pixel
|
||||
: public packed_pixel< bits >
|
||||
{
|
||||
public:
|
||||
packed_gray_pixel(byte value = 0)
|
||||
: packed_pixel< bits >(value)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief The 1-bit Grayscale pixel type.
|
||||
*/
|
||||
typedef packed_gray_pixel< 1 > gray_pixel_1;
|
||||
|
||||
/**
|
||||
* \brief The 2-bit Grayscale pixel type.
|
||||
*/
|
||||
typedef packed_gray_pixel< 2 > gray_pixel_2;
|
||||
|
||||
/**
|
||||
* \brief The 4-bit Grayscale pixel type.
|
||||
*/
|
||||
typedef packed_gray_pixel< 4 > gray_pixel_4;
|
||||
|
||||
/**
|
||||
* \brief Pixel traits specialization for gray_pixel.
|
||||
*/
|
||||
template<>
|
||||
struct pixel_traits< gray_pixel >
|
||||
: basic_pixel_traits< gray_pixel, byte, color_type_gray >
|
||||
{
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Pixel traits specialization for gray_pixel_16.
|
||||
*/
|
||||
template<>
|
||||
struct pixel_traits< gray_pixel_16 >
|
||||
: basic_pixel_traits< gray_pixel_16, uint_16, color_type_gray >
|
||||
{
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Pixel traits specialization for packed_gray_pixel.
|
||||
*/
|
||||
template< size_t bits >
|
||||
struct pixel_traits< packed_gray_pixel< bits > >
|
||||
: basic_pixel_traits< packed_gray_pixel< bits >, byte,
|
||||
color_type_gray, /* channels = */ 1, bits >
|
||||
{
|
||||
};
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_GRAY_PIXEL_HPP_INCLUDED
|
536
src/png++-0.2.5/image.hpp
Normal file
@ -0,0 +1,536 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
#ifndef PNGPP_IMAGE_HPP_INCLUDED
|
||||
#define PNGPP_IMAGE_HPP_INCLUDED
|
||||
|
||||
#include <fstream>
|
||||
#include "pixel_buffer.hpp"
|
||||
#include "generator.hpp"
|
||||
#include "consumer.hpp"
|
||||
#include "convert_color_space.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief Class template to represent PNG image.
|
||||
*
|
||||
* The image consists of pixel data as well as additional %image
|
||||
* %info like interlace type, compression method, palette (for
|
||||
* colormap-based images) etc. Provides methods to read and write
|
||||
* images from/to a generic stream and to manipulate %image pixels.
|
||||
*/
|
||||
template< typename pixel >
|
||||
class image
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* \brief The pixel traits type for \c pixel.
|
||||
*/
|
||||
typedef pixel_traits< pixel > traits;
|
||||
|
||||
/**
|
||||
* \brief The pixel buffer type for \c pixel.
|
||||
*/
|
||||
typedef pixel_buffer< pixel > pixbuf;
|
||||
|
||||
/**
|
||||
* \brief Represents a row of image pixel data.
|
||||
*/
|
||||
typedef typename pixbuf::row_type row_type;
|
||||
|
||||
/**
|
||||
* \brief A transformation functor to convert any image to
|
||||
* appropriate color space.
|
||||
*/
|
||||
typedef convert_color_space< pixel > transform_convert;
|
||||
|
||||
/**
|
||||
* \brief The default io transformation: does nothing.
|
||||
*/
|
||||
struct transform_identity
|
||||
{
|
||||
void operator()(io_base&) const {}
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Constructs an empty image.
|
||||
*/
|
||||
image()
|
||||
: m_info(make_image_info< pixel >())
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Constructs an empty image of specified width and height.
|
||||
*/
|
||||
image(size_t width, size_t height)
|
||||
: m_info(make_image_info< pixel >())
|
||||
{
|
||||
resize(width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Constructs an image reading data from specified file
|
||||
* using default converting transform.
|
||||
*/
|
||||
explicit image(std::string const& filename)
|
||||
{
|
||||
read(filename, transform_convert());
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Constructs an image reading data from specified file
|
||||
* using custom transformaton.
|
||||
*/
|
||||
template< class transformation >
|
||||
image(std::string const& filename,
|
||||
transformation const& transform)
|
||||
{
|
||||
read(filename.c_str(), transform);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Constructs an image reading data from specified file
|
||||
* using default converting transform.
|
||||
*/
|
||||
explicit image(char const* filename)
|
||||
{
|
||||
read(filename, transform_convert());
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Constructs an image reading data from specified file
|
||||
* using custom transformaton.
|
||||
*/
|
||||
template< class transformation >
|
||||
image(char const* filename, transformation const& transform)
|
||||
{
|
||||
read(filename, transform);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Constructs an image reading data from a stream using
|
||||
* default converting transform.
|
||||
*/
|
||||
explicit image(std::istream& stream)
|
||||
{
|
||||
read_stream(stream, transform_convert());
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Constructs an image reading data from a stream using
|
||||
* custom transformation.
|
||||
*/
|
||||
template< class transformation >
|
||||
image(std::istream& stream, transformation const& transform)
|
||||
{
|
||||
read_stream(stream, transform);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Reads an image from specified file using default
|
||||
* converting transform.
|
||||
*/
|
||||
void read(std::string const& filename)
|
||||
{
|
||||
read(filename, transform_convert());
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Reads an image from specified file using custom
|
||||
* transformaton.
|
||||
*/
|
||||
template< class transformation >
|
||||
void read(std::string const& filename, transformation const& transform)
|
||||
{
|
||||
read(filename.c_str(), transform);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Reads an image from specified file using default
|
||||
* converting transform.
|
||||
*/
|
||||
void read(char const* filename)
|
||||
{
|
||||
read(filename, transform_convert());
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Reads an image from specified file using custom
|
||||
* transformaton.
|
||||
*/
|
||||
template< class transformation >
|
||||
void read(char const* filename, transformation const& transform)
|
||||
{
|
||||
std::ifstream stream(filename, std::ios::binary);
|
||||
if (!stream.is_open())
|
||||
{
|
||||
throw std_error(filename);
|
||||
}
|
||||
stream.exceptions(std::ios::badbit);
|
||||
read_stream(stream, transform);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Reads an image from a stream using default
|
||||
* converting transform.
|
||||
*/
|
||||
void read(std::istream& stream)
|
||||
{
|
||||
read_stream(stream, transform_convert());
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Reads an image from a stream using custom
|
||||
* transformation.
|
||||
*/
|
||||
template< class transformation >
|
||||
void read(std::istream& stream, transformation const& transform)
|
||||
{
|
||||
read_stream(stream, transform);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Reads an image from a stream using default
|
||||
* converting transform.
|
||||
*/
|
||||
template< class istream >
|
||||
void read_stream(istream& stream)
|
||||
{
|
||||
read_stream(stream, transform_convert());
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Reads an image from a stream using custom
|
||||
* transformation.
|
||||
*/
|
||||
template< class istream, class transformation >
|
||||
void read_stream(istream& stream, transformation const& transform)
|
||||
{
|
||||
pixel_consumer pixcon(m_info, m_pixbuf);
|
||||
pixcon.read(stream, transform);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Writes an image to specified file.
|
||||
*/
|
||||
void write(std::string const& filename)
|
||||
{
|
||||
write(filename.c_str());
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Writes an image to specified file.
|
||||
*/
|
||||
void write(char const* filename)
|
||||
{
|
||||
std::ofstream stream(filename, std::ios::binary);
|
||||
if (!stream.is_open())
|
||||
{
|
||||
throw std_error(filename);
|
||||
}
|
||||
stream.exceptions(std::ios::badbit);
|
||||
write_stream(stream);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Writes an image to a stream.
|
||||
*/
|
||||
void write_stream(std::ostream& stream)
|
||||
{
|
||||
write_stream(stream);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Writes an image to a stream.
|
||||
*/
|
||||
template< class ostream >
|
||||
void write_stream(ostream& stream)
|
||||
{
|
||||
pixel_generator pixgen(m_info, m_pixbuf);
|
||||
pixgen.write(stream);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns a reference to image pixel buffer.
|
||||
*/
|
||||
pixbuf& get_pixbuf()
|
||||
{
|
||||
return m_pixbuf;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns a const reference to image pixel buffer.
|
||||
*/
|
||||
pixbuf const& get_pixbuf() const
|
||||
{
|
||||
return m_pixbuf;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Replaces the image pixel buffer.
|
||||
*
|
||||
* \param buffer a pixel buffer object to take a copy from
|
||||
*/
|
||||
void set_pixbuf(pixbuf const& buffer)
|
||||
{
|
||||
m_pixbuf = buffer;
|
||||
}
|
||||
|
||||
size_t get_width() const
|
||||
{
|
||||
return m_pixbuf.get_width();
|
||||
}
|
||||
|
||||
size_t get_height() const
|
||||
{
|
||||
return m_pixbuf.get_height();
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Resizes the image pixel buffer.
|
||||
*/
|
||||
void resize(size_t width, size_t height)
|
||||
{
|
||||
m_pixbuf.resize(width, height);
|
||||
m_info.set_width(width);
|
||||
m_info.set_height(height);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns a reference to the row of image data at
|
||||
* specified index.
|
||||
*
|
||||
* \see pixel_buffer::get_row()
|
||||
*/
|
||||
row_type& get_row(size_t index)
|
||||
{
|
||||
return m_pixbuf.get_row(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns a const reference to the row of image data at
|
||||
* specified index.
|
||||
*
|
||||
* \see pixel_buffer::get_row()
|
||||
*/
|
||||
row_type const& get_row(size_t index) const
|
||||
{
|
||||
return m_pixbuf.get_row(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief The non-checking version of get_row() method.
|
||||
*/
|
||||
row_type& operator[](size_t index)
|
||||
{
|
||||
return m_pixbuf[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief The non-checking version of get_row() method.
|
||||
*/
|
||||
row_type const& operator[](size_t index) const
|
||||
{
|
||||
return m_pixbuf[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns a pixel at (x,y) position.
|
||||
*/
|
||||
pixel get_pixel(size_t x, size_t y) const
|
||||
{
|
||||
return m_pixbuf.get_pixel(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Replaces a pixel at (x,y) position.
|
||||
*/
|
||||
void set_pixel(size_t x, size_t y, pixel p)
|
||||
{
|
||||
m_pixbuf.set_pixel(x, y, p);
|
||||
}
|
||||
|
||||
interlace_type get_interlace_type() const
|
||||
{
|
||||
return m_info.get_interlace_type();
|
||||
}
|
||||
|
||||
void set_interlace_type(interlace_type interlace)
|
||||
{
|
||||
m_info.set_interlace_type(interlace);
|
||||
}
|
||||
|
||||
compression_type get_compression_type() const
|
||||
{
|
||||
return m_info.get_compression_type();
|
||||
}
|
||||
|
||||
void set_compression_type(compression_type compression)
|
||||
{
|
||||
m_info.set_compression_type(compression);
|
||||
}
|
||||
|
||||
filter_type get_filter_type() const
|
||||
{
|
||||
return m_info.get_filter_type();
|
||||
}
|
||||
|
||||
void set_filter_type(filter_type filter)
|
||||
{
|
||||
m_info.set_filter_type(filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns a reference to the image palette.
|
||||
*/
|
||||
palette& get_palette()
|
||||
{
|
||||
return m_info.get_palette();
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns a const reference to the image palette.
|
||||
*/
|
||||
palette const& get_palette() const
|
||||
{
|
||||
return m_info.get_palette();
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Replaces the image palette.
|
||||
*/
|
||||
void set_palette(palette const& plte)
|
||||
{
|
||||
m_info.set_palette(plte);
|
||||
}
|
||||
|
||||
tRNS const& get_tRNS() const
|
||||
{
|
||||
return m_info.get_tRNS();
|
||||
}
|
||||
|
||||
tRNS& get_tRNS()
|
||||
{
|
||||
return m_info.get_tRNS();
|
||||
}
|
||||
|
||||
void set_tRNS(tRNS const& trns)
|
||||
{
|
||||
m_info.set_tRNS(trns);
|
||||
}
|
||||
|
||||
protected:
|
||||
/**
|
||||
* \brief A common base class template for pixel_consumer and
|
||||
* pixel_generator classes.
|
||||
*/
|
||||
template< typename base_impl >
|
||||
class streaming_impl
|
||||
: public base_impl
|
||||
{
|
||||
public:
|
||||
streaming_impl(image_info& info, pixbuf& pixels)
|
||||
: base_impl(info),
|
||||
m_pixbuf(pixels)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns the starting address of a \c pos-th row
|
||||
* in the image's pixel buffer.
|
||||
*/
|
||||
byte* get_next_row(size_t pos)
|
||||
{
|
||||
typedef typename pixbuf::row_traits row_traits;
|
||||
return reinterpret_cast< byte* >
|
||||
(row_traits::get_data(m_pixbuf.get_row(pos)));
|
||||
}
|
||||
|
||||
protected:
|
||||
pixbuf& m_pixbuf;
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief The pixel buffer adapter for reading pixel data.
|
||||
*/
|
||||
class pixel_consumer
|
||||
: public streaming_impl< consumer< pixel,
|
||||
pixel_consumer,
|
||||
image_info_ref_holder,
|
||||
/* interlacing = */ true > >
|
||||
{
|
||||
public:
|
||||
pixel_consumer(image_info& info, pixbuf& pixels)
|
||||
: streaming_impl< consumer< pixel,
|
||||
pixel_consumer,
|
||||
image_info_ref_holder,
|
||||
true > >(info, pixels)
|
||||
{
|
||||
}
|
||||
|
||||
void reset(size_t pass)
|
||||
{
|
||||
if (pass == 0)
|
||||
{
|
||||
this->m_pixbuf.resize(this->get_info().get_width(),
|
||||
this->get_info().get_height());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief The pixel buffer adapter for writing pixel data.
|
||||
*/
|
||||
class pixel_generator
|
||||
: public streaming_impl< generator< pixel,
|
||||
pixel_generator,
|
||||
image_info_ref_holder,
|
||||
/* interlacing = */ true > >
|
||||
{
|
||||
public:
|
||||
pixel_generator(image_info& info, pixbuf& pixels)
|
||||
: streaming_impl< generator< pixel,
|
||||
pixel_generator,
|
||||
image_info_ref_holder,
|
||||
true > >(info, pixels)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
image_info m_info;
|
||||
pixbuf m_pixbuf;
|
||||
};
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_IMAGE_HPP_INCLUDED
|
203
src/png++-0.2.5/image_info.hpp
Normal file
@ -0,0 +1,203 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
#ifndef PNGPP_IMAGE_INFO_HPP_INCLUDED
|
||||
#define PNGPP_IMAGE_INFO_HPP_INCLUDED
|
||||
|
||||
#include "types.hpp"
|
||||
#include "palette.hpp"
|
||||
#include "tRNS.hpp"
|
||||
#include "pixel_traits.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief Holds information about PNG image.
|
||||
*
|
||||
* \see image, generator, consumer
|
||||
*/
|
||||
class image_info
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* \brief Constructs the image_info object with default values
|
||||
* for color_type, interlace_type, compression_method and
|
||||
* filter_type.
|
||||
*/
|
||||
image_info()
|
||||
: m_width(0),
|
||||
m_height(0),
|
||||
m_bit_depth(0),
|
||||
m_color_type(color_type_none),
|
||||
m_interlace_type(interlace_none),
|
||||
m_compression_type(compression_type_default),
|
||||
m_filter_type(filter_type_default)
|
||||
{
|
||||
}
|
||||
|
||||
size_t get_width() const
|
||||
{
|
||||
return m_width;
|
||||
}
|
||||
|
||||
void set_width(size_t width)
|
||||
{
|
||||
m_width = width;
|
||||
}
|
||||
|
||||
size_t get_height() const
|
||||
{
|
||||
return m_height;
|
||||
}
|
||||
|
||||
void set_height(size_t height)
|
||||
{
|
||||
m_height = height;
|
||||
}
|
||||
|
||||
color_type get_color_type() const
|
||||
{
|
||||
return m_color_type;
|
||||
}
|
||||
|
||||
void set_color_type(color_type color_space)
|
||||
{
|
||||
m_color_type = color_space;
|
||||
}
|
||||
|
||||
size_t get_bit_depth() const
|
||||
{
|
||||
return m_bit_depth;
|
||||
}
|
||||
|
||||
void set_bit_depth(size_t bit_depth)
|
||||
{
|
||||
m_bit_depth = bit_depth;
|
||||
}
|
||||
|
||||
interlace_type get_interlace_type() const
|
||||
{
|
||||
return m_interlace_type;
|
||||
}
|
||||
|
||||
void set_interlace_type(interlace_type interlace)
|
||||
{
|
||||
m_interlace_type = interlace;
|
||||
}
|
||||
|
||||
compression_type get_compression_type() const
|
||||
{
|
||||
return m_compression_type;
|
||||
}
|
||||
|
||||
void set_compression_type(compression_type compression)
|
||||
{
|
||||
m_compression_type = compression;
|
||||
}
|
||||
|
||||
filter_type get_filter_type() const
|
||||
{
|
||||
return m_filter_type;
|
||||
}
|
||||
|
||||
void set_filter_type(filter_type filter)
|
||||
{
|
||||
m_filter_type = filter;
|
||||
}
|
||||
|
||||
palette const& get_palette() const
|
||||
{
|
||||
return m_palette;
|
||||
}
|
||||
|
||||
palette& get_palette()
|
||||
{
|
||||
return m_palette;
|
||||
}
|
||||
|
||||
void set_palette(palette const& plte)
|
||||
{
|
||||
m_palette = plte;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Removes all entries from the palette.
|
||||
*/
|
||||
void drop_palette()
|
||||
{
|
||||
m_palette.clear();
|
||||
}
|
||||
|
||||
tRNS const& get_tRNS() const
|
||||
{
|
||||
return m_tRNS;
|
||||
}
|
||||
|
||||
tRNS& get_tRNS()
|
||||
{
|
||||
return m_tRNS;
|
||||
}
|
||||
|
||||
void set_tRNS(tRNS const& trns)
|
||||
{
|
||||
m_tRNS = trns;
|
||||
}
|
||||
|
||||
protected:
|
||||
uint_32 m_width;
|
||||
uint_32 m_height;
|
||||
size_t m_bit_depth;
|
||||
color_type m_color_type;
|
||||
interlace_type m_interlace_type;
|
||||
compression_type m_compression_type;
|
||||
filter_type m_filter_type;
|
||||
palette m_palette;
|
||||
tRNS m_tRNS;
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Returns an image_info object with color_type and
|
||||
* bit_depth fields setup appropriate for the \c pixel type.
|
||||
*/
|
||||
template< typename pixel >
|
||||
image_info
|
||||
make_image_info()
|
||||
{
|
||||
typedef pixel_traits< pixel > traits;
|
||||
image_info info;
|
||||
info.set_color_type(traits::get_color_type());
|
||||
info.set_bit_depth(traits::get_bit_depth());
|
||||
return info;
|
||||
}
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_IMAGE_INFO_HPP_INCLUDED
|
112
src/png++-0.2.5/index_pixel.hpp
Normal file
@ -0,0 +1,112 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
#ifndef PNGPP_INDEX_PIXEL_HPP_INCLUDED
|
||||
#define PNGPP_INDEX_PIXEL_HPP_INCLUDED
|
||||
|
||||
#include "types.hpp"
|
||||
#include "packed_pixel.hpp"
|
||||
#include "pixel_traits.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief The 8-bit Indexed (colormap) pixel type.
|
||||
*/
|
||||
class index_pixel
|
||||
{
|
||||
public:
|
||||
index_pixel(byte index = 0)
|
||||
: m_index(index)
|
||||
{
|
||||
}
|
||||
|
||||
operator byte() const
|
||||
{
|
||||
return m_index;
|
||||
}
|
||||
|
||||
private:
|
||||
byte m_index;
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief The packed indexed pixel class template. The available
|
||||
* specializations are for 1-, 2- and 4-bit pixels.
|
||||
*/
|
||||
template< size_t bits >
|
||||
class packed_index_pixel
|
||||
: public packed_pixel< bits >
|
||||
{
|
||||
public:
|
||||
packed_index_pixel(byte value = 0)
|
||||
: packed_pixel< bits >(value)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief The 1-bit Indexed pixel type.
|
||||
*/
|
||||
typedef packed_index_pixel< 1 > index_pixel_1;
|
||||
|
||||
/**
|
||||
* \brief The 1-bit Indexed pixel type.
|
||||
*/
|
||||
typedef packed_index_pixel< 2 > index_pixel_2;
|
||||
|
||||
/**
|
||||
* \brief The 1-bit Indexed pixel type.
|
||||
*/
|
||||
typedef packed_index_pixel< 4 > index_pixel_4;
|
||||
|
||||
/**
|
||||
* \brief Pixel traits specialization for index_pixel.
|
||||
*/
|
||||
template<>
|
||||
struct pixel_traits< index_pixel >
|
||||
: basic_pixel_traits< index_pixel, byte, color_type_palette >
|
||||
{
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Pixel traits specialization for packed_index_pixel.
|
||||
*/
|
||||
template< size_t bits >
|
||||
struct pixel_traits< packed_index_pixel< bits > >
|
||||
: basic_pixel_traits< packed_index_pixel< bits >, byte,
|
||||
color_type_palette, /* channels = */ 1, bits >
|
||||
{
|
||||
};
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_INDEX_PIXEL_HPP_INCLUDED
|
152
src/png++-0.2.5/info.hpp
Normal file
@ -0,0 +1,152 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
#ifndef PNGPP_INFO_HPP_INCLUDED
|
||||
#define PNGPP_INFO_HPP_INCLUDED
|
||||
|
||||
#include <cassert>
|
||||
#include "info_base.hpp"
|
||||
#include "image_info.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief Holds information about PNG image. Adapter class for IO
|
||||
* image operations.
|
||||
*/
|
||||
class info
|
||||
: public info_base,
|
||||
public image_info
|
||||
{
|
||||
public:
|
||||
info(io_base& io, png_struct* png)
|
||||
: info_base(io, png)
|
||||
{
|
||||
}
|
||||
|
||||
void read()
|
||||
{
|
||||
assert(m_png);
|
||||
assert(m_info);
|
||||
|
||||
png_read_info(m_png, m_info);
|
||||
png_get_IHDR(m_png,
|
||||
m_info,
|
||||
& m_width,
|
||||
& m_height,
|
||||
reinterpret_cast< int* >(& m_bit_depth),
|
||||
reinterpret_cast< int* >(& m_color_type),
|
||||
reinterpret_cast< int* >(& m_interlace_type),
|
||||
reinterpret_cast< int* >(& m_compression_type),
|
||||
reinterpret_cast< int* >(& m_filter_type));
|
||||
|
||||
if (png_get_valid(m_png, m_info, chunk_PLTE) == chunk_PLTE)
|
||||
{
|
||||
png_color* colors = 0;
|
||||
int count = 0;
|
||||
png_get_PLTE(m_png, m_info, & colors, & count);
|
||||
m_palette.assign(colors, colors + count);
|
||||
}
|
||||
#ifdef PNG_tRNS_SUPPORTED
|
||||
if (png_get_valid(m_png, m_info, chunk_tRNS) == chunk_tRNS)
|
||||
{
|
||||
if (m_color_type == color_type_palette)
|
||||
{
|
||||
int count;
|
||||
byte* values;
|
||||
if (png_get_tRNS(m_png, m_info, & values, & count, NULL)
|
||||
!= PNG_INFO_tRNS)
|
||||
{
|
||||
throw error("png_get_tRNS() failed");
|
||||
}
|
||||
m_tRNS.assign(values, values + count);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void write() const
|
||||
{
|
||||
assert(m_png);
|
||||
assert(m_info);
|
||||
|
||||
sync_ihdr();
|
||||
if (m_color_type == color_type_palette)
|
||||
{
|
||||
if (! m_palette.empty())
|
||||
{
|
||||
png_set_PLTE(m_png, m_info,
|
||||
const_cast< color* >(& m_palette[0]),
|
||||
m_palette.size());
|
||||
}
|
||||
if (! m_tRNS.empty())
|
||||
{
|
||||
#ifdef PNG_tRNS_SUPPORTED
|
||||
png_set_tRNS(m_png, m_info,
|
||||
const_cast< byte* >(& m_tRNS[0]),
|
||||
m_tRNS.size(),
|
||||
NULL);
|
||||
#else
|
||||
throw error("attempted to write tRNS chunk;"
|
||||
" recompile with PNG_tRNS_SUPPORTED");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
png_write_info(m_png, m_info);
|
||||
}
|
||||
|
||||
void update()
|
||||
{
|
||||
assert(m_png);
|
||||
assert(m_info);
|
||||
|
||||
sync_ihdr();
|
||||
png_read_update_info(m_png, m_info);
|
||||
}
|
||||
|
||||
protected:
|
||||
void sync_ihdr(void) const
|
||||
{
|
||||
png_set_IHDR(m_png,
|
||||
m_info,
|
||||
m_width,
|
||||
m_height,
|
||||
m_bit_depth,
|
||||
m_color_type,
|
||||
m_interlace_type,
|
||||
m_compression_type,
|
||||
m_filter_type);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_INFO_HPP_INCLUDED
|
77
src/png++-0.2.5/info_base.hpp
Normal file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
#ifndef PNGPP_INFO_BASE_HPP_INCLUDED
|
||||
#define PNGPP_INFO_BASE_HPP_INCLUDED
|
||||
|
||||
#include <cassert>
|
||||
#include "error.hpp"
|
||||
#include "types.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
class io_base;
|
||||
|
||||
/**
|
||||
* \brief Internal class to hold PNG info or end_info.
|
||||
*/
|
||||
class info_base
|
||||
{
|
||||
info_base(info_base const&);
|
||||
info_base& operator=(info_base const&);
|
||||
|
||||
public:
|
||||
info_base(io_base& io, png_struct* png)
|
||||
: m_io(io),
|
||||
m_png(png),
|
||||
m_info(png_create_info_struct(m_png))
|
||||
{
|
||||
}
|
||||
|
||||
png_info* get_png_info() const
|
||||
{
|
||||
return m_info;
|
||||
}
|
||||
|
||||
png_info** get_png_info_ptr()
|
||||
{
|
||||
return & m_info;
|
||||
}
|
||||
|
||||
protected:
|
||||
io_base& m_io;
|
||||
png_struct* m_png;
|
||||
png_info* m_info;
|
||||
};
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_INFO_BASE_HPP_INCLUDED
|
468
src/png++-0.2.5/io_base.hpp
Normal file
@ -0,0 +1,468 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
#ifndef PNGPP_IO_BASE_HPP_INCLUDED
|
||||
#define PNGPP_IO_BASE_HPP_INCLUDED
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <cstdarg>
|
||||
#include "error.hpp"
|
||||
#include "info.hpp"
|
||||
#include "end_info.hpp"
|
||||
|
||||
static void
|
||||
trace_io_transform(char const* fmt, ...)
|
||||
{
|
||||
#ifdef DEBUG_IO_TRANSFORM
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
fprintf(stderr, "TRANSFORM_IO: ");
|
||||
vfprintf(stderr, fmt, va);
|
||||
va_end(va);
|
||||
#endif
|
||||
}
|
||||
#define TRACE_IO_TRANSFORM trace_io_transform
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief Base class for PNG reader/writer classes.
|
||||
*
|
||||
* \see reader, writer
|
||||
*/
|
||||
class io_base
|
||||
{
|
||||
io_base(io_base const&);
|
||||
io_base& operator=(io_base const&);
|
||||
|
||||
public:
|
||||
explicit io_base(png_struct* png)
|
||||
: m_png(png),
|
||||
m_info(*this, m_png),
|
||||
m_end_info(*this, m_png)
|
||||
{
|
||||
}
|
||||
|
||||
~io_base()
|
||||
{
|
||||
assert(! m_png);
|
||||
assert(! m_info.get_png_info());
|
||||
assert(! m_end_info.get_png_info());
|
||||
}
|
||||
|
||||
png_struct* get_png_struct() const
|
||||
{
|
||||
return m_png;
|
||||
}
|
||||
|
||||
info& get_info()
|
||||
{
|
||||
return m_info;
|
||||
}
|
||||
|
||||
info const& get_info() const
|
||||
{
|
||||
return m_info;
|
||||
}
|
||||
|
||||
image_info const& get_image_info() const
|
||||
{
|
||||
return m_info;
|
||||
}
|
||||
|
||||
void set_image_info(image_info const& info)
|
||||
{
|
||||
static_cast< image_info& >(m_info) = info; // slice it
|
||||
}
|
||||
|
||||
end_info& get_end_info()
|
||||
{
|
||||
return m_end_info;
|
||||
}
|
||||
|
||||
end_info const& get_end_info() const
|
||||
{
|
||||
return m_end_info;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// info accessors
|
||||
//
|
||||
size_t get_width() const
|
||||
{
|
||||
return m_info.get_width();
|
||||
}
|
||||
|
||||
void set_width(size_t width)
|
||||
{
|
||||
m_info.set_width(width);
|
||||
}
|
||||
|
||||
size_t get_height() const
|
||||
{
|
||||
return m_info.get_height();
|
||||
}
|
||||
|
||||
void set_height(size_t height)
|
||||
{
|
||||
m_info.set_height(height);
|
||||
}
|
||||
|
||||
color_type get_color_type() const
|
||||
{
|
||||
return m_info.get_color_type();
|
||||
}
|
||||
|
||||
void set_color_type(color_type color_space)
|
||||
{
|
||||
m_info.set_color_type(color_space);
|
||||
}
|
||||
|
||||
size_t get_bit_depth() const
|
||||
{
|
||||
return m_info.get_bit_depth();
|
||||
}
|
||||
|
||||
void set_bit_depth(size_t bit_depth)
|
||||
{
|
||||
m_info.set_bit_depth(bit_depth);
|
||||
}
|
||||
|
||||
interlace_type get_interlace_type() const
|
||||
{
|
||||
return m_info.get_interlace_type();
|
||||
}
|
||||
|
||||
void set_interlace_type(interlace_type interlace)
|
||||
{
|
||||
m_info.set_interlace_type(interlace);
|
||||
}
|
||||
|
||||
compression_type get_compression_type() const
|
||||
{
|
||||
return m_info.get_compression_type();
|
||||
}
|
||||
|
||||
void set_compression_type(compression_type compression)
|
||||
{
|
||||
m_info.set_compression_type(compression);
|
||||
}
|
||||
|
||||
filter_type get_filter_type() const
|
||||
{
|
||||
return m_info.get_filter_type();
|
||||
}
|
||||
|
||||
void set_filter_type(filter_type filter)
|
||||
{
|
||||
m_info.set_filter_type(filter);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool has_chunk(chunk id)
|
||||
{
|
||||
return png_get_valid(m_png,
|
||||
m_info.get_png_info(),
|
||||
uint_32(id)) == uint_32(id);
|
||||
}
|
||||
|
||||
#if defined(PNG_READ_EXPAND_SUPPORTED)
|
||||
void set_gray_1_2_4_to_8() const
|
||||
{
|
||||
TRACE_IO_TRANSFORM("png_set_expand_gray_1_2_4_to_8\n");
|
||||
png_set_expand_gray_1_2_4_to_8(m_png);
|
||||
}
|
||||
|
||||
void set_palette_to_rgb() const
|
||||
{
|
||||
TRACE_IO_TRANSFORM("png_set_palette_to_rgb\n");
|
||||
png_set_palette_to_rgb(m_png);
|
||||
}
|
||||
|
||||
void set_tRNS_to_alpha() const
|
||||
{
|
||||
TRACE_IO_TRANSFORM("png_set_tRNS_to_alpha\n");
|
||||
png_set_tRNS_to_alpha(m_png);
|
||||
}
|
||||
#endif // defined(PNG_READ_EXPAND_SUPPORTED)
|
||||
|
||||
#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
|
||||
void set_bgr() const
|
||||
{
|
||||
TRACE_IO_TRANSFORM("png_set_bgr\n");
|
||||
png_set_bgr(m_png);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
|
||||
void set_gray_to_rgb() const
|
||||
{
|
||||
TRACE_IO_TRANSFORM("png_set_gray_to_rgb\n");
|
||||
png_set_gray_to_rgb(m_png);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
void set_rgb_to_gray(rgb_to_gray_error_action error_action
|
||||
= rgb_to_gray_silent,
|
||||
double red_weight = -1.0,
|
||||
double green_weight = -1.0) const
|
||||
{
|
||||
TRACE_IO_TRANSFORM("png_set_rgb_to_gray: error_action=%d,"
|
||||
" red_weight=%lf, green_weight=%lf\n",
|
||||
error_action, red_weight, green_weight);
|
||||
|
||||
png_set_rgb_to_gray(m_png, error_action, red_weight, green_weight);
|
||||
}
|
||||
#else
|
||||
void set_rgb_to_gray(rgb_to_gray_error_action error_action
|
||||
= rgb_to_gray_silent,
|
||||
fixed_point red_weight = -1,
|
||||
fixed_point green_weight = -1) const
|
||||
{
|
||||
TRACE_IO_TRANSFORM("png_set_rgb_to_gray_fixed: error_action=%d,"
|
||||
" red_weight=%d, green_weight=%d\n",
|
||||
error_action, red_weight, green_weight);
|
||||
|
||||
png_set_rgb_to_gray_fixed(m_png, error_action,
|
||||
red_weight, green_weight);
|
||||
}
|
||||
#endif // PNG_FLOATING_POINT_SUPPORTED
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// alpha channel transformations
|
||||
//
|
||||
#if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
|
||||
void set_strip_alpha() const
|
||||
{
|
||||
TRACE_IO_TRANSFORM("png_set_strip_alpha\n");
|
||||
png_set_strip_alpha(m_png);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) \
|
||||
|| defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
|
||||
void set_swap_alpha() const
|
||||
{
|
||||
TRACE_IO_TRANSFORM("png_set_swap_alpha\n");
|
||||
png_set_swap_alpha(m_png);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) \
|
||||
|| defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
|
||||
void set_invert_alpha() const
|
||||
{
|
||||
TRACE_IO_TRANSFORM("png_set_invert_alpha\n");
|
||||
png_set_invert_alpha(m_png);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
|
||||
void set_filler(uint_32 filler, filler_type type) const
|
||||
{
|
||||
TRACE_IO_TRANSFORM("png_set_filler: filler=%08x, type=%d\n",
|
||||
filler, type);
|
||||
|
||||
png_set_filler(m_png, filler, type);
|
||||
}
|
||||
|
||||
#if !defined(PNG_1_0_X)
|
||||
void set_add_alpha(uint_32 filler, filler_type type) const
|
||||
{
|
||||
TRACE_IO_TRANSFORM("png_set_add_alpha: filler=%08x, type=%d\n",
|
||||
filler, type);
|
||||
|
||||
png_set_add_alpha(m_png, filler, type);
|
||||
}
|
||||
#endif
|
||||
#endif // PNG_READ_FILLER_SUPPORTED || PNG_WRITE_FILLER_SUPPORTED
|
||||
|
||||
#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
|
||||
void set_swap() const
|
||||
{
|
||||
TRACE_IO_TRANSFORM("png_set_swap\n");
|
||||
png_set_swap(m_png);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
|
||||
void set_packing() const
|
||||
{
|
||||
TRACE_IO_TRANSFORM("png_set_packing\n");
|
||||
png_set_packing(m_png);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_PACKSWAP_SUPPORTED) \
|
||||
|| defined(PNG_WRITE_PACKSWAP_SUPPORTED)
|
||||
void set_packswap() const
|
||||
{
|
||||
TRACE_IO_TRANSFORM("png_set_packswap\n");
|
||||
png_set_packswap(m_png);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
|
||||
void set_shift(byte red_bits, byte green_bits, byte blue_bits,
|
||||
byte alpha_bits = 0) const
|
||||
{
|
||||
TRACE_IO_TRANSFORM("png_set_shift: red_bits=%d, green_bits=%d,"
|
||||
" blue_bits=%d, alpha_bits=%d\n",
|
||||
red_bits, green_bits, blue_bits, alpha_bits);
|
||||
|
||||
if (get_color_type() != color_type_rgb
|
||||
|| get_color_type() != color_type_rgb_alpha)
|
||||
{
|
||||
throw error("set_shift: expected RGB or RGBA color type");
|
||||
}
|
||||
color_info bits;
|
||||
bits.red = red_bits;
|
||||
bits.green = green_bits;
|
||||
bits.blue = blue_bits;
|
||||
bits.alpha = alpha_bits;
|
||||
png_set_shift(m_png, & bits);
|
||||
}
|
||||
|
||||
void set_shift(byte gray_bits, byte alpha_bits = 0) const
|
||||
{
|
||||
TRACE_IO_TRANSFORM("png_set_shift: gray_bits=%d, alpha_bits=%d\n",
|
||||
gray_bits, alpha_bits);
|
||||
|
||||
if (get_color_type() != color_type_gray
|
||||
|| get_color_type() != color_type_gray_alpha)
|
||||
{
|
||||
throw error("set_shift: expected Gray or Gray+Alpha"
|
||||
" color type");
|
||||
}
|
||||
color_info bits;
|
||||
bits.gray = gray_bits;
|
||||
bits.alpha = alpha_bits;
|
||||
png_set_shift(m_png, & bits);
|
||||
}
|
||||
#endif // PNG_READ_SHIFT_SUPPORTED || PNG_WRITE_SHIFT_SUPPORTED
|
||||
|
||||
#if defined(PNG_READ_INTERLACING_SUPPORTED) \
|
||||
|| defined(PNG_WRITE_INTERLACING_SUPPORTED)
|
||||
int set_interlace_handling() const
|
||||
{
|
||||
TRACE_IO_TRANSFORM("png_set_interlace_handling\n");
|
||||
return png_set_interlace_handling(m_png);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
|
||||
void set_invert_mono() const
|
||||
{
|
||||
TRACE_IO_TRANSFORM("png_set_invert_mono\n");
|
||||
png_set_invert_mono(m_png);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_16_TO_8_SUPPORTED)
|
||||
void set_strip_16() const
|
||||
{
|
||||
TRACE_IO_TRANSFORM("png_set_strip_16\n");
|
||||
png_set_strip_16(m_png);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
|
||||
void set_read_user_transform(png_user_transform_ptr transform_fn)
|
||||
{
|
||||
TRACE_IO_TRANSFORM("png_set_read_user_transform_fn\n");
|
||||
png_set_read_user_transform_fn(m_png, transform_fn);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) \
|
||||
|| defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
|
||||
void set_user_transform_info(void* info, int bit_depth, int channels)
|
||||
{
|
||||
TRACE_IO_TRANSFORM("png_set_user_transform_info: bit_depth=%d,"
|
||||
" channels=%d\n", bit_depth, channels);
|
||||
|
||||
png_set_user_transform_info(m_png, info, bit_depth, channels);
|
||||
}
|
||||
#endif
|
||||
|
||||
protected:
|
||||
void* get_io_ptr() const
|
||||
{
|
||||
return png_get_io_ptr(m_png);
|
||||
}
|
||||
|
||||
void set_error(char const* message)
|
||||
{
|
||||
assert(message);
|
||||
m_error = message;
|
||||
}
|
||||
|
||||
void reset_error()
|
||||
{
|
||||
m_error.clear();
|
||||
}
|
||||
|
||||
/*
|
||||
std::string const& get_error() const
|
||||
{
|
||||
return m_error;
|
||||
}
|
||||
*/
|
||||
|
||||
bool is_error() const
|
||||
{
|
||||
return !m_error.empty();
|
||||
}
|
||||
|
||||
void raise_error()
|
||||
{
|
||||
longjmp(png_jmpbuf(m_png), -1);
|
||||
}
|
||||
|
||||
static void raise_error(png_struct* png, char const* message)
|
||||
{
|
||||
io_base* io = static_cast< io_base* >(png_get_error_ptr(png));
|
||||
io->set_error(message);
|
||||
io->raise_error();
|
||||
}
|
||||
|
||||
png_struct* m_png;
|
||||
info m_info;
|
||||
end_info m_end_info;
|
||||
std::string m_error;
|
||||
};
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_IO_BASE_HPP_INCLUDED
|
84
src/png++-0.2.5/packed_pixel.hpp
Normal file
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
#ifndef PNGPP_PACKED_PIXEL_HPP_INCLUDED
|
||||
#define PNGPP_PACKED_PIXEL_HPP_INCLUDED
|
||||
|
||||
#include "types.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template< size_t bits > class allowed_bit_depth;
|
||||
|
||||
template<> class allowed_bit_depth< 1 > {};
|
||||
template<> class allowed_bit_depth< 2 > {};
|
||||
template<> class allowed_bit_depth< 4 > {};
|
||||
} // namespace detail
|
||||
|
||||
/**
|
||||
* \brief The packed pixel class template.
|
||||
*
|
||||
* \see packed_gray_pixel, packed_index_pixel
|
||||
*/
|
||||
template< size_t bits >
|
||||
class packed_pixel
|
||||
: detail::allowed_bit_depth< bits >
|
||||
{
|
||||
public:
|
||||
packed_pixel(byte value = 0)
|
||||
: m_value(value & get_bit_mask())
|
||||
{
|
||||
}
|
||||
|
||||
operator byte() const
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
|
||||
static size_t const get_bit_depth()
|
||||
{
|
||||
return bits;
|
||||
}
|
||||
|
||||
static byte const get_bit_mask()
|
||||
{
|
||||
return (1 << bits) - 1;
|
||||
}
|
||||
|
||||
private:
|
||||
byte m_value;
|
||||
};
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_PACKED_PIXEL_HPP_INCLUDED
|
48
src/png++-0.2.5/palette.hpp
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
#ifndef PNGPP_PALETTE_HPP_INCLUDED
|
||||
#define PNGPP_PALETTE_HPP_INCLUDED
|
||||
|
||||
#include <vector>
|
||||
#include "color.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief The palette type. Currently implemented as \c std::vector
|
||||
* of png::color.
|
||||
*/
|
||||
typedef std::vector< color > palette;
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_PALETTE_HPP_INCLUDED
|
495
src/png++-0.2.5/pixel_buffer.hpp
Normal file
@ -0,0 +1,495 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
#ifndef PNGPP_PIXEL_BUFFER_HPP_INCLUDED
|
||||
#define PNGPP_PIXEL_BUFFER_HPP_INCLUDED
|
||||
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
|
||||
#include "packed_pixel.hpp"
|
||||
#include "gray_pixel.hpp"
|
||||
#include "index_pixel.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief The pixel row traits class template. Provides a common
|
||||
* way to get starting address of the row for packed and unpacked
|
||||
* row types.
|
||||
*
|
||||
* Not implemented--see specializations.
|
||||
*/
|
||||
template< typename row > class row_traits;
|
||||
|
||||
/**
|
||||
* \brief The basic class template to represent image pixel data.
|
||||
*/
|
||||
template< typename pixel,
|
||||
typename row,
|
||||
class traits = row_traits< row > >
|
||||
class basic_pixel_buffer
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* \brief A row of pixel data.
|
||||
*/
|
||||
typedef row row_type;
|
||||
typedef traits row_traits;
|
||||
|
||||
/**
|
||||
* \brief Constructs an empty 0x0 pixel buffer object.
|
||||
*/
|
||||
basic_pixel_buffer()
|
||||
: m_width(0),
|
||||
m_height(0)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Constructs an empty pixel buffer object.
|
||||
*/
|
||||
basic_pixel_buffer(size_t width, size_t height)
|
||||
: m_width(0),
|
||||
m_height(0)
|
||||
{
|
||||
resize(width, height);
|
||||
}
|
||||
|
||||
size_t get_width() const
|
||||
{
|
||||
return m_width;
|
||||
}
|
||||
|
||||
size_t get_height() const
|
||||
{
|
||||
return m_height;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Resizes the pixel buffer.
|
||||
*
|
||||
* If new width or height is greater than the original,
|
||||
* expanded pixels are filled with value of \a pixel().
|
||||
*/
|
||||
void resize(size_t width, size_t height)
|
||||
{
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
m_rows.resize(height);
|
||||
for (typename row_vec::iterator r = m_rows.begin();
|
||||
r != m_rows.end();
|
||||
++r)
|
||||
{
|
||||
r->resize(width);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns a reference to the row of image data at
|
||||
* specified index.
|
||||
*
|
||||
* Checks the index before returning a row: an instance of
|
||||
* std::out_of_range is thrown if \c index is greater than \c
|
||||
* height.
|
||||
*/
|
||||
row_type& get_row(size_t index)
|
||||
{
|
||||
return m_rows.at(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns a const reference to the row of image data at
|
||||
* specified index.
|
||||
*
|
||||
* The checking version.
|
||||
*/
|
||||
row_type const& get_row(size_t index) const
|
||||
{
|
||||
return m_rows.at(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief The non-checking version of get_row() method.
|
||||
*/
|
||||
row_type& operator[](size_t index)
|
||||
{
|
||||
return m_rows[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief The non-checking version of get_row() method.
|
||||
*/
|
||||
row_type const& operator[](size_t index) const
|
||||
{
|
||||
return m_rows[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Replaces the row at specified index.
|
||||
*/
|
||||
void put_row(size_t index, row_type const& r)
|
||||
{
|
||||
assert(r.size() == m_width);
|
||||
m_rows.at(index) = r;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns a pixel at (x,y) position.
|
||||
*/
|
||||
pixel get_pixel(size_t x, size_t y) const
|
||||
{
|
||||
return get_row(y).at(x);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Replaces a pixel at (x,y) position.
|
||||
*/
|
||||
void set_pixel(size_t x, size_t y, pixel p)
|
||||
{
|
||||
get_row(y).at(x) = p;
|
||||
}
|
||||
|
||||
protected:
|
||||
size_t m_width;
|
||||
size_t m_height;
|
||||
typedef std::vector< row_type > row_vec;
|
||||
row_vec m_rows;
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief The row_traits specialization for unpacked pixel rows.
|
||||
*/
|
||||
template< typename pixel >
|
||||
class row_traits< std::vector< pixel > >
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* \brief Returns the starting address of the row.
|
||||
*/
|
||||
static pixel* get_data(std::vector< pixel >& vec)
|
||||
{
|
||||
assert(vec.size());
|
||||
return & vec[0];
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* The pixel_buffer specialization for unpacked pixels.
|
||||
*/
|
||||
template< typename pixel >
|
||||
class pixel_buffer
|
||||
: public basic_pixel_buffer< pixel, std::vector< pixel > >
|
||||
{
|
||||
public:
|
||||
pixel_buffer()
|
||||
{
|
||||
}
|
||||
|
||||
pixel_buffer(size_t width, size_t height)
|
||||
: basic_pixel_buffer< pixel, std::vector< pixel > >(width, height)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template< class pixel, typename reference >
|
||||
class basic_packed_pixel_proxy
|
||||
{
|
||||
public:
|
||||
explicit basic_packed_pixel_proxy(reference ref)
|
||||
: m_ref(ref),
|
||||
m_shift(0)
|
||||
{
|
||||
}
|
||||
|
||||
basic_packed_pixel_proxy(reference ref, size_t index)
|
||||
: m_ref(ref),
|
||||
m_shift(get_shift(index))
|
||||
{
|
||||
}
|
||||
|
||||
operator pixel() const
|
||||
{
|
||||
return pixel((m_ref >> m_shift) & pixel::get_bit_mask());
|
||||
}
|
||||
|
||||
protected:
|
||||
/*
|
||||
* bits: . . .
|
||||
* 1: 7 6 5 4 3 2 1 0
|
||||
* 2: 6 4 2 0
|
||||
* 4: 4 0
|
||||
*/
|
||||
static size_t get_shift(size_t index)
|
||||
{
|
||||
size_t const bits = pixel::get_bit_depth();
|
||||
return (8 - bits) - (index % get_pixels_per_byte()) * bits;
|
||||
}
|
||||
|
||||
static size_t get_pixels_per_byte()
|
||||
{
|
||||
return 8 / pixel::get_bit_depth();
|
||||
}
|
||||
|
||||
reference m_ref;
|
||||
size_t m_shift;
|
||||
};
|
||||
|
||||
template< class pixel >
|
||||
class const_packed_pixel_proxy
|
||||
: public basic_packed_pixel_proxy< pixel, byte const& >
|
||||
{
|
||||
public:
|
||||
const_packed_pixel_proxy(byte const& ref, size_t index)
|
||||
: basic_packed_pixel_proxy< pixel, byte const& >(ref, index)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
template< class pixel >
|
||||
class packed_pixel_proxy
|
||||
: public basic_packed_pixel_proxy< pixel, byte& >
|
||||
{
|
||||
public:
|
||||
typedef basic_packed_pixel_proxy< pixel, byte& > basic_proxy;
|
||||
|
||||
packed_pixel_proxy(byte& ref, size_t index)
|
||||
: basic_proxy(ref, index)
|
||||
{
|
||||
}
|
||||
|
||||
packed_pixel_proxy(packed_pixel_proxy const& other)
|
||||
: basic_proxy(other.m_ref)
|
||||
{
|
||||
this->m_shift = other.m_shift;
|
||||
}
|
||||
|
||||
packed_pixel_proxy& operator=(packed_pixel_proxy const& other)
|
||||
{
|
||||
return *this = static_cast< pixel >(other);
|
||||
}
|
||||
|
||||
template< typename reference >
|
||||
packed_pixel_proxy&
|
||||
operator=(basic_packed_pixel_proxy< pixel, reference > const& other)
|
||||
{
|
||||
return *this = static_cast< pixel >(other);
|
||||
}
|
||||
|
||||
packed_pixel_proxy& operator=(pixel p)
|
||||
{
|
||||
this->m_ref = (this->m_ref
|
||||
& ~(pixel::get_bit_mask() << this->m_shift))
|
||||
| (p << this->m_shift);
|
||||
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
/**
|
||||
* \brief The packed pixel row class template.
|
||||
*
|
||||
* Stores the pixel row as a std::vector of byte-s, providing
|
||||
* access to individual packed pixels via proxy objects.
|
||||
*/
|
||||
template< class pixel >
|
||||
class packed_pixel_row
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* \brief Constructs a pixel row object for \c size packed pixels.
|
||||
*/
|
||||
explicit packed_pixel_row(size_t size = 0)
|
||||
{
|
||||
resize(size);
|
||||
}
|
||||
|
||||
size_t size() const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Resizes the pixel row to hold up to \c size packed pixels.
|
||||
*/
|
||||
void resize(size_t size)
|
||||
{
|
||||
m_vec.resize(size / get_pixels_per_byte()
|
||||
+ (size % get_pixels_per_byte() ? 1 : 0));
|
||||
m_size = size;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief The immutable packed pixel proxy type.
|
||||
*/
|
||||
typedef detail::const_packed_pixel_proxy< pixel > const_pixel_proxy;
|
||||
|
||||
/**
|
||||
* \brief The mutable packed pixel proxy type.
|
||||
*/
|
||||
typedef detail::packed_pixel_proxy< pixel > pixel_proxy;
|
||||
|
||||
/**
|
||||
* \brief Returns an immutable proxy the to the pixel at \c
|
||||
* index.
|
||||
*/
|
||||
const_pixel_proxy at(size_t index) const
|
||||
{
|
||||
return const_pixel_proxy(m_vec.at(index / get_pixels_per_byte()),
|
||||
index);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns a mutable proxy the to the pixel at \c
|
||||
* index.
|
||||
*/
|
||||
pixel_proxy at(size_t index)
|
||||
{
|
||||
return pixel_proxy(m_vec.at(index / get_pixels_per_byte()),
|
||||
index);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns an immutable proxy the to the pixel at \c
|
||||
* index. The non-checking version.
|
||||
*/
|
||||
const_pixel_proxy operator[](size_t index) const
|
||||
{
|
||||
return const_pixel_proxy(m_vec[index / get_pixels_per_byte()],
|
||||
index);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns n mutable proxy the to the pixel at \c
|
||||
* index. The non-checking version.
|
||||
*/
|
||||
pixel_proxy operator[](size_t index)
|
||||
{
|
||||
return pixel_proxy(m_vec[index / get_pixels_per_byte()],
|
||||
index);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns the starting address of the row.
|
||||
*/
|
||||
byte* get_data()
|
||||
{
|
||||
assert(m_vec.size());
|
||||
return & m_vec[0];
|
||||
}
|
||||
|
||||
private:
|
||||
static size_t get_pixels_per_byte()
|
||||
{
|
||||
return 8 / pixel::get_bit_depth();
|
||||
}
|
||||
|
||||
std::vector< byte > m_vec;
|
||||
size_t m_size;
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief The row_traits class template specialization for packed
|
||||
* pixel row type.
|
||||
*/
|
||||
template< typename pixel >
|
||||
class row_traits< packed_pixel_row< pixel > >
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* \brief Returns the starting address of the row.
|
||||
*/
|
||||
static byte* get_data(packed_pixel_row< pixel >& row)
|
||||
{
|
||||
return row.get_data();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief The pixel buffer class template specialization for the
|
||||
* packed_gray_pixel type.
|
||||
*/
|
||||
template< size_t bits >
|
||||
class pixel_buffer< packed_gray_pixel< bits > >
|
||||
: public basic_pixel_buffer< packed_gray_pixel< bits >,
|
||||
packed_pixel_row< packed_gray_pixel
|
||||
< bits > > >
|
||||
{
|
||||
public:
|
||||
typedef packed_gray_pixel< bits > pixel_type;
|
||||
typedef packed_pixel_row< pixel_type > pixel_row_type;
|
||||
|
||||
pixel_buffer()
|
||||
{
|
||||
}
|
||||
|
||||
pixel_buffer(size_t width, size_t height)
|
||||
: basic_pixel_buffer< pixel_type,
|
||||
pixel_row_type >(width, height)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief The pixel buffer class template specialization for the
|
||||
* packed_index_pixel type.
|
||||
*/
|
||||
template< size_t bits >
|
||||
class pixel_buffer< packed_index_pixel< bits > >
|
||||
: public basic_pixel_buffer< packed_index_pixel< bits >,
|
||||
packed_pixel_row< packed_index_pixel
|
||||
< bits > > >
|
||||
{
|
||||
public:
|
||||
typedef packed_index_pixel< bits > pixel_type;
|
||||
typedef packed_pixel_row< pixel_type > pixel_row_type;
|
||||
|
||||
pixel_buffer()
|
||||
{
|
||||
}
|
||||
|
||||
pixel_buffer(size_t width, size_t height)
|
||||
: basic_pixel_buffer< pixel_type,
|
||||
pixel_row_type >(width, height)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_PIXEL_BUFFER_HPP_INCLUDED
|
99
src/png++-0.2.5/pixel_traits.hpp
Normal file
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
#ifndef PNGPP_PIXEL_TRAITS_HPP_INCLUDED
|
||||
#define PNGPP_PIXEL_TRAITS_HPP_INCLUDED
|
||||
|
||||
#include <limits>
|
||||
#include "types.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief Pixel traits class template.
|
||||
*
|
||||
* Provides information about pixel color type and components bit depth.
|
||||
* Not implemented--see specializations.
|
||||
*
|
||||
* \see pixel_traits<rgb_pixel>, pixel_traits<rgba_pixel>
|
||||
*/
|
||||
template< typename pixel > struct pixel_traits;
|
||||
|
||||
/**
|
||||
* \brief Basic pixel traits class template.
|
||||
*
|
||||
* Provides common implementation for various pixel_traits<>
|
||||
* specializations.
|
||||
*/
|
||||
template< typename pixel,
|
||||
typename component,
|
||||
color_type pixel_color_type,
|
||||
size_t channels = sizeof(pixel) / sizeof(component),
|
||||
size_t bit_depth = std::numeric_limits< component >::digits >
|
||||
struct basic_pixel_traits
|
||||
{
|
||||
typedef pixel pixel_type;
|
||||
typedef component component_type;
|
||||
|
||||
static color_type get_color_type()
|
||||
{
|
||||
return pixel_color_type;
|
||||
}
|
||||
static size_t get_channels()
|
||||
{
|
||||
return channels;
|
||||
}
|
||||
static size_t get_bit_depth()
|
||||
{
|
||||
return bit_depth;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Basic pixel traits class template for pixels with alpha
|
||||
* channel.
|
||||
*/
|
||||
template< typename component >
|
||||
struct basic_alpha_pixel_traits
|
||||
{
|
||||
/**
|
||||
* \brief Returns the default alpha channel filler for full
|
||||
* opacity.
|
||||
*/
|
||||
static component get_alpha_filler()
|
||||
{
|
||||
return std::numeric_limits< component >::max();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_PIXEL_TRAITS_HPP_INCLUDED
|
295
src/png++-0.2.5/png.hpp
Normal file
@ -0,0 +1,295 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
#ifndef PNGPP_PNG_HPP_INCLUDED
|
||||
#define PNGPP_PNG_HPP_INCLUDED
|
||||
|
||||
#include <png.h>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "types.hpp"
|
||||
#include "error.hpp"
|
||||
#include "color.hpp"
|
||||
#include "palette.hpp"
|
||||
#include "tRNS.hpp"
|
||||
#include "packed_pixel.hpp"
|
||||
#include "rgb_pixel.hpp"
|
||||
#include "rgba_pixel.hpp"
|
||||
#include "gray_pixel.hpp"
|
||||
#include "ga_pixel.hpp"
|
||||
#include "index_pixel.hpp"
|
||||
#include "info_base.hpp"
|
||||
#include "info.hpp"
|
||||
#include "end_info.hpp"
|
||||
#include "io_base.hpp"
|
||||
#include "reader.hpp"
|
||||
#include "writer.hpp"
|
||||
#include "generator.hpp"
|
||||
#include "consumer.hpp"
|
||||
#include "pixel_buffer.hpp"
|
||||
#include "require_color_space.hpp"
|
||||
#include "convert_color_space.hpp"
|
||||
#include "image.hpp"
|
||||
|
||||
/**
|
||||
* \mainpage
|
||||
*
|
||||
* \section sec_intro Introduction
|
||||
*
|
||||
* This is the documentation for png++ the C++ wrapper for libpng.
|
||||
* This page documents png++ version 0.2.
|
||||
*
|
||||
* PNG++ aims to provide simple yet powerful C++ interface to libpng,
|
||||
* the PNG reference implementation library. PNG++ is free software
|
||||
* distributed under a modified variant of BSD <a
|
||||
* href="http://www.nongnu.org/pngpp/license.html">license</a>.
|
||||
*
|
||||
* \section sec_news News
|
||||
*
|
||||
* - Added support for tRNS chunk.
|
||||
* - Added non-std IO streams support.
|
||||
* - Fixed 16-bit endianness problems.
|
||||
* - Improved test script.
|
||||
*
|
||||
* \section sec_getting_started Getting started
|
||||
*
|
||||
* The following code demonstrates how to read and write PNG images
|
||||
* using png++:
|
||||
*
|
||||
* \code
|
||||
* png::image< png::rgb_pixel > image("input.png");
|
||||
* image.write("output.png");
|
||||
* \endcode
|
||||
*
|
||||
* The code reads an image from the file named \c input.png, then
|
||||
* writes the image to a file named \c output.png. The image class
|
||||
* template allows you to specify the desired pixel type for the image
|
||||
* data. The available pixel types include: RGB, Grayscale and
|
||||
* Indexed pixels. Some of the pixel types can have an alpha channel.
|
||||
*
|
||||
* The png++ naturally supports reading PNG images of any %color type
|
||||
* into RGB or Grayscale pixel buffers (with optional alpha channel).
|
||||
* This is particularly useful for an image viewer if it needs to
|
||||
* display the PNG image on, for example, RGB device regardless of the
|
||||
* image %color type.
|
||||
*
|
||||
* On the other hand one might want to read only images of particular
|
||||
* type. With png++ you can specify it this way:
|
||||
*
|
||||
* \code
|
||||
* png::image< png::rgb_pixel > image("rgb.png", png::require_color_space< png::rgb_pixel >());
|
||||
* \endcode
|
||||
*
|
||||
* \section sec_installing Installing
|
||||
*
|
||||
* PNG++ comes as a set of header files and does not require
|
||||
* compilation to be installed. For the same reason there are no
|
||||
* binary packages for png++.
|
||||
*
|
||||
* \subsection subs_prerequisites Prerequisites
|
||||
*
|
||||
* - png++ works with libpng-1.2.x.
|
||||
* - png++ compiles with g++-4.1 and g++-4.2. Other version should
|
||||
* work well too.
|
||||
* - png++ relies on GNU make for compiling tests and examples; in
|
||||
* particular it uses "remaking makefiles" feature
|
||||
* - Documentation is produced using <a
|
||||
* href="http://www.doxygen.org/">doxygen</a>. See the bottom of
|
||||
* this page for doxygen version used to compile these docs.
|
||||
*
|
||||
* \subsection subs_installing_pngpp Installing png++
|
||||
*
|
||||
* Follow these instructions in order to install png++:
|
||||
*
|
||||
* -# Unpack source package:
|
||||
* \verbatim $ tar -zxf png++-0.2.x.tar.gz -C ~/src \endverbatim
|
||||
* -# Go to your brand new png++ sources directory:
|
||||
* \verbatim $ cd ~/src/png++-0.2.x \endverbatim
|
||||
* -# Issue \c make to test how it's doing:
|
||||
* \verbatim $ make \endverbatim
|
||||
* This will compile examples in the \c example directory. If everything
|
||||
* goes well, try \verbatim $ make test \endverbatim (or \c make \c
|
||||
* check which is the same as above) to run the test suite. If tests
|
||||
* do not produce error messages then probably all is OK.
|
||||
* -# Now you can create documentation (optional). Use
|
||||
* \verbatim $ make docs \endverbatim
|
||||
* to run \c doxygen in the sources directory.
|
||||
* -# Now it is time to become \c root and install png++ into your
|
||||
* system. It's OK to issue \c make \c install under ordinary user
|
||||
* permissions if you want to install png++ into your home
|
||||
* directory. Run the following command:
|
||||
* \verbatim $ make install PREFIX=$HOME \endverbatim
|
||||
* to copy png++ header files to \c ~/include/png++ and documentation
|
||||
* files to <tt>~/share/doc/png++-0.2.x</tt>. Without a \c PREFIX png++
|
||||
* installs to \c /usr/local.
|
||||
*
|
||||
* \section sec_working_with_images Working with images
|
||||
*
|
||||
* In png++ you can create new images like this:
|
||||
*
|
||||
* \code
|
||||
* #include <png++/png.hpp>
|
||||
* //...
|
||||
* png::image< png::rgb_pixel > image(128, 128);
|
||||
* for (size_t y = 0; y < image.get_height(); ++y)
|
||||
* {
|
||||
* for (size_t x = 0; x < image.get_width(); ++x)
|
||||
* {
|
||||
* image[y][x] = png::rgb_pixel(x, y, x + y);
|
||||
* // non-checking equivalent of image.set_pixel(x, y, ...);
|
||||
* }
|
||||
* }
|
||||
* image.write("rgb.png");
|
||||
* \endcode
|
||||
*
|
||||
* Optionally, you may specify
|
||||
* \code
|
||||
* image.set_interlace_type(png::interlace_adam7)
|
||||
* \endcode
|
||||
* to produce an interlaced image.
|
||||
*
|
||||
* If you are writing an indexed colors image, you should provide a
|
||||
* palette (colormap). One of the ways to do this is the following:
|
||||
*
|
||||
* \code
|
||||
* #include <png++/png.hpp>
|
||||
* //...
|
||||
* png::image< png::index_pixel > image;
|
||||
* png::palette pal(256);
|
||||
* for (size_t i = 0; i < pal.size(); ++i)
|
||||
* {
|
||||
* pal[i] = png::color(i, 255 - i, i);
|
||||
* }
|
||||
* image.set_palette(pal);
|
||||
* ...
|
||||
* image.write("palette.png");
|
||||
* \endcode
|
||||
*
|
||||
* It is not absolutely necessary to have the whole image data in
|
||||
* memory in order to write a PNG file. You can use generator class
|
||||
* template to write the image row-by-row. An example of this is
|
||||
* provided in \c example/pixel_generator.cpp bundled with the sources
|
||||
* package.
|
||||
*
|
||||
* The same holds for reading images too. You can use consumer class
|
||||
* template in order to read the image data row-by-row. This might
|
||||
* help in applications which have to deal with large PNG images but
|
||||
* do not want to read the entire image into memory.
|
||||
*
|
||||
* You can read or write images from/to generic IO stream, not only
|
||||
* file on disk. Check out \c image::read(std::istream&),
|
||||
* \c image::write(std::ostream&) overloads in the reference manual.
|
||||
*
|
||||
* \section sec_compiling_user Compiling your programs
|
||||
*
|
||||
* Use the following command to compile your program:
|
||||
*
|
||||
* \verbatim $ g++ -c example.cpp `libpng-config --cflags` \endverbatim
|
||||
*
|
||||
* and the following to link it:
|
||||
*
|
||||
* \verbatim $ g++ -o example example.o `libpng-config --ldflags` \endverbatim
|
||||
*
|
||||
* When compiling you should add \c -I \c $PREFIX/include if you have
|
||||
* installed png++ to non-standard location, like your home directory.
|
||||
*
|
||||
* In your program, the line
|
||||
*
|
||||
* \code
|
||||
* #include <png++/png.hpp>
|
||||
* \endcode
|
||||
*
|
||||
* brings in all the header files in png++ which should be suitable
|
||||
* for the most of the applications. You may include only the headers
|
||||
* you really use, for example:
|
||||
*
|
||||
* \code
|
||||
* #include <png++/image.hpp>
|
||||
* #include <png++/rgb_pixel.hpp>
|
||||
* \endcode
|
||||
*
|
||||
* If do not want to install png++ headers you still can compile your
|
||||
* programs. Just create a subdirectory named \c png++ somewhere in
|
||||
* your project tree and copy all of the \c .hpp files in png++
|
||||
* distribution there. Then use appropriate compiler options to add
|
||||
* this directory into the header search path.
|
||||
*
|
||||
* \section sec_further Further reading
|
||||
*
|
||||
* - To get information about specific features, use reference (can be
|
||||
* reached from the top of this page).
|
||||
* - If you are looking for more example code, please go to the \c
|
||||
* example/ directory of the source distribution. You may also find
|
||||
* sources in the \c test/ directory insightful (well, somewhat).
|
||||
* - Have a question? Check out \ref sec_help section below.
|
||||
* - Of course, your ultimate source for learning is the source
|
||||
* code. <tt>:-)</tt>
|
||||
*
|
||||
* \section sec_download Download
|
||||
*
|
||||
* The project is hosted at Savannah:
|
||||
* http://savannah.nongnu.org/projects/pngpp/
|
||||
*
|
||||
* Released source packages can be found here:
|
||||
* http://download.savannah.nongnu.org/releases/pngpp/
|
||||
*
|
||||
* Also, you can check out sources directly from SVN repository:
|
||||
* svn://svn.sv.nongnu.org/pngpp/trunk/ or
|
||||
* http://svn.sv.nongnu.org/pngpp/trunk/ (for people w/o outgoing svn).
|
||||
*
|
||||
* Online version of this documentation can be found here:
|
||||
* http://www.nongnu.org/pngpp/doc/0.2.3/index.html
|
||||
*
|
||||
* \section sec_bugs Bugs
|
||||
*
|
||||
* The following is a list of known bugs and limitations:
|
||||
*
|
||||
* - Lacks support for output transformations
|
||||
* - Lacks support for optional/unknown chunks in PNG data stream
|
||||
* - Documentation sucks <tt>;-)</tt>
|
||||
*
|
||||
* To report bugs, please use Savannah bug tracker:
|
||||
* http://savannah.nongnu.org/bugs/?group=pngpp&func=additem
|
||||
*
|
||||
* Do not forget to check if the bug was already filed. <tt>:-)</tt>
|
||||
*
|
||||
* \section sec_help Getting help
|
||||
*
|
||||
* There is a mailing list for developers:
|
||||
* http://lists.nongnu.org/mailman/listinfo/pngpp-devel
|
||||
*
|
||||
* You can also contact me by dropping a mail to <alex.shulgin@gmail.com>.
|
||||
*
|
||||
* Happy hacking!
|
||||
*
|
||||
* Alex Shulgin
|
||||
*/
|
||||
|
||||
#endif // PNGPP_PNG_HPP_INCLUDED
|
179
src/png++-0.2.5/reader.hpp
Normal file
@ -0,0 +1,179 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
#ifndef PNGPP_READER_HPP_INCLUDED
|
||||
#define PNGPP_READER_HPP_INCLUDED
|
||||
|
||||
#include <cassert>
|
||||
#include "io_base.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief The PNG reader class template. This is the low-level
|
||||
* reading interface--use image class or consumer class to
|
||||
* actually read images.
|
||||
*
|
||||
* The \c istream template parameter specifies the type of input
|
||||
* stream to work with. The \c istream class should implement the
|
||||
* minimum of the following interface:
|
||||
*
|
||||
* \code
|
||||
* class my_istream
|
||||
* {
|
||||
* public:
|
||||
* void read(char*, size_t);
|
||||
* bool good();
|
||||
* };
|
||||
* \endcode
|
||||
*
|
||||
* With the semantics similar to the \c std::istream. Naturally,
|
||||
* \c std::istream fits this requirement and can be used with the
|
||||
* reader class as is.
|
||||
*
|
||||
* \see image, consumer, writer, io_base
|
||||
*/
|
||||
template< class istream >
|
||||
class reader
|
||||
: public io_base
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* \brief Constructs a reader prepared to read PNG image from
|
||||
* a \a stream.
|
||||
*/
|
||||
explicit reader(istream& stream)
|
||||
: io_base(png_create_read_struct(PNG_LIBPNG_VER_STRING,
|
||||
static_cast< io_base* >(this),
|
||||
raise_error,
|
||||
0))
|
||||
{
|
||||
png_set_read_fn(m_png, & stream, read_data);
|
||||
}
|
||||
|
||||
~reader()
|
||||
{
|
||||
png_destroy_read_struct(& m_png,
|
||||
m_info.get_png_info_ptr(),
|
||||
m_end_info.get_png_info_ptr());
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Reads the whole PNG data stream into memory. Not
|
||||
* particularly useful.
|
||||
*/
|
||||
void read_png()
|
||||
{
|
||||
if (setjmp(png_jmpbuf(m_png)))
|
||||
{
|
||||
throw error(m_error);
|
||||
}
|
||||
png_read_png(m_png,
|
||||
m_info.get_png_info(),
|
||||
/* transforms = */ 0,
|
||||
/* params = */ 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Reads info about PNG image.
|
||||
*/
|
||||
void read_info()
|
||||
{
|
||||
if (setjmp(png_jmpbuf(m_png)))
|
||||
{
|
||||
throw error(m_error);
|
||||
}
|
||||
m_info.read();
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Reads a row of image data at a time.
|
||||
*/
|
||||
void read_row(byte* bytes)
|
||||
{
|
||||
if (setjmp(png_jmpbuf(m_png)))
|
||||
{
|
||||
throw error(m_error);
|
||||
}
|
||||
png_read_row(m_png, bytes, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Reads ending info about PNG image.
|
||||
*/
|
||||
void read_end_info()
|
||||
{
|
||||
if (setjmp(png_jmpbuf(m_png)))
|
||||
{
|
||||
throw error(m_error);
|
||||
}
|
||||
m_end_info.read();
|
||||
}
|
||||
|
||||
void update_info()
|
||||
{
|
||||
m_info.update();
|
||||
}
|
||||
|
||||
private:
|
||||
static void read_data(png_struct* png, byte* data, size_t length)
|
||||
{
|
||||
io_base* io = static_cast< io_base* >(png_get_error_ptr(png));
|
||||
reader* rd = static_cast< reader* >(io);
|
||||
rd->reset_error();
|
||||
istream* stream = reinterpret_cast< istream* >(png_get_io_ptr(png));
|
||||
try
|
||||
{
|
||||
stream->read(reinterpret_cast< char* >(data), length);
|
||||
if (!stream->good())
|
||||
{
|
||||
rd->set_error("istream::read() failed");
|
||||
}
|
||||
}
|
||||
catch (std::exception const& error)
|
||||
{
|
||||
rd->set_error(error.what());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
assert(!"read_data: caught something wrong");
|
||||
rd->set_error("read_data: caught something wrong");
|
||||
}
|
||||
if (rd->is_error())
|
||||
{
|
||||
rd->raise_error();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_READER_HPP_INCLUDED
|
171
src/png++-0.2.5/require_color_space.hpp
Normal file
@ -0,0 +1,171 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
#ifndef PNGPP_REQUIRE_COLOR_SPACE_HPP_INCLUDED
|
||||
#define PNGPP_REQUIRE_COLOR_SPACE_HPP_INCLUDED
|
||||
|
||||
#include "error.hpp"
|
||||
#include "rgb_pixel.hpp"
|
||||
#include "rgba_pixel.hpp"
|
||||
#include "gray_pixel.hpp"
|
||||
#include "ga_pixel.hpp"
|
||||
#include "index_pixel.hpp"
|
||||
#include "io_base.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template< typename pixel >
|
||||
struct wrong_color_space
|
||||
{
|
||||
inline static char const* error_msg();
|
||||
};
|
||||
|
||||
template<> inline char const*
|
||||
wrong_color_space< rgb_pixel >::error_msg()
|
||||
{
|
||||
return "8-bit RGB color space required";
|
||||
}
|
||||
|
||||
template<> inline char const*
|
||||
wrong_color_space< rgb_pixel_16 >::error_msg()
|
||||
{
|
||||
return "16-bit RGB color space required";
|
||||
}
|
||||
|
||||
template<> inline char const*
|
||||
wrong_color_space< rgba_pixel >::error_msg()
|
||||
{
|
||||
return "8-bit RGBA color space required";
|
||||
}
|
||||
|
||||
template<> inline char const*
|
||||
wrong_color_space< rgba_pixel_16 >::error_msg()
|
||||
{
|
||||
return "16-bit RGBA color space required";
|
||||
}
|
||||
|
||||
template<> inline char const*
|
||||
wrong_color_space< gray_pixel >::error_msg()
|
||||
{
|
||||
return "8-bit Grayscale color space required";
|
||||
}
|
||||
|
||||
template<> inline char const*
|
||||
wrong_color_space< gray_pixel_1 >::error_msg()
|
||||
{
|
||||
return "1-bit Grayscale color space required";
|
||||
}
|
||||
|
||||
template<> inline char const*
|
||||
wrong_color_space< gray_pixel_2 >::error_msg()
|
||||
{
|
||||
return "2-bit Grayscale color space required";
|
||||
}
|
||||
|
||||
template<> inline char const*
|
||||
wrong_color_space< gray_pixel_4 >::error_msg()
|
||||
{
|
||||
return "4-bit Grayscale color space required";
|
||||
}
|
||||
|
||||
template<> inline char const*
|
||||
wrong_color_space< gray_pixel_16 >::error_msg()
|
||||
{
|
||||
return "16-bit Grayscale color space required";
|
||||
}
|
||||
|
||||
template<> inline char const*
|
||||
wrong_color_space< ga_pixel >::error_msg()
|
||||
{
|
||||
return "8-bit Gray+Alpha color space required";
|
||||
}
|
||||
|
||||
template<> inline char const*
|
||||
wrong_color_space< ga_pixel_16 >::error_msg()
|
||||
{
|
||||
return "16-bit Gray+Alpha color space required";
|
||||
}
|
||||
|
||||
template<> inline char const*
|
||||
wrong_color_space< index_pixel >::error_msg()
|
||||
{
|
||||
return "8-bit Colormap color space required";
|
||||
}
|
||||
|
||||
template<> inline char const*
|
||||
wrong_color_space< index_pixel_1 >::error_msg()
|
||||
{
|
||||
return "1-bit Colormap color space required";
|
||||
}
|
||||
|
||||
template<> inline char const*
|
||||
wrong_color_space< index_pixel_2 >::error_msg()
|
||||
{
|
||||
return "2-bit Colormap color space required";
|
||||
}
|
||||
|
||||
template<> inline char const*
|
||||
wrong_color_space< index_pixel_4 >::error_msg()
|
||||
{
|
||||
return "4-bit Colormap color space required";
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
/**
|
||||
* \brief IO transformation class template. Enforces image color space.
|
||||
*
|
||||
* This IO transformation class template used to enforce source image
|
||||
* color space.
|
||||
*
|
||||
* \see image, image::read
|
||||
*/
|
||||
template< typename pixel >
|
||||
struct require_color_space
|
||||
{
|
||||
typedef pixel_traits< pixel > traits;
|
||||
|
||||
void operator()(io_base& io) const
|
||||
{
|
||||
if (io.get_color_type() != traits::get_color_type()
|
||||
|| io.get_bit_depth() != traits::get_bit_depth())
|
||||
{
|
||||
throw error(detail::wrong_color_space< pixel >::error_msg());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_REQUIRE_COLOR_SPACE_HPP_INCLUDED
|
90
src/png++-0.2.5/rgb_pixel.hpp
Normal file
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
#ifndef PNGPP_RGB_PIXEL_HPP_INCLUDED
|
||||
#define PNGPP_RGB_PIXEL_HPP_INCLUDED
|
||||
|
||||
#include "types.hpp"
|
||||
#include "pixel_traits.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief RGB pixel type.
|
||||
*/
|
||||
template< typename T >
|
||||
struct basic_rgb_pixel
|
||||
{
|
||||
/**
|
||||
* \brief Default constructor. Initializes all components
|
||||
* with zeros.
|
||||
*/
|
||||
basic_rgb_pixel()
|
||||
: red(0), green(0), blue(0)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Constructs rgb_pixel object from \a red, \a green
|
||||
* and \a blue components passed as parameters.
|
||||
*/
|
||||
basic_rgb_pixel(T red, T green, T blue)
|
||||
: red(red), green(green), blue(blue)
|
||||
{
|
||||
}
|
||||
|
||||
T red;
|
||||
T green;
|
||||
T blue;
|
||||
};
|
||||
|
||||
/**
|
||||
* The 8-bit RGB pixel type.
|
||||
*/
|
||||
typedef basic_rgb_pixel< byte > rgb_pixel;
|
||||
|
||||
/**
|
||||
* The 16-bit RGB pixel type.
|
||||
*/
|
||||
typedef basic_rgb_pixel< uint_16 > rgb_pixel_16;
|
||||
|
||||
/**
|
||||
* \brief Pixel traits specialization for basic_rgb_pixel.
|
||||
*/
|
||||
template< typename T >
|
||||
struct pixel_traits< basic_rgb_pixel< T > >
|
||||
: basic_pixel_traits< basic_rgb_pixel< T >, T, color_type_rgb >
|
||||
{
|
||||
};
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_RGB_PIXEL_HPP_INCLUDED
|
96
src/png++-0.2.5/rgba_pixel.hpp
Normal file
@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
#ifndef PNGPP_RGBA_PIXEL_HPP_INCLUDED
|
||||
#define PNGPP_RGBA_PIXEL_HPP_INCLUDED
|
||||
|
||||
#include "types.hpp"
|
||||
#include "pixel_traits.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief RGBA pixel type.
|
||||
*/
|
||||
template< typename T >
|
||||
struct basic_rgba_pixel
|
||||
{
|
||||
typedef pixel_traits< basic_rgba_pixel< T > > traits;
|
||||
|
||||
/**
|
||||
* \brief Default constructor. Initializes all components
|
||||
* with zeros.
|
||||
*/
|
||||
basic_rgba_pixel()
|
||||
: red(0), green(0), blue(0), alpha(0)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Constructs rgba_pixel object from \a red, \a green,
|
||||
* \a blue and \a alpha components passed as parameters.
|
||||
* Alpha defaults to full opacity.
|
||||
*/
|
||||
basic_rgba_pixel(T red, T green, T blue,
|
||||
T alpha = traits::get_alpha_filler())
|
||||
: red(red), green(green), blue(blue), alpha(alpha)
|
||||
{
|
||||
}
|
||||
|
||||
T red;
|
||||
T green;
|
||||
T blue;
|
||||
T alpha;
|
||||
};
|
||||
|
||||
/**
|
||||
* The 8-bit RGBA pixel type.
|
||||
*/
|
||||
typedef basic_rgba_pixel< byte > rgba_pixel;
|
||||
|
||||
/**
|
||||
* The 16-bit RGBA pixel type.
|
||||
*/
|
||||
typedef basic_rgba_pixel< uint_16 > rgba_pixel_16;
|
||||
|
||||
/**
|
||||
* \brief Pixel traits specialization for basic_rgba_pixel.
|
||||
*/
|
||||
template< typename T >
|
||||
struct pixel_traits< basic_rgba_pixel< T > >
|
||||
: basic_pixel_traits< basic_rgba_pixel< T >, T, color_type_rgba >,
|
||||
basic_alpha_pixel_traits< T >
|
||||
{
|
||||
};
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_RGBA_PIXEL_HPP_INCLUDED
|
128
src/png++-0.2.5/streaming_base.hpp
Normal file
@ -0,0 +1,128 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
#ifndef PNGPP_STREAMING_BASE_HPP_INCLUDED
|
||||
#define PNGPP_STREAMING_BASE_HPP_INCLUDED
|
||||
|
||||
#include <cassert>
|
||||
#include "image_info.hpp"
|
||||
#include "pixel_traits.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief The default image_info holder class. Stores image_info
|
||||
* member object.
|
||||
*/
|
||||
class def_image_info_holder
|
||||
{
|
||||
public:
|
||||
def_image_info_holder(image_info const& info)
|
||||
: m_info(info)
|
||||
{
|
||||
}
|
||||
|
||||
image_info& get_info()
|
||||
{
|
||||
return m_info;
|
||||
}
|
||||
|
||||
private:
|
||||
image_info m_info;
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief An image_info holder class. Stores a reference to the
|
||||
* image_info object. The image_info object itself should be
|
||||
* stored elsewhere.
|
||||
*/
|
||||
class image_info_ref_holder
|
||||
{
|
||||
public:
|
||||
image_info_ref_holder(image_info& info)
|
||||
: m_info(info)
|
||||
{
|
||||
}
|
||||
|
||||
image_info& get_info()
|
||||
{
|
||||
return m_info;
|
||||
}
|
||||
|
||||
private:
|
||||
image_info& m_info;
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief A base class template for consumer and generator
|
||||
* classes. Provides default \c reset() method implementation as
|
||||
* well as \c info_holder policy.
|
||||
*/
|
||||
template< typename pixel, class info_holder >
|
||||
class streaming_base
|
||||
{
|
||||
public:
|
||||
typedef pixel_traits< pixel > traits;
|
||||
|
||||
explicit streaming_base(image_info& info)
|
||||
: m_info_holder(info)
|
||||
{
|
||||
}
|
||||
|
||||
streaming_base(size_t width, size_t height)
|
||||
: m_info_holder(make_image_info< pixel >())
|
||||
{
|
||||
get_info().set_width(width);
|
||||
get_info().set_height(height);
|
||||
}
|
||||
|
||||
image_info const& get_info() const
|
||||
{
|
||||
return m_info_holder.get_info();
|
||||
}
|
||||
|
||||
protected:
|
||||
void reset(size_t /*pass*/)
|
||||
{
|
||||
// nothing to do in the most general case
|
||||
}
|
||||
|
||||
image_info& get_info()
|
||||
{
|
||||
return m_info_holder.get_info();
|
||||
}
|
||||
|
||||
info_holder m_info_holder;
|
||||
};
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_STREAMING_BASE_HPP_INCLUDED
|
48
src/png++-0.2.5/tRNS.hpp
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (C) 2007,2008 Alex Shulgin
|
||||
*
|
||||
* This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
* software; the exact copying conditions are as follows:
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
#ifndef PNGPP_TRNS_HPP_INCLUDED
|
||||
#define PNGPP_TRNS_HPP_INCLUDED
|
||||
|
||||
#include <vector>
|
||||
#include "color.hpp"
|
||||
|
||||
namespace png
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief The palette transparency map type. Currently
|
||||
* implemented as \c std::vector of png::byte.
|
||||
*/
|
||||
typedef std::vector< byte > tRNS;
|
||||
|
||||
} // namespace png
|
||||
|
||||
#endif // PNGPP_TRNS_HPP_INCLUDED
|
100
src/png++-0.2.5/test/Makefile
Normal file
@ -0,0 +1,100 @@
|
||||
#
|
||||
# Copyright (C) 2007,2008 Alex Shulgin
|
||||
#
|
||||
# This file is part of png++ the C++ wrapper for libpng. PNG++ is free
|
||||
# software; the exact copying conditions are as follows:
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 3. The name of the author may not be used to endorse or promote products
|
||||
# derived from this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
#
|
||||
ifndef PREFIX
|
||||
PREFIX := /usr/local
|
||||
endif
|
||||
|
||||
ifndef PNGPP
|
||||
PNGPP := ..
|
||||
endif
|
||||
|
||||
make_cflags := -Wall $(CFLAGS) -I$(PREFIX)/include -I$(PNGPP)
|
||||
make_ldflags := $(LDFLAGS) -L$(PREFIX)/lib
|
||||
|
||||
ifndef NDEBUG
|
||||
make_cflags := $(make_cflags) -g
|
||||
make_ldflags := $(make_ldflags) -g
|
||||
endif
|
||||
|
||||
ifndef LIBPNG_CONFIG
|
||||
LIBPNG_CONFIG := libpng-config
|
||||
endif
|
||||
|
||||
sources := convert_color_space.cpp \
|
||||
generate_gray_packed.cpp \
|
||||
read_write_gray_packed.cpp \
|
||||
generate_palette.cpp \
|
||||
write_gray_16.cpp \
|
||||
read_write_param.cpp \
|
||||
dump.cpp
|
||||
|
||||
deps := $(sources:.cpp=.dep)
|
||||
objects := $(sources:.cpp=.o)
|
||||
targets := $(sources:.cpp=$(bin_suffix))
|
||||
|
||||
all: $(deps) $(targets)
|
||||
|
||||
dist-copy-files:
|
||||
mkdir $(dist_dir)/test
|
||||
cp -r $(sources) Makefile test.sh README cmp $(dist_dir)/test
|
||||
tar cf - pngsuite --exclude=\*.out | tar xf - -C $(dist_dir)/test
|
||||
|
||||
clean: clean-targets clean-tests-output clean-deps
|
||||
|
||||
clean-targets:
|
||||
rm -f $(targets) $(objects)
|
||||
|
||||
test: all
|
||||
./test.sh
|
||||
|
||||
clean-tests-output:
|
||||
rm -f *.out pngsuite/*.out
|
||||
|
||||
.PHONY: all dist-copy-files \
|
||||
clean clean-targets \
|
||||
test test-convert_color_space \
|
||||
clean-tests-output \
|
||||
clean-deps
|
||||
|
||||
%$(bin_suffix): %.o
|
||||
g++ -o $@ $< $(make_ldflags) `$(LIBPNG_CONFIG) --ldflags`
|
||||
|
||||
%.o: %.cpp
|
||||
g++ -c -o $@ $< $(make_cflags) `$(LIBPNG_CONFIG) --cflags`
|
||||
|
||||
%.dep: %.cpp
|
||||
g++ -M $(CPPFLAGS) $(make_cflags) $< -o- | \
|
||||
sed 's/\($*\)\.o[ :]*/\1.o $@ : /g' > $@
|
||||
|
||||
clean-deps:
|
||||
rm -f $(deps)
|
||||
|
||||
include $(deps)
|
85
src/png++-0.2.5/test/README
Normal file
@ -0,0 +1,85 @@
|
||||
|
||||
pngsuite
|
||||
--------
|
||||
(c) Willem van Schaik, 1999
|
||||
|
||||
Permission to use, copy, and distribute these images for any purpose and
|
||||
without fee is hereby granted.
|
||||
|
||||
These 15 images are part of the much larger PngSuite test-set of
|
||||
images, available for developers of PNG supporting software. The
|
||||
complete set, available at http:/www.schaik.com/pngsuite/, contains
|
||||
a variety of images to test interlacing, gamma settings, ancillary
|
||||
chunks, etc.
|
||||
|
||||
The images in this directory represent the basic PNG color-types:
|
||||
grayscale (1-16 bit deep), full color (8 or 16 bit), paletted
|
||||
(1-8 bit) and grayscale or color images with alpha channel. You
|
||||
can use them to test the proper functioning of PNG software.
|
||||
|
||||
filename depth type
|
||||
------------ ------ --------------
|
||||
basn0g01.png 1-bit grayscale
|
||||
basn0g02.png 2-bit grayscale
|
||||
basn0g04.png 4-bit grayscale
|
||||
basn0g08.png 8-bit grayscale
|
||||
basn0g16.png 16-bit grayscale
|
||||
basn2c08.png 8-bit truecolor
|
||||
basn2c16.png 16-bit truecolor
|
||||
basn3p01.png 1-bit paletted
|
||||
basn3p02.png 2-bit paletted
|
||||
basn3p04.png 4-bit paletted
|
||||
basn3p08.png 8-bit paletted
|
||||
basn4a08.png 8-bit gray with alpha
|
||||
basn4a16.png 16-bit gray with alpha
|
||||
basn6a08.png 8-bit RGBA
|
||||
basn6a16.png 16-bit RGBA
|
||||
|
||||
Here is the correct result of typing "pngtest -m *.png" in
|
||||
this directory:
|
||||
|
||||
Testing basn0g01.png: PASS (524 zero samples)
|
||||
Filter 0 was used 32 times
|
||||
Testing basn0g02.png: PASS (448 zero samples)
|
||||
Filter 0 was used 32 times
|
||||
Testing basn0g04.png: PASS (520 zero samples)
|
||||
Filter 0 was used 32 times
|
||||
Testing basn0g08.png: PASS (3 zero samples)
|
||||
Filter 1 was used 9 times
|
||||
Filter 4 was used 23 times
|
||||
Testing basn0g16.png: PASS (1 zero samples)
|
||||
Filter 1 was used 1 times
|
||||
Filter 2 was used 31 times
|
||||
Testing basn2c08.png: PASS (6 zero samples)
|
||||
Filter 1 was used 5 times
|
||||
Filter 4 was used 27 times
|
||||
Testing basn2c16.png: PASS (592 zero samples)
|
||||
Filter 1 was used 1 times
|
||||
Filter 4 was used 31 times
|
||||
Testing basn3p01.png: PASS (512 zero samples)
|
||||
Filter 0 was used 32 times
|
||||
Testing basn3p02.png: PASS (448 zero samples)
|
||||
Filter 0 was used 32 times
|
||||
Testing basn3p04.png: PASS (544 zero samples)
|
||||
Filter 0 was used 32 times
|
||||
Testing basn3p08.png: PASS (4 zero samples)
|
||||
Filter 0 was used 32 times
|
||||
Testing basn4a08.png: PASS (32 zero samples)
|
||||
Filter 1 was used 1 times
|
||||
Filter 4 was used 31 times
|
||||
Testing basn4a16.png: PASS (64 zero samples)
|
||||
Filter 0 was used 1 times
|
||||
Filter 1 was used 2 times
|
||||
Filter 2 was used 1 times
|
||||
Filter 4 was used 28 times
|
||||
Testing basn6a08.png: PASS (160 zero samples)
|
||||
Filter 1 was used 1 times
|
||||
Filter 4 was used 31 times
|
||||
Testing basn6a16.png: PASS (1072 zero samples)
|
||||
Filter 1 was used 4 times
|
||||
Filter 4 was used 28 times
|
||||
libpng passes test
|
||||
|
||||
Willem van Schaik
|
||||
<willem@schaik.com>
|
||||
October 1999
|
BIN
src/png++-0.2.5/test/cmp/gray_16.out
Normal file
After Width: | Height: | Size: 35 KiB |
BIN
src/png++-0.2.5/test/cmp/gray_packed_1.png.out
Normal file
After Width: | Height: | Size: 75 B |
BIN
src/png++-0.2.5/test/cmp/gray_packed_2.png.out
Normal file
After Width: | Height: | Size: 83 B |
BIN
src/png++-0.2.5/test/cmp/gray_packed_4.png.out
Normal file
After Width: | Height: | Size: 148 B |
BIN
src/png++-0.2.5/test/cmp/palette1.png.out
Normal file
After Width: | Height: | Size: 85 B |
BIN
src/png++-0.2.5/test/cmp/palette2.png.out
Normal file
After Width: | Height: | Size: 93 B |
BIN
src/png++-0.2.5/test/cmp/palette4.png.out
Normal file
After Width: | Height: | Size: 158 B |
BIN
src/png++-0.2.5/test/cmp/palette8.png.out
Normal file
After Width: | Height: | Size: 1.4 KiB |
BIN
src/png++-0.2.5/test/cmp/palette8_tRNS.png.out
Normal file
After Width: | Height: | Size: 1.6 KiB |
BIN
src/png++-0.2.5/test/cmp/pngsuite/basi0g01.png.GA.16.out
Normal file
After Width: | Height: | Size: 378 B |
BIN
src/png++-0.2.5/test/cmp/pngsuite/basi0g01.png.GA.8.out
Normal file
After Width: | Height: | Size: 330 B |
BIN
src/png++-0.2.5/test/cmp/pngsuite/basi0g01.png.GRAY.16.out
Normal file
After Width: | Height: | Size: 303 B |
BIN
src/png++-0.2.5/test/cmp/pngsuite/basi0g01.png.GRAY.8.out
Normal file
After Width: | Height: | Size: 255 B |
BIN
src/png++-0.2.5/test/cmp/pngsuite/basi0g01.png.RGB.16.out
Normal file
After Width: | Height: | Size: 386 B |
BIN
src/png++-0.2.5/test/cmp/pngsuite/basi0g01.png.RGB.8.out
Normal file
After Width: | Height: | Size: 344 B |
BIN
src/png++-0.2.5/test/cmp/pngsuite/basi0g01.png.RGBA.16.out
Normal file
After Width: | Height: | Size: 438 B |
BIN
src/png++-0.2.5/test/cmp/pngsuite/basi0g01.png.RGBA.8.out
Normal file
After Width: | Height: | Size: 390 B |
BIN
src/png++-0.2.5/test/cmp/pngsuite/basi0g02.png.GA.16.out
Normal file
After Width: | Height: | Size: 227 B |
BIN
src/png++-0.2.5/test/cmp/pngsuite/basi0g02.png.GA.8.out
Normal file
After Width: | Height: | Size: 199 B |
BIN
src/png++-0.2.5/test/cmp/pngsuite/basi0g02.png.GRAY.16.out
Normal file
After Width: | Height: | Size: 191 B |
BIN
src/png++-0.2.5/test/cmp/pngsuite/basi0g02.png.GRAY.8.out
Normal file
After Width: | Height: | Size: 171 B |
BIN
src/png++-0.2.5/test/cmp/pngsuite/basi0g02.png.RGB.16.out
Normal file
After Width: | Height: | Size: 259 B |
BIN
src/png++-0.2.5/test/cmp/pngsuite/basi0g02.png.RGB.8.out
Normal file
After Width: | Height: | Size: 228 B |
BIN
src/png++-0.2.5/test/cmp/pngsuite/basi0g02.png.RGBA.16.out
Normal file
After Width: | Height: | Size: 278 B |
BIN
src/png++-0.2.5/test/cmp/pngsuite/basi0g02.png.RGBA.8.out
Normal file
After Width: | Height: | Size: 233 B |
BIN
src/png++-0.2.5/test/cmp/pngsuite/basi0g04.png.GA.16.out
Normal file
After Width: | Height: | Size: 175 B |
BIN
src/png++-0.2.5/test/cmp/pngsuite/basi0g04.png.GA.8.out
Normal file
After Width: | Height: | Size: 151 B |
BIN
src/png++-0.2.5/test/cmp/pngsuite/basi0g04.png.GRAY.16.out
Normal file
After Width: | Height: | Size: 159 B |
BIN
src/png++-0.2.5/test/cmp/pngsuite/basi0g04.png.GRAY.8.out
Normal file
After Width: | Height: | Size: 146 B |
BIN
src/png++-0.2.5/test/cmp/pngsuite/basi0g04.png.RGB.16.out
Normal file
After Width: | Height: | Size: 204 B |
BIN
src/png++-0.2.5/test/cmp/pngsuite/basi0g04.png.RGB.8.out
Normal file
After Width: | Height: | Size: 174 B |
BIN
src/png++-0.2.5/test/cmp/pngsuite/basi0g04.png.RGBA.16.out
Normal file
After Width: | Height: | Size: 220 B |
BIN
src/png++-0.2.5/test/cmp/pngsuite/basi0g04.png.RGBA.8.out
Normal file
After Width: | Height: | Size: 178 B |
BIN
src/png++-0.2.5/test/cmp/pngsuite/basi0g08.png.GA.16.out
Normal file
After Width: | Height: | Size: 307 B |
BIN
src/png++-0.2.5/test/cmp/pngsuite/basi0g08.png.GA.8.out
Normal file
After Width: | Height: | Size: 276 B |
BIN
src/png++-0.2.5/test/cmp/pngsuite/basi0g08.png.GRAY.16.out
Normal file
After Width: | Height: | Size: 259 B |
BIN
src/png++-0.2.5/test/cmp/pngsuite/basi0g08.png.GRAY.8.out
Normal file
After Width: | Height: | Size: 238 B |
BIN
src/png++-0.2.5/test/cmp/pngsuite/basi0g08.png.RGB.16.out
Normal file
After Width: | Height: | Size: 393 B |
BIN
src/png++-0.2.5/test/cmp/pngsuite/basi0g08.png.RGB.8.out
Normal file
After Width: | Height: | Size: 328 B |
BIN
src/png++-0.2.5/test/cmp/pngsuite/basi0g08.png.RGBA.16.out
Normal file
After Width: | Height: | Size: 443 B |
BIN
src/png++-0.2.5/test/cmp/pngsuite/basi0g08.png.RGBA.8.out
Normal file
After Width: | Height: | Size: 375 B |
BIN
src/png++-0.2.5/test/cmp/pngsuite/basi0g16.png.GA.16.out
Normal file
After Width: | Height: | Size: 325 B |
BIN
src/png++-0.2.5/test/cmp/pngsuite/basi0g16.png.GA.8.out
Normal file
After Width: | Height: | Size: 267 B |
BIN
src/png++-0.2.5/test/cmp/pngsuite/basi0g16.png.GRAY.16.out
Normal file
After Width: | Height: | Size: 283 B |
BIN
src/png++-0.2.5/test/cmp/pngsuite/basi0g16.png.GRAY.8.out
Normal file
After Width: | Height: | Size: 242 B |
BIN
src/png++-0.2.5/test/cmp/pngsuite/basi0g16.png.RGB.16.out
Normal file
After Width: | Height: | Size: 386 B |
BIN
src/png++-0.2.5/test/cmp/pngsuite/basi0g16.png.RGB.8.out
Normal file
After Width: | Height: | Size: 331 B |
BIN
src/png++-0.2.5/test/cmp/pngsuite/basi0g16.png.RGBA.16.out
Normal file
After Width: | Height: | Size: 434 B |
BIN
src/png++-0.2.5/test/cmp/pngsuite/basi0g16.png.RGBA.8.out
Normal file
After Width: | Height: | Size: 367 B |
BIN
src/png++-0.2.5/test/cmp/pngsuite/basi2c08.png.GA.16.out
Normal file
After Width: | Height: | Size: 445 B |
BIN
src/png++-0.2.5/test/cmp/pngsuite/basi2c08.png.GA.8.out
Normal file
After Width: | Height: | Size: 383 B |
BIN
src/png++-0.2.5/test/cmp/pngsuite/basi2c08.png.GRAY.16.out
Normal file
After Width: | Height: | Size: 372 B |
BIN
src/png++-0.2.5/test/cmp/pngsuite/basi2c08.png.GRAY.8.out
Normal file
After Width: | Height: | Size: 327 B |