本文整理汇总了C++中PNG::load方法的典型用法代码示例。如果您正苦于以下问题:C++ PNG::load方法的具体用法?C++ PNG::load怎么用?C++ PNG::load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PNG
的用法示例。
在下文中一共展示了PNG::load方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: rx_load_png
bool rx_load_png(Image& img, std::string filename, bool datapath) {
PNG png;
if(!png.load(filename, datapath)) {
return false;
}
switch(png.getColorType()) {
case PNG_COLOR_TYPE_GRAY: {
img.setPixelFormat(RX_FMT_GRAY8);
break;
}
case PNG_COLOR_TYPE_RGB: {
img.setPixelFormat(RX_FMT_RGB24);
break;
}
case PNG_COLOR_TYPE_RGB_ALPHA: {
img.setPixelFormat(RX_FMT_RGBA32);
break;
}
default: {
RX_ERROR(PNG_ERR_UNSUPPORTED_FORMAT);
return false;
}
}
img.setWidth(png.getWidth());
img.setHeight(png.getHeight());
return img.copyPixels(png.getPixels(), png.getWidth(), png.getHeight(), img.getPixelFormat());
}
示例2: loadHeightMap
void Terrain::loadHeightMap(string filename, int res_x, int res_y)
{
PNG inputFile;
inputFile.load(filename);
dim_x = inputFile.width;
dim_y = inputFile.height;
unsigned char * data = inputFile.getData();
int size = dim_x*dim_y;
float * originalHeightMap = new float[size];
int i,x,y;
for (i=0; i<size; i++){
originalHeightMap[i] = 256*data[2*i]+data[2*i + 1];
}
// recalculate to the given resolution (use linear interpolation...)
size = res_x*res_y;
heightMap = new float[size];
float step_x = float(dim_x)/float(res_x);
float step_y = float(dim_y)/float(res_y);
for(x=0; x<res_x; x++)
{
for(y=0; y<res_y; y++)
{
heightMap[x*res_y + y] = getHeightAt(originalHeightMap, dim_x, dim_y, float(x*step_x), float(y*step_y));
}
}
SAFE_DELETE_ARRAY_PTR(originalHeightMap);
}
示例3: loadFromFiles
bool CTdata::loadFromFiles(const char * filename, int cnt, int scaleX, int scaleY, int scaleZ){
int divide = 2;
int chars = 0;
scX = scaleX;
scY = scaleY;
scZ = scaleZ/divide;
char filen [50];
unsigned char * rawData;
PNG ctfile;
int width=0, height=0, width2, height2;
int x,y,z;
float val;
for(z=0; z<cnt; z++){
sprintf(filen, filename, z+1);
ctfile.clear();
if (!ctfile.load(filen)){
return false;
}
rawData = ctfile.getData();
height = ctfile.height;
width = ctfile.width;
width2 = width/float(divide);
height2 = height/float(divide);
if (data==NULL){
data = new float[cnt*width2*height2]; //data = new float[cnt*width*height];
}
for (y=0; y<height2; y++){ //height
for (x=0; x<width2; x++){ //width
// 2x 8-bit to 1x 16-bit
val = 256*rawData[(2*y*width + 2*x)*divide]+rawData[(2*y*width + 2*x)*divide + 1]; //val = 256*rawData[2*y*width + 2*x]+rawData[2*y*width + 2*x + 1];
// save in array
data[z*height2*width2 + y*width2 +(width2-1-x)] = val; //data[z*width*height + y*width +x] = val;
}
}
BACKSPACE(chars);
chars = printf("LOADING CT images: %03i %%",((z+1)*100)/cnt);
}
dimX = width2;
dimY = height2;
dimZ = cnt;
szX = dimX * scX;
szY = dimY * scY;
szZ = dimZ * scZ;
center.x = szX/2.0;
center.y = szY/2.0;
center.z = szZ/2.0;
// backspace...
BACKSPACE(chars);
printf("LOADING CT images (%i) DONE\n", cnt);
return true;
}