bool sprite_file_export(int spriteIndex, const char *outPath)
{
	rct_g1_element *spriteHeader;
	rct_drawpixelinfo dpi;
	uint8 *pixels;
	int pixelBufferSize;

	spriteHeader = &spriteFileEntries[spriteIndex];
	pixelBufferSize = spriteHeader->width * spriteHeader->height;
	pixels = malloc(pixelBufferSize);
	memset(pixels, 0, pixelBufferSize);

	dpi.bits = pixels;
	dpi.x = 0;
	dpi.y = 0;
	dpi.width = spriteHeader->width;
	dpi.height = spriteHeader->height;
	dpi.pitch = 0;
	dpi.zoom_level = 0;

	memcpy(spriteFilePalette, _standardPalette, 256 * 4);
	gfx_rle_sprite_to_buffer(spriteHeader->offset, pixels, (uint8*)spriteFilePalette, &dpi, IMAGE_TYPE_NO_BACKGROUND, 0, spriteHeader->height, 0, spriteHeader->width);

	LodePNGState pngState;
	unsigned int pngError;
	unsigned char* pngData;
	size_t pngSize;

	lodepng_state_init(&pngState);
	pngState.info_raw.colortype = LCT_PALETTE;
	lodepng_palette_add(&pngState.info_raw, 0, 0, 0, 0);
	for (int i = 1; i < 256; i++) {
		lodepng_palette_add(
			&pngState.info_raw,
			spriteFilePalette[i].r,
			spriteFilePalette[i].g,
			spriteFilePalette[i].b,
			255
		);
	}

	pngError = lodepng_encode(&pngData, &pngSize, pixels, spriteHeader->width, spriteHeader->height, &pngState);
	if (pngError != 0) {
		free(pngData);
		fprintf(stderr, "Error creating PNG data, %u: %s", pngError, lodepng_error_text(pngError));
		return false;
	} else {
		lodepng_save_file(pngData, pngSize, outPath);
		free(pngData);
		return true;
	}
}
示例#2
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);
}
示例#3
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;
}
示例#4
0
int screenshot_dump_png()
{
	int i, index, width, height, stride;
	char path[MAX_PATH] = "";

	unsigned char r, g, b, a = 255;

	unsigned char* png;
	size_t pngSize;
	LodePNGState state;

	// Get a free screenshot path
	if ((index = screenshot_get_next_path(path, ".png")) == -1)
		return -1;


	lodepng_state_init(&state);
	state.info_raw.colortype = LCT_PALETTE;

	// Get image size
	width = RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_WIDTH, uint16);
	height = RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_HEIGHT, uint16);
	stride = (width + 3) & 0xFFFFFFFC;

	for (i = 0; i < 246; i++) {
		b = RCT2_ADDRESS(0x01424680, uint8)[i * 4 + 0];
		g = RCT2_ADDRESS(0x01424680, uint8)[i * 4 + 1];
		r = RCT2_ADDRESS(0x01424680, uint8)[i * 4 + 2];

		lodepng_palette_add(&state.info_raw, r, g, b, a);
	}

	rct_drawpixelinfo *dpi = RCT2_ADDRESS(RCT2_ADDRESS_SCREEN_DPI, rct_drawpixelinfo);

	unsigned int error = lodepng_encode(&png, &pngSize, dpi->bits, stride, dpi->height, &state);
	if (!error) lodepng_save_file(png, pngSize, path);

	if (error) {
		fprintf(stderr, "error: %u: %s\n", error, lodepng_error_text(error));
		index = -1;
	}

	free(png);
	return index;
}
示例#5
0
/*
Example 3
Save a PNG file to disk using a State, normally needed for more advanced usage.
The image argument has width * height RGBA pixels or width * height * 4 bytes
*/
void encodeWithState(const char* filename, const unsigned char* image, unsigned width, unsigned height)
{
  unsigned error;
  unsigned char* png;
  size_t pngsize;
  LodePNGState state;

  lodepng_state_init(&state);
  /*optionally customize the state*/

  error = lodepng_encode(&png, &pngsize, image, width, height, &state);
  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));

  lodepng_state_cleanup(&state);
  free(png);
}
示例#6
0
int main(void)
{
    unsigned error;
    unsigned char* image;
    unsigned width, height;
    unsigned char* png;
    size_t pngsize;
    LodePNGState state;
    char filename[] = "handmaze.png";  /* NAME OF INPUT IMAGE */

    lodepng_state_init(&state);
    /*optionally customize the state*/
    state.info_raw.colortype = LCT_GREY;

    lodepng_load_file(&png, &pngsize, filename);
    error = lodepng_decode(&image, &width, &height, &state, png, pngsize);
    if(error) printf("error %u: %s\n", error, lodepng_error_text(error));

    free(png);

    /*use image here*/
    //printf("Width=%d Height=%d\n", width, height);
    
    //FILE * fp;
    //fp = fopen("imgout.txt", "w");
    //fp = fopen("imgout.ram", "wb");
    //int i,x,y;
    //char * ramimg = (char*) calloc(2*width*height, sizeof(char));
    //for(i = 0; i < 2*width*height; i++){
        //fprintf(fp, "%d (%d,%d)=%d\n", i, i%width, i/width, image[i]);
    //    if(i%2 == 0)
    //        ramimg[i] = image[i/2];
    //    else
    //        ramimg[i] = 0;
    //}
    //fwrite(ramimg, sizeof(unsigned char), 2*width*height, fp);
    //free(ramimg);
    //fclose(fp);
    //for(y = 0; y < height; y++) {
    //    for(x = 0; x < width; x++) {
    //        fprintf(fp, "(%d,%d)=%d\n", x, y, image[coords(x,y,width,height)]);
    //    }
    //}
    
    unsigned char * gaussimg = (unsigned char*) calloc(width*height, sizeof(char));
    unsigned char * outimg = (unsigned char*) calloc(width*height, sizeof(char));
    gaussian_blur(width, height, image, gaussimg);
    sobel_filtering(width, height, gaussimg, outimg);
    
    int right_coord, startx, starty, index1=6, index2=5;
    int block_size =blocksize(width, height, image, &startx, &starty, 7, &right_coord, index1, index2);
    //printf("blocksize = %d\n", block_size);
    
    int solver;
    unsigned char path[144];
    int *size=(int *) malloc(sizeof(int));
    *size = 0;

    solver = dfs(width,height,image, startx, starty, startx, starty, block_size, path, size);
    
    //printf("size = %d\n", *size);
    int i1;
    for(i1 = *size; i1 >= 0; i1--)
    {
        printf("%c\n", path[i1]);
    }
    
    //int x, y;
    //for(x = 0; x < width; x++)
    //{
    //    for(y = 0; y < height; y++)
    //    {
    //        outimg[coords(x,y,width,height)] = image[coords(x,y,width,height)];
    //    }
    //}
    
    unsigned char* outpng;
    error = lodepng_encode(&outpng, &pngsize, outimg, width, height, &state);
    if(!error) lodepng_save_file(outpng, pngsize, "sobel.png");  /* NAME OF OUTPUT IMAGE */
    if(error) printf("error %u: %s\n", error, lodepng_error_text(error));
    
    
    
    /* CLEANUP */
    lodepng_state_cleanup(&state);
    free(image);
    free(outimg);
    
    return 0;
}