Pizus Posted September 3, 2012 Report Share Posted September 3, 2012 Hello everyone,don't know if it is of any interest but for those poor guys using windows (that don't have access to linux conversion tools) here is a small contribution to a simple image .dat generation process for ZPUino VGA with 8bit colors.1) select your image2) scale it to 160x120 pixels (almost any tools out there) and save in .png3) convert the palette (Corel Photo-paint->Image->Convert to palette and select the attached .pal file)4) save the new .png image5) convert the .png in .raw ( Irfanview->Save As ->(raw))6) rename to .datSo I hope I saved you an hour or two.ByeZPUino_VGA_8bit_palette.zip Link to comment Share on other sites More sharing options...
whiteimage Posted May 15, 2013 Report Share Posted May 15, 2013 an image app can do c# batch conversion just by a click, that can save a lot of time and effors, maybe even do auto-resize. Link to comment Share on other sites More sharing options...
alvieboy Posted August 21, 2013 Report Share Posted August 21, 2013 Pizus: if you're interested in porting the conversion tool to windows... just say There's a dependency on libpng, that what makes things harder. The code itself is very simple.#include <png.h>int width, height;png_byte color_type;png_byte bit_depth;png_structp png_ptr;png_infop info_ptr;int number_of_passes;png_bytep * row_pointers;#define COLOR_BYTES 2#define COLOR_WEIGHT_R 4#define COLOR_WEIGHT_G 4#define COLOR_WEIGHT_B 4#define COLOR_SHIFT_R (COLOR_WEIGHT_B+COLOR_WEIGHT_G)#define COLOR_SHIFT_G (COLOR_WEIGHT_#define COLOR_SHIFT_B 0int readpng(const char*name){ unsigned char header[8]; int y; FILE *f = fopen(name, "rb"); if (!f) { perror("fopen"); return -1; } fread(header, 1, 8, f); if (png_sig_cmp(header, 0, 8)) { fprintf(stderr,"Invalid PNG file"); fclose(f); return -1; } /* initialize stuff */ png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if (!png_ptr) { fprintf(stderr,"Cannot read struct\n"); return -1; } info_ptr = png_create_info_struct(png_ptr); if (!info_ptr) { fprintf(stderr,"Cannot create struct\n"); return -1; } png_init_io(png_ptr, f); png_set_sig_bytes(png_ptr, 8); png_read_info(png_ptr, info_ptr); width = png_get_image_width(png_ptr, info_ptr); height = png_get_image_height(png_ptr, info_ptr); color_type = png_get_color_type(png_ptr, info_ptr); bit_depth = png_get_bit_depth(png_ptr, info_ptr); number_of_passes = png_set_interlace_handling(png_ptr); png_read_update_info(png_ptr, info_ptr); row_pointers = (png_bytep*) malloc(sizeof(png_bytep) * height); for (y=0; y<height; y++) row_pointers[y] = (png_byte*) malloc(png_get_rowbytes(png_ptr,info_ptr)); png_read_image(png_ptr, row_pointers); fclose(f); return 0;}void process(){ FILE *outf; outf=fopen("image.dat","wb"); if (NULL==outf) { perror("Cannot open file"); return; } if (png_get_color_type(png_ptr, info_ptr) != PNG_COLOR_TYPE_RGB) { fprintf(stderr,"Unsupported format %d %d\n", PNG_COLOR_TYPE_RGB, png_get_color_type(png_ptr, info_ptr)); return; } int x,y; unsigned int v; for (y=0; y<height; y++) { png_byte* row = row_pointers[y]; for (x=0; x<width; x++) { png_byte* ptr = &(row[x*3]); /* printf("Pixel at position [ %d - %d ] has RGB values: %02x - %02x - %02x\n", x, y, ptr[0], ptr[1], ptr[2]);*/ ptr[0] = (ptr[0] >> (8- COLOR_WEIGHT_R) ); ptr[1] = (ptr[1] >> (8-COLOR_WEIGHT_G)); ptr[2] = (ptr[2] >> (8-COLOR_WEIGHT_); v = (ptr[0]<<(COLOR_SHIFT_R)) + (ptr[1]<<COLOR_SHIFT_G) + (ptr[2]<<COLOR_SHIFT_;#if COLOR_BYTES == 2 { unsigned char rv = (v>>8)&0xff; fwrite(&rv,1,1,outf); rv=v&0xff; fwrite(&rv,1,1,outf); }#else { unsigned char rv = v&0xff; fwrite(&rv,1,1,outf); }#endif } } fclose(outf);}int main(int argc,char **argv){ if (argc<2) return -1; if (readpng(argv[1])<0) return -1; if (width!=160 || height!=120) { fprintf(stderr,"Image size not 160x120\n"); return -1; } process(); return 0;}Alvie Link to comment Share on other sites More sharing options...
fgimage Posted January 7, 2014 Report Share Posted January 7, 2014 thank you for the codes up here. i have been researching image product and here is one i found perform the followign things. image processing and image conversion mutiple functions are provideed as well.hope it will help you in the way it does to me. Link to comment Share on other sites More sharing options...
Nana111 Posted March 12, 2014 Report Share Posted March 12, 2014 Hi thereThanks for your sharing for code.But it is harder for me to do that.Is there any image program which supports to convert image or process the image directly .Thanks a lot. Link to comment Share on other sites More sharing options...
jezsmith41 Posted August 6, 2015 Report Share Posted August 6, 2015 Given that I nearly smacked a Linux weeny very hard in the mouth this morning because of his patronising attitude and his overriding obsession with the wittering of the paranoid delusional tramp that is Richard Stallman, I am quite glad I don't use linux Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.