GLubyte *EJTexture::loadPixelsWithLodePNGFromPath (const char* path) { unsigned int w, h; unsigned char * origPixels = NULL; unsigned int error = lodepng_decode32_file(&origPixels, &w, &h, path); if( error ) { LOGE("Error Loading image %s - %u: %s", path, error, lodepng_error_text(error)); return origPixels; } this->setWidth(w, h); // If the image is already in the correct (power of 2) size, just return // the original pixels unmodified if( width == realWidth && height == realHeight ) { return origPixels; } // Copy the original pixels into the upper left corner of a larger // (power of 2) pixel buffer, free the original pixels and return // the larger buffer else { GLubyte * pixels = (GLubyte*)malloc( realWidth * realHeight * 4 ); memset(pixels, 0x00, realWidth * realHeight * 4 ); for( int y = 0; y < height; y++ ) { memcpy( &pixels[y*realWidth*4], &origPixels[y*width*4], width*4 ); } free( origPixels ); return pixels; } }
SDL_Texture *ImgToTex(SDL_Renderer *renderer, string filename, int &w, int &h) { const u32 rmask = 0x000000ff; const u32 gmask = 0x0000ff00; const u32 bmask = 0x00ff0000; const u32 amask = 0xff000000; u8 *img; u32 uw, uh; lodepng_decode32_file(&img, &uw, &uh, filename.c_str()); w = int(uw); h = int(uh); SDL_Surface *image = SDL_CreateRGBSurface(0, w, h, 32, rmask, gmask, bmask, amask); SDL_LockSurface(image); memcpy(image->pixels, img, 4 * w * h); SDL_UnlockSurface(image); SDL_Texture *tex = SDL_CreateTextureFromSurface(renderer, image); free(img); SDL_SetTextureBlendMode(tex, SDL_BLENDMODE_BLEND); return tex; }
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); }
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; }
GLuint loadPNGImage(const char *file_name) { unsigned int error; unsigned char *data; unsigned int width, height; error = lodepng_decode32_file(&data, &width, &height, file_name); if (error) { fprintf(stderr, "error %u: %s\n", error, lodepng_error_text(error)); } GLuint textureID; glGenTextures(1, &textureID); glBindTexture(GL_TEXTURE_2D, textureID); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 5); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); if (!error) { free(data); } return textureID; }
static int pixMap_read(pixMap *p,char *filename){ int error; if((error=lodepng_decode32_file(&(p->image), &(p->width), &(p->height),filename))){ fprintf(stderr,"error %u: %s\n", error, lodepng_error_text(error)); return 1; } return 0; }
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); }
Texture2d* Texture2d::load(std::string path) { arc<internal::PngData> image = internal::PngData::create(); path = path + ".png"; if(lodepng_decode32_file(&image->image, &image->width, &image->height, path.c_str()) != 0) { throw std::exception(); } Texture2d* texture = new Texture2d(image->width, image->height); if(texture->nativeTexture.get() == NULL) { texture->nativeTexture = gl::Uint::genTexture(); } int sampleWidth = image->width; int sampleHeight = image->height; sampleWidth = poweroftwo(image->width); sampleHeight = poweroftwo(image->height); std::cout << sampleWidth << " " << sampleHeight << std::endl; std::vector<GLbyte> imageBytes(sampleHeight * sampleWidth * 4); double scaleWidth = (double)sampleWidth / (double)image->width; double scaleHeight = (double)sampleHeight / (double)image->height; for(int cy = 0; cy < sampleHeight; cy++) { for(int cx = 0; cx < sampleWidth; cx++) { int pixel = (cy * (sampleWidth * 4)) + (cx * 4); int nearestMatch = (((int)(cy / scaleHeight) * (image->width * 4)) + ((int)(cx / scaleWidth) * 4) ); imageBytes[pixel ] = image->image[nearestMatch ]; imageBytes[pixel + 1] = image->image[nearestMatch + 1]; imageBytes[pixel + 2] = image->image[nearestMatch + 2]; imageBytes[pixel + 3] = image->image[nearestMatch + 3]; } } glBindTexture(GL_TEXTURE_2D, texture->nativeTexture->getGLuint()); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, sampleWidth, sampleHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, &imageBytes[0]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); //glGenerateMipmap(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 0); return texture; }
void create_background_texture(background_t *state) { // Read in background PNG unsigned error; unsigned char* image; unsigned width, height; #ifdef RASPI error = lodepng_decode32_file(&image, &width, &height, "SPH/images/OakRidgeLeaf.png"); #else error = lodepng_decode32_file(&image, &width, &height, "images/OakRidgeLeaf.png"); #endif if(error) printf("error %u: %s\n", error, lodepng_error_text(error)); state->background_width = state->screen_width/3.2; state->background_height = state->screen_height/1.5; printf("Background image loaded: %d x %d pixels\n", width, height); // Generate texture glGenTextures(1, &state->tex_uniform); // Set texture unit 0 and bind texture glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, state->tex_uniform); // Buffer texture glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image); // Set texture parameters glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Create Mipmap glGenerateMipmap(GL_TEXTURE_2D); // Release image host memory free(image); }
void load_png_texture(const char *file_name) { unsigned error; unsigned char *image; unsigned width, height; error = lodepng_decode32_file(&image, &width, &height, file_name); if (error) { fprintf(stderr, "error %u: %s\n", error, lodepng_error_text(error)); } glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image); free(image); }
void *Loader_load_png(const char *filename, int *width, int *height) { unsigned char *pixels; int error = lodepng_decode32_file(&pixels, (unsigned *)width, (unsigned *)height, filename); if (error) { Log("ERROR: loading png %s, %s", filename, lodepng_error_text(error)); return NULL; } return pixels; }
// load a file and return the index of the data loaded in m_listFileData. unsigned int ResourceManager::LoadFile(const char* fn, unsigned int& h, unsigned int& w) { unsigned char* data; // load the black and white heightmap png file. Data is RGBA unsigned char. unsigned error = lodepng_decode32_file(&data, &w, &h, fn); if (error) { std::string msg = "ResourceManager::LoadFile: Error loading file " + std::string(fn); throw GFX_Exception(msg.c_str()); } m_listFileData.push_back(data); return (unsigned int)m_listFileData.size() - 1; }
/* Example 1 Decode from disk to raw pixels with a single function call */ void decodeOneStep(const char *filename) { unsigned error; unsigned char *image; unsigned width, height; error = lodepng_decode32_file(&image, &width, &height, filename); if (error) printf("error %u: %s\n", error, lodepng_error_text(error)); /*use image here*/ free(image); }
void UI::load_png_texture(const char *file_name) { unsigned int error; unsigned char *data; unsigned int width, height; error = lodepng_decode32_file(&data, &width, &height, file_name); if (error) { fprintf(stderr, "error %u: %s\n", error, lodepng_error_text(error)); } flip_image_vertical(data, width, height); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); free(data); }
unsigned int Image::loadPNG(){ std::vector<unsigned char> image; //the raw pixels //decode unsigned int error; error = lodepng_decode32_file(&pixels, &width, &height, path.c_str()); //if there's an error, display it if (error) { DEBUG("decoder error " << error << ": " << lodepng_error_text(error)); } return error; }
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); }
void open_png(unsigned char* image, unsigned rows, unsigned cols, char *image_name){ unsigned error; /*open image + handle error*/ error = lodepng_decode32_file(&image, &cols, &rows, image_name); 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); }
bool Image::loadPNG( const char *path, bool multiply_color_by_alpha ) { const char *cpath = platformCStringPath(path); FILE *fp = fopen(cpath,"rb"); if(!fp) { print( "Image::loadPNG: can't open file:%s", cpath ); return false; } unsigned error; unsigned char* image_data; unsigned w, h; error = lodepng_decode32_file(&image_data, &w, &h, cpath ); if(error) { fprintf(stderr, "decoder error %u: %s\n", error, lodepng_error_text(error) ); FREE(image_data); fclose(fp); return false; } width = w; height = h; if( multiply_color_by_alpha ) multiplyAlphaRGBA(image_data,width,height); ensureBuffer(); #define IMAGE_BUFFER_COPY \ for(int i=0;i<width*height;i++){ \ int x = i % width; \ int y = (i / width); \ int ii = y * width + x; \ buffer[ii*4+0] = image_data[i*4+0]; /*r*/ \ buffer[ii*4+1] = image_data[i*4+1]; /*g*/ \ buffer[ii*4+2] = image_data[i*4+2]; /*b*/ \ buffer[ii*4+3] = image_data[i*4+3]; /*a*/ \ } IMAGE_BUFFER_COPY; // clean up FREE(image_data); fclose(fp); strncpy( last_load_file_path, path, sizeof(last_load_file_path) ); return true; }
void load(){ glEnable(GL_TEXTURE_2D); glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_2D, texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); int width, height; unsigned char* image; lodepng_decode32_file(&image, &width, &height, "WoodFine0001_1_thumblarge.png"); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image); glEnable(GL_TEXTURE_2D); }
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); }
int LodePngCoder::Decode(const char *filePath, unsigned char **outputBuffer, unsigned int *outputWidth, unsigned int *outputHeight) { unsigned int uw = 0, uh = 0; unsigned char *buffer = NULL; int error = lodepng_decode32_file(&buffer, &uw, &uh, filePath); if (outputWidth) *outputWidth = uw; if (outputHeight) *outputHeight = uh; if (outputBuffer) *outputBuffer = buffer; if (error) { LOG_I("[LodePngCoder] fail to decode, error:%d, %s", error, lodepng_error_text(error)); } return error; }
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); }
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"); }
//function for decoding a PNG Image *decode(const char *filename) { Image *inputImage=(Image*)malloc(sizeof(Image)); unsigned int error; unsigned char *image; error=lodepng_decode32_file(&image,(unsigned int*)&(inputImage->width),(unsigned int*)&(inputImage->height),filename); if(error) printf("error %u: %s\n",error,lodepng_error_text(error)); int width=inputImage->width; int height=inputImage->height; inputImage->redChannel=(uint8_t*)malloc(sizeof(uint8_t)*width*height); inputImage->blueChannel=(uint8_t*)malloc(sizeof(uint8_t)*width*height); inputImage->greenChannel=(uint8_t*)malloc(sizeof(uint8_t)*width*height); inputImage->alphaChannel=(uint8_t*)malloc(sizeof(uint8_t)*width*height); int row,col; int imageWidth=width*4; uint8_t *redChannel=inputImage->redChannel; uint8_t *blueChannel=inputImage->blueChannel; uint8_t *greenChannel=inputImage->greenChannel; uint8_t *alphaChannel=inputImage->alphaChannel; for(row=0;row<height;row++) { for(col=0;col<width;col++) { redChannel[row*width+col]=image[imageWidth*row+4*col+0]; blueChannel[row*width+col]=image[imageWidth*row+4*col+1]; greenChannel[row*width+col]=image[imageWidth*row+4*col+2]; alphaChannel[row*width+col]=image[imageWidth*row+4*col+3]; } } free(image); return inputImage; }
SDL_Surface *SDL_LodePNG(const char* filename) { SDL_Surface *temp = NULL; unsigned char *data = NULL; unsigned int w, h; unsigned ret = lodepng_decode32_file(&data, &w, &h, filename); if (ret == 0) { temp = SDL_CreateRGBSurfaceFrom((void*)data, w, h, 32, 4 * w, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000); if (temp) { SDL_Surface *t2 = SDL_ConvertSurface(temp, temp->format, 0); SDL_FreeSurface(temp); temp = t2; } free(data); } return temp; }
int main(int argc, char *argv[]){ error= lodepng_decode32_file(&image, &width, &height, "../gfx/numbers4map.png"); if( error ) printf("Error %u: %s\n", error, lodepng_error_text(error)), exit(-1); if( width!= 50 && height!= 21 ) printf("Error. Bad dimmensions"); fo= fopen("numbers4map.h", "wb+"); fprintf(fo, "short n4m[]={"); if( !fo ) printf("\nCannot create output file: numbers4map.h\n"), exit(-1); for ( i= 0; i < 3; i++ ) for ( j= 0; j < 10; j++ ){ (i || j) && fprintf(fo, "0x%04x,", m); for ( m= k= 0; k < 5; k++ ) for ( l= 0; l < 3; l++ ) m<<= 1, m|= !image[((7*i+k+1)*50+j*5+l+1)*4]; } fprintf(fo, "0x%04x};", m); fclose(fo); free(image); }
int main(VOID * task, int argc, char * argv[]) { unsigned w, h, x, y; if(argc != 2) { printf("usage: showpng pngFileName"); return -1; } char * tmp = NULL; if(detect_filename(argv[1], &tmp) == FALSE) { printf("the file \"%s\" is not exists\n", argv[1]); return -1; } if(tmp == NULL) tmp = argv[1]; printf("now load and decode %s\n", tmp); unsigned error = lodepng_decode32_file(&image, &w, &h, tmp); /*stop if there is an error*/ if(error) { printf("decoder error %u: %s", error, lodepng_error_text(error)); if(tmp != argv[1]) free(tmp); return 0; } if(tmp != argv[1]) free(tmp); /*avoid too large window size by downscaling large image*/ if(w / 1024 >= jump) jump = w / 1024 + 1; if(h / 1024 >= jump) jump = h / 1024 + 1; img_w = w; img_h = h; VOID * hshowpng = NULL; showpng.x = 310; showpng.y = 160; showpng.width = w / jump + 2; showpng.height = h / jump + 21; showpng.mywin_callback = (MY_WINDOW_CALLBACK)showpng_win_callback; showpng.task = task; hshowpng = (VOID *)syscall_create_my_window(&showpng); TASK_MSG msg; int ret; while(TRUE) { ret = syscall_get_tskmsg(task,&msg,TRUE); if(ret != 1) { syscall_idle_cpu(); continue; } switch(msg.type) { case MT_CREATE_MY_WINDOW: syscall_dispatch_win_msg(&msg, hshowpng); break; case MT_CLOSE_MY_WINDOW: return 0; break; default: break; } } return 0; }
// png void read_png(char* filename, uint8_t** image, uint32_t* width, uint32_t* height) { unsigned error = lodepng_decode32_file(image, width, height, filename); if(error) printf("error %u: %s\n", error, lodepng_error_text(error)); }
image *load_image(const char *imgpath) { image *img = (image*)malloc(sizeof(image)); lodepng_decode32_file(&img->data, &img->width, &img->height, imgpath); return img; }
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; }