示例#1
0
void Image::read_png(const char* filename)
{
    std::vector<unsigned char> buffer, image;
    //load the image file with given filename
    LodePNG::loadFile(buffer, filename);

    //decode the png
    LodePNG::Decoder decoder;
    decoder.decode(image, buffer.empty() ? 0 : &buffer[0], (unsigned)buffer.size());

    if (decoder.getChannels()<3 || decoder.getBpp()<24) {
        cerr << "Error: only color (RGBA), 8 bit per channel png images are supported." << endl;
        cerr << "Either convert your image or change the sourcecode." << endl;
        exit(1);
    }
    int w = decoder.getWidth();
    int h = decoder.getHeight();
    set_extent(w,h);

    // now convert the image data
    std::vector<unsigned char>::iterator imageIterator = image.begin();
    Color *currentPixel = _pixel;
    while (imageIterator != image.end()) {
        currentPixel->r = (*imageIterator)/255.0;
        imageIterator++;
        currentPixel->g = (*imageIterator)/255.0;
        imageIterator++;
        currentPixel->b = (*imageIterator)/255.0;
        imageIterator++;
        // Let's just ignore the alpha channel
        imageIterator++; 
        currentPixel++;
    }	
}
示例#2
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;
}
示例#3
0
 //lodepng용 추가 함수
 static void PrintLog(LodePNG::Decoder &decoder) {
   if(decoder.hasError()) {
     std::cout << "error " << decoder.getError() << ": " << LodePNG_error_text(decoder.getError()) << std::endl;
   } else {
     std::cout << "\n" <<
       "w: " << decoder.getWidth() << "\n" <<
       "h: " << decoder.getHeight() << "\n" <<
       "bitDepth: " << decoder.getInfoPng().color.bitDepth << "\n" <<
       "bpp: " << decoder.getBpp() << "\n" <<
       "colorChannels: " << decoder.getChannels() << "\n" <<
       "paletteSize: " << decoder.getInfoPng().color.palettesize / 4 << "\n" <<
       "colorType: " << decoder.getInfoPng().color.colorType << "\n" <<
       "compressionMethod: " << decoder.getInfoPng().compressionMethod << "\n" <<
       "filterMethod: " << decoder.getInfoPng().filterMethod << "\n" <<
       "interlaceMethod: " << decoder.getInfoPng().interlaceMethod << "\n";
     for(size_t i = 0; i < decoder.getInfoPng().text.num; i++) {
       std::cout << decoder.getInfoPng().text.keys[i] << ": " << decoder.getInfoPng().text.strings[i] << "\n";
     }
   }
 }
示例#4
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;
    }
  }