Example #1
0
void render_png(Scene *scene, bstring output_file)
{
    int width  = scene->canvas->width;
    int height = scene->canvas->height;

    Colour **data = scene->canvas->data;

    Colour colour;

    unsigned err;

    unsigned char* image = malloc(width * height * 4);

    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            // Fix image being upside down
            // We trace from bottom left to top right
            // Logepng goes topleft to bottom right
            int yc = (height - 1) - y;
            colour = data[x][y];
            image[4 * width * yc + 4 * x + 0] = (uint8_t)colour.red;
            image[4 * width * yc + 4 * x + 1] = (uint8_t)colour.green;
            image[4 * width * yc + 4 * x + 2] = (uint8_t)colour.blue;
            image[4 * width * yc + 4 * x + 3] = (uint8_t)colour.alpha;
        }
    }

    err = lodepng_encode32_file(bdata(output_file), image, width, height);

    if (err) {
        printf("error %u: %s\n", err, lodepng_error_text(err));
    }
}
Example #2
0
void sobelize(char* input_filename, char* output_filename, int thread_count)
{
  unsigned error;
  unsigned char *image, *new_image;
  unsigned width, height;

  // load image from PNG into C array
  error = lodepng_decode32_file(&image, &width, &height, input_filename);
  if(error) printf("error %u: %s\n", error, lodepng_error_text(error));
  new_image = malloc(width * height * 4 * sizeof(unsigned char));

  struct timeval start, end; // struct used to compute execution time
  gettimeofday(&start, NULL);  // set starting point

  /* TODO: create your thread team here and send each thread an argument 
  telling it which part of "image" to process 

  remember to join all threads!
  */

  gettimeofday(&end, NULL);
  printf("\n\nAlgorithm's computational part duration : %ld\n", \
               ((end.tv_sec * 1000000 + end.tv_usec) - (start.tv_sec * 1000000 + start.tv_usec)));


  lodepng_encode32_file(output_filename, new_image, width, height);

  free(image);
  free(new_image);
}
Example #3
0
int main(int argc, char* argv[]) {
	if (argc < 2) {
		printf("No images specified.\n");

		printf("Press ENTER to continue...\n");
		while(getchar() != '\n');

		exit(EXIT_FAILURE);
	}

	unsigned int error;
	for (unsigned argi = 1; argi < argc; argi++) {
		char* path = argv[argi];

		// Load image

		unsigned char* pixels;
		unsigned width;
		unsigned height;

		error = lodepng_decode32_file(&pixels, &width, &height, path);
		if (error) {
			const char* error_text = lodepng_error_text(error);
			printf("Error loading `%s`: %s\n", path, error_text);

			printf("Press ENTER to continue...\n");
			while(getchar() != '\n');

			exit(EXIT_FAILURE);
		}
		printf("Performing on `%s`...\n", path);

		// Initialize 'nearest' map and jump flood

		unsigned size = width * height;
		ivec2* nearests = malloc(size * sizeof(ivec2));

		init_nearests(nearests, pixels, width, height);
		jump_flood(nearests, width, height);

		// Copy colors into invisible pixels and write image

		copy_nearests(nearests, pixels, width, height);
		free(nearests);

		error = lodepng_encode32_file(path, pixels, width, height);
		free(pixels);
		if (error) {
			const char* error_text = lodepng_error_text(error);
			printf("Error saving to `%s`: %s\n", path, error_text);

			printf("Press ENTER to continue...\n");
			while(getchar() != '\n');

			exit(EXIT_FAILURE);
		}
	}

	return EXIT_SUCCESS;
}
Example #4
0
//function for encoding a PNG
void encode(const char *filename,Image *encodeImage)
{
  int width=encodeImage->width;
  int height=encodeImage->height;
  unsigned char *image=(unsigned char*)malloc(sizeof(unsigned char)*4*height*width);
  
  int row,col;
  int imageWidth=4*width;
  uint8_t *redChannel=encodeImage->redChannel;
  uint8_t *blueChannel=encodeImage->blueChannel;
  uint8_t *greenChannel=encodeImage->greenChannel;
  uint8_t *alphaChannel=encodeImage->alphaChannel;

  for(row=0;row<height;row++)
    for(col=0;col<width;col++)
    {
      image[imageWidth*row+4*col+0]=redChannel[row*width+col];
      image[imageWidth*row+4*col+1]=blueChannel[row*width+col];
      image[imageWidth*row+4*col+2]=greenChannel[row*width+col];
      image[imageWidth*row+4*col+3]=alphaChannel[row*width+col];
    }

  unsigned int error=lodepng_encode32_file(filename,image,width,height);
  if(error)
    printf("error %u:%s\n",error,lodepng_error_text(error));

  free(image);
}
Example #5
0
/* exports the level as png image */
void export_level(char *filename) {
	/* add file extension if not given */
	if (!strstr(filename, ".png")) {
		strcat(filename, ".png");
	}

	/* allocate memory for every block * 4 (RGBA) */
	unsigned char *image = malloc(js_level_width * js_level_height * 4);
	
	/* visit every R index and write R, G, B, A --> 4 steps */
	for (int i = 0; i < js_level_width * js_level_height * 4; i += 4) {
		/* get color */
		const struct color block = blocks[js_level[i / 4]];
		/* set R, G, B and A */
		image[i + 0] = block.r;
		image[i + 1] = block.g;
		image[i + 2] = block.b;
		image[i + 3] = 255;
	}
	
	/* encode the image with lodepng */
	unsigned error = lodepng_encode32_file(filename,
		image,
		js_level_width,
		js_level_height);
	/* if there's an error, print it! */
	if (error)
		printf("Error %u: %s\n", error, lodepng_error_text(error));
	
	/* free memory for image */
	free(image);
}
Example #6
0
int ConvertIcon(FILE *in, char *out, u32 offset, s32 width)
{
	// In and Out Buffers
	u32 ctpk_size = width*width*sizeof(u16);
	u32 bmp_encoded_buff_size = width*width*3;
	u32 bmp_decoded_buff_size = width*width*4;
	
	u16 *ctpk = malloc(ctpk_size);
	u8 *bmp_encoded = malloc(bmp_encoded_buff_size);
	u8 *bmp_decoded = malloc(bmp_decoded_buff_size);
	
	// Reading CTPK (CTR Texture Package)
	fseek(in,offset,SEEK_SET);
	fread(ctpk,ctpk_size,1,in);
	
	// Getting Decoding CTPK and encoding to 24-bit BMP data
	CTPKtoBMP(ctpk,bmp_encoded,width);
	free(ctpk);
	
	// Decoding BMP data
	DecodeBMPData(bmp_encoded,bmp_decoded,(u16)width);
	free(bmp_encoded);
	
	// Writing PNG
	unsigned result = lodepng_encode32_file(out, bmp_decoded, width, width);
	free(bmp_decoded);
	
	return (int)result;
}
Example #7
0
void ScreenCapture()
{
	int viewPort[4];
	glGetIntegerv(GL_VIEWPORT, viewPort);
	int width = viewPort[2] - viewPort[0];
	int height = viewPort[3] - viewPort[1];

	SDL_Surface* surface = SDL_CreateRGBSurface(0, width, height, 32, 0xff, 0xff << 8, 0xff << 16, 0xff << 24);
	if (!surface)
		return;

	glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels);

	// This is a fancy swap, for the screen pixels:
	int i;
	U32* buffer = new U32[width];

	for (i = 0; i < height / 2; ++i)
	{
		memcpy(buffer,
			   ((U32*)surface->pixels + i*width),
			   width * 4);
		memcpy(((U32*)surface->pixels + i*width),
			   ((U32*)surface->pixels + (height - 1 - i)*width),
			   width * 4);
		memcpy(((U32*)surface->pixels + (height - 1 - i)*width),
			   buffer,
			   width * 4);
	}
	delete[] buffer;

	// And now, set all the alphas to opaque:
	for (i = 0; i < width*height; ++i)
		*((U32*)surface->pixels + i) |= 0xff000000;

	grinliz::Rectangle2I r;
	r.Set(0, 0, width - 1, height - 1);
	if (width == 0 || height == 0) {
		return;
	}

	int index = 0;
	grinliz::GLString path;
	for (index = 0; index < 100; ++index)
	{
		char buf[32];
		grinliz::SNPrintf(buf, 32, "cap%02d.png", index);
		GetSystemPath(GAME_SAVE_DIR, buf, &path);
		FILE* fp = fopen(path.c_str(), "rb");
		if (fp)
			fclose(fp);
		else
			break;
	}
	if (index < 100) {
		lodepng_encode32_file(path.c_str(), (const unsigned char*)surface->pixels, width, height);
	}
	SDL_FreeSurface(surface);
}
int pixMap_write(pixMap *p,char *filename){
	int error=0;
 if(lodepng_encode32_file(filename, p->image, p->width, p->height)){
  fprintf(stderr,"error %u: %s\n", error, lodepng_error_text(error));
  return 1;
	}
	return 0;
}	 
Example #9
0
/*
Example 1
Encode from raw pixels to disk with a single function call
The image argument has width * height RGBA pixels or width * height * 4 bytes
*/
void encodeOneStep(const char* filename, const unsigned char* image, unsigned width, unsigned height)
{
  /*Encode the image*/
  unsigned error = lodepng_encode32_file(filename, image, width, height);

  /*if there's an error, display it*/
  if(error) printf("error %u: %s\n", error, lodepng_error_text(error));
}
void sobelize(char* input_filename, char* output_filename, int thread_count)
{
  unsigned error;
  unsigned pos[2];
  // unsigned char *image, *new_image;
  // unsigned width, height;

  // load image from PNG into C array
  error = lodepng_decode32_file(&image, &width, &height, input_filename);
  if(error) printf("error %u: %s\n", error, lodepng_error_text(error));
  new_image = malloc(width * height * 4 * sizeof(unsigned char));

  struct timeval start, end; // struct used to compute execution time
  gettimeofday(&start, NULL);  // set starting point

  unsigned height_piece = ceil(height/(float)(thread_count));
  fprintf(stdout, "height = %d\n", height);
  /* TODO: create your thread team here and send each thread an argument
  telling it which part of "image" to process

  remember to join all threads!
  */
  pthread_t threads[thread_count];
  for(int i = 0; i < thread_count; i++){
    pos[0] = i*height_piece;
    pos[1] = MIN((i+1)*height_piece, height);

    unsigned *j = malloc(2*sizeof(unsigned));
    memcpy(j, pos, 2*sizeof(unsigned));
    int c = pthread_create(&threads[i], NULL, &worker_thread, j);
    if (c != 0) {
      fprintf(stderr, "Error creating pthreads exiting...\n");
      exit(1);
    }
  }

  for(int i = 0; i < thread_count; i++) {
    int c = pthread_join(threads[i], NULL);
    if (c != 0) {
      fprintf(stderr, "Error joining pthreads exiting...\n");
      exit(1);
    }
  }




  gettimeofday(&end, NULL);
  printf("\n\nAlgorithm's computational part duration : %ld\n", \
               ((end.tv_sec * 1000000 + end.tv_usec) - (start.tv_sec * 1000000 + start.tv_usec)));


  lodepng_encode32_file(output_filename, new_image, width, height);

  free(image);
  free(new_image);
}
Example #11
0
int main(int argc,char *argv[])
{
	BM	mainBM;
	OPTIONS options;
	LOCATIONHISTORY locationHistory;

	int error;


	//set vars to zero
	memset(&options, 0, sizeof(options));	//set all the option results to 0
	memset(&mainBM, 0, sizeof(mainBM));

	//Display introductory text
	PrintIntro(argv[0]);

	//locationHistory.jsonfilename="LocationHistory.json";	//default

	if (argc == 1)	PrintUsage(argv[0]);	//print usage instructions
	HandleCLIOptions(argc, argv, &options);
	PrintOptions(&options);
	RationaliseOptions(&options);

	//Initialise the bitmap
	bitmapInit(&mainBM, &options, &locationHistory);
	DrawGrid(&mainBM);
	//ColourWheel(mainBM, 100, 100, 100, 5);  	//Color wheel test of lines and antialiasing


	fprintf(stdout, "Loading locations from %s.\r\n", mainBM.options->jsonfilenamefinal);
	LoadLocations(&locationHistory, &mainBM.options->jsonfilenamefinal[0]);

	fprintf(stdout, "Plotting paths.\r\n");
	PlotPaths(&mainBM, &locationHistory, &options);
//	HeatmapPlot(&mainBM, &locationHistory);

	fprintf(stdout, "Ploted lines between: %i points\r\n", mainBM.countPoints);
	printf("From:\t%s\r\n", asctime(localtime(&locationHistory.earliesttimestamp)));
	printf("To:\t%s\r\n", asctime(localtime(&locationHistory.latesttimestamp)));

	FreeLocations(&locationHistory);


	//Write the PNG file
	fprintf(stdout, "Writing to %s.\r\n", mainBM.options->pngfilenamefinal);
	error = lodepng_encode32_file(mainBM.options->pngfilenamefinal, mainBM.bitmap, mainBM.width, mainBM.height);
	if(error) fprintf(stderr, "LodePNG error %u: %s\n", error, lodepng_error_text(error));

	//Write KML file
	fprintf(stdout, "Writing to %s.\r\n", mainBM.options->kmlfilenamefinal);
	WriteKMLFile(&mainBM);

	bitmapDestroy(&mainBM);
	fprintf(stdout, "Program finished.");
	return 0;
}
Example #12
0
void Film::write_to_image() {
  
  unsigned error = lodepng_encode32_file(output, image, width, height);
 
  if (error) {
    printf("Lodepng error: %u: %s\n", error, lodepng_error_text(error));
    exit(EXIT_FAILURE);
  }
  
}
Example #13
0
void save_mandelbrot(const char* file_name, uint width, uint height, uint max_iterations)
{
    uchar* host_image;
    size_t image_size;
    run_mandelbrot(&host_image, &image_size,
                   width, height,
                   max_iterations,
                   X_SCALE, Y_SCALE,
                   X_ADJUST, Y_ADJUST);
    lodepng_encode32_file(file_name, host_image, width, height);
    free(host_image);
}
Example #14
0
int main(int argc, char **argv) {
    unsigned error;
    unsigned char* image;
    unsigned width, height;
    unsigned char* png;
    size_t pngsize;
    LodePNGState state;

    if (argc != 3) {
        fprintf(stderr, "Usage: %s input-8bit.png output-32bit.png\n\nVersion 0.2, © 2014 Kornel Lesiński <*****@*****.**>\nhttps://github.com/pornel/undither\n\n", argv[0]);
        return 1;
    }

    lodepng_state_init(&state);
    state.decoder.color_convert = 0;
    state.info_raw.colortype = LCT_PALETTE;
    state.info_raw.bitdepth = 8;
    error = lodepng_load_file(&png, &pngsize, argv[1]);
    if (!error) {
        error = lodepng_decode(&image, &width, &height, &state, png, pngsize);
    }
    free(png);
    if (error) {
        fprintf(stderr, "error when loading '%s': %s\n", argv[1], lodepng_error_text(error));
        return error;
    }

    if (state.info_raw.bitdepth != 8) {
        fprintf(stderr, "Only 256-color images are supported\n");
        return 1;
    }

    const rgba *pal = (rgba *)state.info_raw.palette;
    if (!pal || state.info_raw.colortype != LCT_PALETTE) {
        fprintf(stderr, "No pal?\n");
        return 1;
    }
    rgba *out = malloc(width*height*4);

    undither(image, pal, width, height, out);

    lodepng_state_cleanup(&state);
    free(image);

    error = lodepng_encode32_file(argv[2], (unsigned char*)out, width, height);
    if (error) {
        fprintf(stderr, "error when saving '%s': %s\n", argv[2], lodepng_error_text(error));
        return error;
    }

    return 0;
}
void binarize(char* input_filename, char* output_filename, int thread_count)
{
  unsigned error;
  unsigned width, height;

  // load image from PNG into C array
  error = lodepng_decode32_file(&image, &width, &height, input_filename);
  if(error) printf("error %u: %s\n", error, lodepng_error_text(error));
  new_image = malloc(width * height * 4 * sizeof(unsigned char));

  struct timeval start, end; // struct used to compute execution time
  gettimeofday(&start, NULL);  // set starting point

  /* TODO: create your thread team here and send each thread an argument 
  telling it which part of "image" to process 

  remember to join all threads!
  */

  total_width = width;
  total_height = height;

  partitions = width/thread_count;

  part = (width * height)/thread_count;

  int threads[thread_count];

  int i;
  for (i = 0; i < thread_count; i++) {
    pthread_t t;

    threads[i] = pthread_create(&t, NULL, worker_thread, (void*) i);
  }

  int j;
  for (j = 0; j < thread_count; j++){
    pthread_join(threads[i], NULL);
  }

  gettimeofday(&end, NULL);
  printf("\n\nAlgorithm's computational part duration : %ld\n", \
               ((end.tv_sec * 1000000 + end.tv_usec) - (start.tv_sec * 1000000 + start.tv_usec)));


  lodepng_encode32_file(output_filename, new_image, width, height);

  free(image);
  free(new_image);
}
Example #16
0
int LodePngCoder::Encode(const char *filename, const unsigned char *image,
                         unsigned w, unsigned h)
{
    if (!filename || !image) return -1;

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

    return res;
}
Example #17
0
bool Image::writePNG(const char *path) {
    const char *cpath = platformCStringPath(path);
    
    assertmsg( buffer!=0 , "image not initialized?" );
    assertmsg( width <= 2048 && height <= 2048, "image too big" );
    

    /*Same as lodepng_encode_file, but always encodes from 32-bit RGBA raw image.*/
    unsigned error;
    error = lodepng_encode32_file( cpath, buffer, width, height );
    if(error) {
        fprintf(stderr, "lodepng_encode32_file failed%d", error );
        return false;
    }
    return true;
}
Example #18
0
int winpr_image_write(wImage* image, const char* filename)
{
	int status = -1;

	if (image->type == WINPR_IMAGE_BITMAP)
	{
		status = winpr_bitmap_write(filename, image->data, image->width, image->height, image->bitsPerPixel);
	}
	else
	{
		int lodepng_status;

		lodepng_status = lodepng_encode32_file(filename, image->data, image->width, image->height);

		status = (lodepng_status) ? -1 : 1;
	}

	return status;
}
void sobelize(char* input_filename, char* output_filename)
{
  unsigned error;
  unsigned char *image, *new_image;
  unsigned width, height;

  error = lodepng_decode32_file(&image, &width, &height, input_filename);
  if(error) printf("error %u: %s\n", error, lodepng_error_text(error));
  new_image = malloc(width * height * 4 * sizeof(unsigned char));

  struct timeval start, end; // struct used to compute execution time
  gettimeofday(&start, NULL);  // set starting point

  /* TODO: Loop through the "image" and generate the "new_image". */
  unsigned char value;
  for (int i = 1; i < height-1; i++) {
    for (int j = 1; j < width-1; j++) {
      /* TODO: use the Sobel kernel on this pixel,
      put the result into the "value" variable */
      value = (abs((image[4*width*(i-1) + 4*(j-1)] + 2*image[4*width*(i-1) + 4*j]
                  + image[4*width*(i-1) + 4*(j+1)]) - (image[4*width*(i+1) + 4*(j-1)]
                  + 2*image[4*width*(i+1) + 4*j] + image[4*width*(i+1) + 4*(j+1)]))
                  + abs((image[4*width*(i-1) + 4*(j+1)] + 2*image[4*width*(i) + 4*(j+1)]
                  + image[4*width*(i+1) + 4*(j+1)]) - (image[4*width*(i-1) + 4*(j-1)]
                  + 2*image[4*width*i + 4*(j-1)] + image[4*width*(i+1) + 4*(j-1)])));

      new_image[4*width*i + 4*j] = value;
      new_image[4*width*i + 4*j + 1] = value;
      new_image[4*width*i + 4*j + 2] = value;
      new_image[4*width*i + 4*j + 3] = 255;
    }
  }

  gettimeofday(&end, NULL);
  printf("\n\nAlgorithm's computational part duration : %ld\n", \
               ((end.tv_sec * 1000000 + end.tv_usec) - (start.tv_sec * 1000000 + start.tv_usec)));

  lodepng_encode32_file(output_filename, new_image, width, height);

  free(image);
  free(new_image);
}
void binarize(char* input_filename, char* output_filename, int thread_count)
{
    unsigned error;
    unsigned char *image, *new_image;
    unsigned width, height;

    error = lodepng_decode32_file(&image, &width, &height, input_filename);
    if(error) printf("error %u: %s\n", error, lodepng_error_text(error));
    new_image = malloc(width * height * 4 * sizeof(unsigned char));

    struct timeval start, end; // struct used to compute execution time
    gettimeofday(&start, NULL);  // set starting point

    omp_set_num_threads(thread_count);
    int i, j;
    unsigned char value;
    #pragma omp parallel for shared(new_image) private(i,j,value)
    for (i = 0; i < height; i++) {
        for (j = 0; j < width; j++) {
            if (image[4*width*i + 4*j] > THRESHOLD) {
                value = 255;
            } else {
                value = 0;
            }

            new_image[4*width*i + 4*j] = value;
            new_image[4*width*i + 4*j + 1] = value;
            new_image[4*width*i + 4*j + 2] = value;
            new_image[4*width*i + 4*j + 3] = 255;
        }
    }

    gettimeofday(&end, NULL);
    printf("\n\nAlgorithm's computational part duration : %ld\n", \
           ((end.tv_sec * 1000000 + end.tv_usec) - (start.tv_sec * 1000000 + start.tv_usec)));

    lodepng_encode32_file(output_filename, new_image, width, height);

    free(image);
}
Example #21
0
int main(int argc, char *argv[]){
  if( argc==1 )
    printf("\nPosterizeZX v1.11. Transform an image to ZX Spectrum colors (no color clash)\n"
           "                                                by AntonioVillena, 11 Nov 2013\n\n"
           "  PosterizeZX <input_file> <output_file>\n\n"
           "  <input_file>      PNG input file\n"
           "  <output_file>     PNG output file\n\n"
           "Example: PosterizeZX work.png tiles.png\n"),
    exit(0);
  if( argc!=3 )
    printf("\nInvalid number of parameters\n"),
    exit(-1);
  if( error= lodepng_decode32_file(&image, &width, &height, argv[1]) )
    printf("\nError %u: %s\n", error, lodepng_error_text(error)),
    exit(-1);
  size= width*height;
  pixel= image;
  while ( size-- ){
    min= 1e9;
    for ( i= 0; i<15; i++ ){
      calc= (pixel[0]-colors[i][0])*(pixel[0]-colors[i][0])
          + (pixel[1]-colors[i][1])*(pixel[1]-colors[i][1])
          + (pixel[2]-colors[i][2])*(pixel[2]-colors[i][2]);
      if( calc<min )
        min= calc,
        minind= i;
    }
    pixel[0]= colors[minind][0];
    pixel[1]= colors[minind][1];
    pixel[2]= colors[minind][2];
    pixel+= 4;
  }
  if( error= lodepng_encode32_file(argv[2], image, width, height) )
    printf("Error %u: %s\n", error, lodepng_error_text(error)),
    exit(-1);
  free(image);
  printf("\nFile posterized successfully\n");
}
Example #22
0
void save_image(const image *img, const char *imgpath)
{
	lodepng_encode32_file(imgpath, img->data, img->width, img->height);
}
int main(void) {

	unsigned char* image;
	unsigned cols, rows, error;
	int input_channels;
	int **pixel_values, *count_values, **new_pixel_values;


	/*open image + handle error*/
	input_channels = 4;

	error = lodepng_decode32_file(&image, &cols, &rows, "LenaDark.png");
	if(error) {
		printf("error %u: %s\n", error, lodepng_error_text(error));}
	else{
		printf("Image successfully open!\n");}

	/*print width + height*/
	//printf("\nwidth = %u\n", width);
	//printf("height = %u\n\n\n", height);

	/*allocate pixel values 2D array*/
    pixel_values = allocate_2d_array(rows, cols);

	/*put pixel values in the array*/
	make_grayscale_pixel_values_array(rows, cols, input_channels, image, pixel_values);

    /*print pixel values*/
	//print_pixel_values(width, height, pixel_values);

	/*allocate + initialize array to count pixel values*/
	count_values = (int*)malloc(256*sizeof(int));
	initialize_1d_array(256, count_values);

	/*count different pixel values*/
	count_pixel_values(rows, cols, pixel_values, count_values);

	/*allocate pixel values 2D array*/
	new_pixel_values = allocate_2d_array(rows, cols);

	/*histogram equalization*/
	histogram_equalization(rows, cols, pixel_values, count_values, new_pixel_values);

	/*change image*/
	change_RGB_values(rows, cols, input_channels, image, new_pixel_values);

	/*print RGB values*/
	//print_RGB_values(width, height, input_channels, image);


	 /*Encode the image + error handling*/
	 error = lodepng_encode32_file("img_out.png", image, cols, rows);
	 if(error){
		 printf("error %u: %s\n", error, lodepng_error_text(error));}
	 else{
		 printf("Image successfully saved!\n");}

	/*Deallocate memory*/
	free(pixel_values);
	free(image);

	return EXIT_SUCCESS;
}
void Preview_save(Preview *self){
    unsigned error = lodepng_encode32_file(self->imageName, self->imageData, self->width, self->height);
    if(error) printf("error %u: %s\n", error, lodepng_error_text(error));
 }
