Exemplo n.º 1
0
int FPBmpToRGB565(char* bmpfile, int w, int h)
{
        unsigned short* buffer=(unsigned short*)(bmpfile);
        char* tmpbuf=NULL;
        int y,x,index;
        int i=0;
        unsigned short color;

	w=((w *8 + 31)/32) * 4;

        tmpbuf=MALLOC(w*h);
        if(tmpbuf==NULL)
                return 0;

        memcpy(tmpbuf,(char*)buffer,w*h);

        for(y=0; y < h; y++)
        {
                for (x = 0; x < w; x++)
                {
                        index=tmpbuf[(h-y-1)*w+x];
                        color = RGB888toRGB565(index, index,index);
                        buffer[i]=color;
                        i++;
                }
        }
        FREE(tmpbuf);
        return 1;
}
Exemplo n.º 2
0
int Bmp8ToRGB565(unsigned char* bmpfile, int w, int h)
{
        int y,x;
	unsigned char index=0;
        int i=0;
        unsigned short color;
	char* temp=NULL;

	temp=MALLOC(640*480);
	if(temp ==NULL)
		return 0;

	memcpy(temp,(char*)(bmpfile+54+1024), 640*480);

        for(y=0; y < h; y++)
        {
                for (x = 0; x < w; x++)
                {
                        index=temp[(h-y-1)*w+x];
                        color = RGB888toRGB565(index, index, index);
			face_bmp[i]=color;
			i++;
                }
        }
	FREE(temp);
        return 1;
}
Exemplo n.º 3
0
/************ function implementation ********************/
int main(int argc, char *argv[])
{
    /*
     * declaration for jpeg decompression
     */
    struct jpeg_decompress_struct cinfo;
    struct jpeg_error_mgr jerr;
    FILE           *infile;
    unsigned char  *buffer;
    /*
     * declaration for framebuffer device
     */
    int             fbdev;
    char           *fb_device;
    unsigned char  *fbmem;
    unsigned int    screensize;
    unsigned int    fb_width;
    unsigned int    fb_height;
    unsigned int    fb_depth;
    unsigned int    x;
    unsigned int    y;
    /*
     * check auguments
     */
    /*if (argc != 2) {
        usage("insuffient auguments");
        exit(-1);
    }*/
    /*
     * open framebuffer device
     */
    if((fb_device = getenv("FRAMEBUFFER")) == NULL)
    { 
        fb_device = FB_DEV; 
    }
        
    fbdev = fb_open(fb_device);
    /*
     * get status of framebuffer device
     */
    fb_stat(fbdev, &fb_width, &fb_height, &fb_depth);
    printf("%d ", fb_width);
    printf("%d ", fb_height);
    printf("%d\n", fb_depth);
    /*
     * map framebuffer device to shared memory
     */
    screensize = fb_width * fb_height * fb_depth / 8;
    fbmem = fb_mmap(fbdev, screensize);
    if(fbmem == 0)
    {
        printf("fb mmap error");
    }
    /*open input jpeg file   */
    char jpgname[32] = {0};
    int jpgcnt = 0;
   // SystemSetBlankInterVal(0);
    while(1)
    {
        //for(jpgcnt = 0; jpgcnt < 10; jpgcnt++)
        {
            /*
            * init jpeg decompress object error handler
            */
            sprintf(jpgname, "%s","./picture.jpg");
            //sprintf(jpgname, "/var/run/%d.jpg", jpgcnt);
            printf("begint to display %s\n", jpgname);
            cinfo.err = jpeg_std_error(&jerr);
            jpeg_create_decompress(&cinfo);
            if((infile = fopen(jpgname, "rb+")) == NULL)
            {
                fprintf(stderr, "open %s failed\n", "1.jpg");
                exit(-1);
            }
            /*
             * bind jpeg decompress object to infile
             */
            jpeg_stdio_src(&cinfo, infile);
            /*
             * read jpeg header
             */
            jpeg_read_header(&cinfo, TRUE);
            /*
             * decompress process.
             * note: after jpeg_start_decompress() is called
             * the dimension infomation will be known,
             * so allocate memory buffer for scanline immediately
             */
            jpeg_start_decompress(&cinfo);
            /*if ((cinfo.output_width > fb_width) ||
                (cinfo.output_height > fb_height)) {
                printf("too large JPEG file,cannot display\n");
                return (-1);
            }*/
            buffer = (unsigned char *) malloc(cinfo.output_width *
                                              cinfo.output_components);
            y = 0;
            while(cinfo.output_scanline < cinfo.output_height)
            {
                jpeg_read_scanlines(&cinfo, &buffer, 1);
                if(fb_depth == 16)
                {
                    unsigned short  color;
                    for(x = 0; x < cinfo.output_width; x++)
                    {
                        color = RGB888toRGB565(buffer[x * 3],
                                               buffer[x * 3 + 1]
                                               , buffer[x * 3 + 2]);
                        fb_pixel(fbmem, fb_width, fb_height, x, y, color);
                    }
                }
                else if(fb_depth == 24)
                {
                    memcpy((unsigned char *) fbmem + y * fb_width * 3,
                           buffer, cinfo.output_width * cinfo.output_components);
                }
                y++;                    // next scanline
            }
            /*
             * finish decompress, destroy decompress object
             */
            jpeg_finish_decompress(&cinfo);
            jpeg_destroy_decompress(&cinfo);
            /*
             * release memory buffer
             */
            free(buffer);
            /*
             * close jpeg inputing file
             */
            fclose(infile);
            usleep(400000);
        }
    }
    /*
     * unmap framebuffer's shared memory
     */
    fb_munmap(fbmem, screensize);
    /*
     * close framebuffer device
     */
    fb_close(fbdev);
    return (0);
}
Exemplo n.º 4
0
int main(int argc, char* argv[]) {
    // check parameter
    if (argc != 2 && argc != 3) {
        printf("Usage: png2c [PNG file] [-a]\n"
                "A header file will be generated in the same directory\n"
                "If -a is provided then the output will be RGB5A1 instead of RGB565.\n");
        return -1;
    }
    
    // open file
    printf("Opening file %s...\n", argv[1]);
    char header[8];
    file = fopen(argv[1], "rb");
    if (!file) {
        printf("Could not open file %s.\n", argv[1]);
        return -1;
    }
    
    // check if RGB5A1
    if (argc == 3 && 0 == strcmp(argv[2], "-a"))
        generate5A1 = 1;

    // read the header
    printf("Reading header...\n");
    if (fread(header, 1, 8, file) <= 0) {
        printf("Could not read PNG header.\n");
        return -1;
    }
    
    // make sure it's a PNG file
    if (png_sig_cmp(header, 0, 8)) {
        printf("File is not a valid PNG file.\n");
        return -1;
    }
    printf("Valid PNG file found. Reading more...\n");
    
    // create the read struct
    pPng = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
    if (!pPng) {
        printf("Error: couldn't read PNG read struct.\n");
        return -1;
    }

    // create the info struct
    png_infop pInfo = png_create_info_struct(pPng);
    if (!pInfo) {
        printf("Error: couldn't read PNG info struct.\n");
        png_destroy_read_struct(&pPng, (png_infopp)0, (png_infopp)0);
        return -1;
    }
    
    // basic error handling
    if (setjmp(png_jmpbuf(pPng))) {
        printf("Error reading PNG file properties.\n");
        return -1;
    }
    
    // read PNG properties
    png_init_io(pPng, file);
    png_set_sig_bytes(pPng, 8);
    png_read_info(pPng, pInfo);
    width = png_get_image_width(pPng, pInfo);
    height = png_get_image_height(pPng, pInfo);
    colorType = png_get_color_type(pPng, pInfo);
    bitDepth = png_get_bit_depth(pPng, pInfo);
    numPasses = png_set_interlace_handling(pPng);
    png_read_update_info(pPng, pInfo);
    printf("Metadata: w: %i, h: %i, color type: %i, bit depth: %i, num passes: %i\n", width, height, colorType, bitDepth, numPasses);

    // read the file
    if (setjmp(png_jmpbuf(pPng))) {
        printf("Error reading PNG file data.\n");
        return -1;
    }
    rows = (png_bytep*) malloc(sizeof(png_bytep) * height);
    for (y = 0; y < height; y++)
        rows[y] = (png_byte*) malloc(png_get_rowbytes(pPng,pInfo));
    png_read_image(pPng, rows);
    fclose(file);
    
    // verify that the PNG image is RGBA
    if (png_get_color_type(pPng, pInfo) != PNG_COLOR_TYPE_RGBA) {
        printf("Error: Input PNG file must be RGBA (%d), but is %d.", PNG_COLOR_TYPE_RGBA, png_get_color_type(pPng, pInfo));
        return -1;
    }
    
    // get the name of the image, without the extension (assume it ends with .png)
    size_t len = strlen(argv[1]);
    char *imageName = malloc(len - 3);
    memcpy(imageName, argv[1], len - 4);
    imageName[len - 4] = 0;
    printf("Creating output file %s.h...\n", imageName);
                       
    // create output file
    FILE *outputHeader, *outputSource;
    char outputHeaderName[100], outputSourceName[100];
    sprintf(outputHeaderName, "%s.h", imageName);
    sprintf(outputSourceName, "%s.c", imageName);
    outputHeader = fopen(outputHeaderName, "w"); // overwrite/create empty file
    outputSource = fopen(outputSourceName, "w"); // overwrite/create empty file
    
    // write the header
    fprintf(outputHeader,
        "// Generated by png2c [(c) Oleg Vaskevich 2013]\n\n"
        "#ifndef _%s_H_\n"
        "#define _%s_H_\n\n"
        "extern const unsigned int %s_width;\n"
        "extern const unsigned int %s_height;\n"
        "extern const int %s_size;\n"
        "extern const unsigned short %s[];\n\n"
        "#endif\n\n",
        imageName, imageName, imageName, imageName, imageName, imageName);
    fclose(outputHeader);

    // write the source
    fprintf(outputSource,
        "// Generated by png2c [(c) Oleg Vaskevich 2013]\n\n"
        "#include \"%s.h\"\n\n"
        "const unsigned int %s_width = %u;\n"
        "const unsigned int %s_height = %u;\n"
        "const int %s_size = %u;\n"
        "const unsigned short %s[] = {\n",
        imageName, imageName, width, imageName, height, imageName, width*height, imageName);

    // go through each pixel
    printf("Processing pixels...\n");
    for (y=0; y<height; y++) {
        png_byte* row = rows[y];
        for (x=0; x<width; x++) {
            png_byte* pixel = &(row[x*4]);
            unsigned short convPixel = generate5A1 ? RGB8888toRGB5A1(pixel[0], pixel[1], pixel[2], pixel[3]) : RGB888toRGB565(pixel[0], pixel[1], pixel[2]);
            // the last pixel shouldn't have a comma
            if (y == height-1 && x == width-1)
                fprintf(outputSource, "0x%x\n};\n", convPixel);
            else
                fprintf(outputSource, "0x%x, ", convPixel);
        }
        fprintf(outputSource, "\n");
    }
    
    fclose(outputSource);
    if (generate5A1)
        printf("Output format is RGB5A1.\n");
    else
        printf("Output format is RGB565.\n");
    printf("Done! Generated %s.h and %s.c.\n", imageName, imageName);

    return 0;
}
Exemplo n.º 5
0
void drawNewRecordMenu(newRecordMenu* menu){
	drawBitmap(menu->fundo, 0, 0,ALIGN_LEFT);
	drawString(menu->nome, 0.45*get_h_res(), 0.35*get_h_res(), RGB888toRGB565(255,255,255));
}