Пример #1
0
bool Image::writePNGMem( unsigned char **out, size_t *outsize ) {
    assertmsg( buffer!=0 , "image not initialized?" );
    assertmsg( width <= 2048 && height <= 2048, "image too big" );
    unsigned error;
    error = lodepng_encode32( out, outsize, buffer, width, height );
    if(error) {
        fprintf(stderr, "lodepng_encode32_file failed%d", error );
        return false;
    }
    return true;        
}
Пример #2
0
int LodePngCoder::Encode(unsigned char** out, int* outsize, const unsigned char* image, unsigned w, unsigned h) {

  if (!image) return -1;

  int res = lodepng_encode32(out,(size_t *)outsize, image, w, h);
  if (res != 0) {
    LOG_I( "[LodePngCoder] fail to encode png, error:%d, %s", res, lodepng_error_text(res));
  }

  return res;
}
Пример #3
0
/*
Example 2
Encode from raw pixels to an in-memory PNG file first, then write it to disk
The image argument has width * height RGBA pixels or width * height * 4 bytes
*/
void encodeTwoSteps(const char* filename, const unsigned char* image, unsigned width, unsigned height)
{
  unsigned char* png;
  size_t pngsize;

  unsigned error = lodepng_encode32(&png, &pngsize, image, width, height);
  if(!error) lodepng_save_file(png, pngsize, filename);

  /*if there's an error, display it*/
  if(error) printf("error %u: %s\n", error, lodepng_error_text(error));

  free(png);
}
Пример #4
0
unsigned int Image::writePNG(std::string filename) {
    unsigned char* png;
    size_t pngsize;

    unsigned error = lodepng_encode32(&png, &pngsize, pixels, width, height);
    if(!error) lodepng_save_file(png, pngsize, filename.c_str());

    /*if there's an error, display it*/
	if (error) {
		DEBUG("error " << error << ": " << lodepng_error_text(error));
	}

    free(png);

    return 0;
}
Пример #5
0
static bool icvEncodePng32(std::string* dst, const char* data, int size, int width, int height, int width_step/*=0*/) {
	if(dst == NULL || data == NULL || size <= 0) {
		return false;
	}
	if(width <= 0 || height <= 0) {
		return false;
	}

	if(width_step < width*4) {
		width_step = width*4;
	}

	std::string tmp;
	const char* pSrcData = data;

	if(width_step > width*4) {
		tmp.resize(width*height*4);
		for(int i = 0; i < height; ++i) {
			char* ppTmp = (char*)tmp.data() + i*width*4;
			char* ppSrc = (char*)data + i*width_step;
			memcpy(ppTmp, ppSrc, width*4);
		}
		pSrcData = tmp.data();
	}

	unsigned char* png;
	size_t pngsize;

	unsigned err = lodepng_encode32(&png, &pngsize, (const unsigned char*)pSrcData, width, height);
	if(err != 0) return false;

	dst->assign((const char*)png, pngsize);
	free(png);

	return true;
}