Example #25
0
int main (int argc, char const *argv[]) {
    int fd = open(argv[1], O_RDONLY);
    assert(fd >= 0);
    
    ahff_header_t info = { 0 };
    READ_FULLY(fd, info.b, sizeof(ahff_header_t));
    
    unsigned char *buf = malloc(info.s.datsize);
    unsigned char *out = calloc(info.s.width * info.s.height, 4);
    assert(buf && out);
    
    READ_FULLY(fd, buf, info.s.datsize);
    
    int len = strlen(argv[1]);
    char *cp = strdup(argv[1]);
    char *fn;
    if (strcmp(cp + len - 5, ".ahff") == 0) {
        memcpy(cp + len - 5, ".png\0", 5);
        fn = cp;
    } else {
        fn = malloc(len + 5);
        snprintf(fn, len + 5, "%s.png", cp);
        free(cp);
    }
    printf("[>] %s\n", fn);
    
    uint32_t point_count = info.s.width * info.s.height;
    uint32_t expect_size = 0;
    
    switch (info.s.pixel_format) {
        case A8:
            expect_size = point_count;
            EXPECT_SIZE_CHK_AND_WARN();
            copy_1bpp_alpha(buf, expect_size, out);
            break;
        case RGB24:
            expect_size = point_count * 3;
            EXPECT_SIZE_CHK_AND_WARN();
            copy_3bpp_rgb(buf, expect_size, out);
            break;
        case RGB565:
            expect_size = point_count * 2;
            EXPECT_SIZE_CHK_AND_WARN();
            copy_2bpp_rgb565(buf, expect_size, out);
            break;
        case RGBA4444:
            expect_size = point_count * 2;
            EXPECT_SIZE_CHK_AND_WARN();
            copy_2bpp_rgba4444(buf, expect_size, out);
            break;
        case RGBA32:
            expect_size = point_count * 4;
            EXPECT_SIZE_CHK_AND_WARN();
            memcpy(out, buf, expect_size);
            break;
        case ETC1RGB:
            /* ETC1 encodes 4x4 blocks.
             * So w and h must be multiples of 4. */
            assert(info.s.width % 4 == 0);
            assert(info.s.height % 4 == 0);
            expect_size = point_count / 2;
            EXPECT_SIZE_CHK_AND_WARN();
            copy_etc1_rgb(buf, expect_size, out, info.s.width);
            break;
        default:
            fprintf(stderr, "unknown pixel format %d\n", info.s.pixel_format);
            goto end;
    }
    
    // flip_image_sideways(out, info.width, info.height);
    flip_image_upside_down(out, info.s.width, info.s.height);
    lodepng_encode32_file(fn, out, info.s.width, info.s.height);

  end:
    free(fn);
    free(buf);
    free(out);
    return 0;
}
Example #26
0
void write_png(char* filename, uint8_t* image, uint16_t width, uint16_t height) {
  unsigned error = lodepng_encode32_file(filename, image, width, height);
  if(error) printf("error %u: %s\n", error, lodepng_error_text(error));
}