Beispiel #1
0
bool ProceduralTexture::loadPNG(char *png_map)
{
	LodePNG::Decoder pngDecoder;
	std::vector<unsigned char> buffer;
	
	Logger::log("Loading png file %s..\n",png_map);
	
	LodePNG::loadFile(buffer,png_map);
	
	Logger::log("Calling PNG decoder..\n");
	pngDecoder.decode(image, buffer);
	
	Logger::log("Checking decoder state..\n");
	if(pngDecoder.hasError())
	{
		Logger::log("[loadTextureFromPng] Error %d\n", pngDecoder.getError());
		Logger::log(" while trying to load \'%s\'\n",png_map);
		return false;
	}
	
	width = pngDecoder.getWidth();
	height = pngDecoder.getHeight();
	
	Logger::log("PNG Decoder Info [ width: %d, height: %d ]..\n",width,height);
	
	Logger::log("image size: %d\n",image.size());
	
	Logger::log("isGreyScale: %s\n",pngDecoder.isGreyscaleType()?"true":"false");
	Logger::log("isAlphaType: %s\n",pngDecoder.isAlphaType()?"true":"false");
	Logger::log("Channels: %d\n",pngDecoder.getChannels());
	Logger::log("BPP: %d\n",pngDecoder.getBpp());
		
	return true;
}
Beispiel #2
0
// Load image from file [true = success, false otherwise]
bool PNG::load(string pathname){
	std::vector<unsigned char> buffer;
	LodePNG::loadFile(buffer, pathname); //load the image file with given filename
	LodePNG::Decoder decoder;
	decoder.inspect(buffer);
	if (decoder.isGreyscaleType()){
		decoder.getInfoRaw().color.colorType = 0;
		decoder.getInfoRaw().color.bitDepth = 16;
		// is grayscale

	}
	decoder.decode(image, buffer);
	width  = decoder.getWidth(); 
	height = decoder.getHeight();
	if(decoder.hasError())
	  {
		return false;
	  }
	return true;
}
Beispiel #3
0
  static bool Load(Image *img, ImageDesc *desc, uchar *data, int data_size) {
    //lodepng를 기반으로 적절히 로딩하기  
    SR_ASSERT(data != NULL);
    SR_ASSERT(data_size > 0);
    img->image_data_.clear();

    LodePNG::Decoder decoder;
    decoder.decode(img->image_data(), data, data_size);
    if(decoder.hasError()) { 
      return false;

    } else {
      desc->width = decoder.getWidth();
      desc->height = decoder.getHeight();
      desc->bit_depth = decoder.getInfoPng().color.bitDepth;
      desc->bpp = decoder.getBpp();
      desc->color_channels = decoder.getChannels();
      desc->is_grayscale = decoder.isGreyscaleType() > 0 ? true : false;
      desc->is_alpha = decoder.isAlphaType() > 0 ? true : false;

      return true;
    }
  }