Linux---libjpeg use (jpg to RGB)

Source: Internet
Author: User

One: Compilation of the Libjpeg library


Download the source code, after decompression

./configure--prefix=/xxxx CC=ARM-LINUX-GCC--host=arm-linux--enable-shared--enable-static

---xxxx for the creation of dynamic static pants directory

----CC for Cross compiler

-----enable-shared---enable-static the active Static library


Then make,

Make install again, generate the corresponding header files and libraries in the XXX directory

Jconfig.h jerror.h jmorecfg.h jpeglib.h and libjpeg.9.so.1.0 libjpeg.a


Program writing

Example for framebuffer JPG picture format turn rgb (565)


TEST.c


#include <sys/types.h>

#include <sys/stat.h>

#include <fcntl.h>

#include <unistd.h>

#include <stdio.h>

#include <sys/mman.h>

#include <linux/fb.h>

#include <stdlib.h>


Header file

#include "Libinclude/jpeglib.h"

#include "Libinclude/jerror.h"



struct Fb_var_screeninfo var;

unsigned short *fbp;


Define Structure body

struct Jpeg_decompress_struct cinfo;

struct Jpeg_error_mgr jerr;


FILE * infile;



int main (int argc, char **argv)

{

int fd,screen_size,i,j;

unsigned short value;

int POS;

Char *rdata;

Char *tbmp[]={"bmp/t1.jpg", "bmp/t2.jpg", "bmp/t3.jpg", "bmp/t4.jpg",

"Bmp/t5.jpg", "bmp/t6.jpg", "bmp/t7.jpg", "bmp/t8.jpg", "bmp/t9.jpg",

"Bmp/t10.jpg", "Bmp/t11.jpg"};

char Tpos = 0;


FD = open ("/dev/fb0", O_RDWR);

if (fd<0)

Perror ("open");

IOCTL (Fd,fbioget_vscreeninfo,&var);

printf ("var x =%d, y =%d bits =%d".) \ n ", Var.xres, Var.yres,var.bits_per_pixel);

Screen_size = Var.xres *VAR.YRES*VAR.BITS_PER_PIXEL/8;

printf ("Screen_size is%d\n", screen_size);

FBP = (unsigned short *) mmap (0, screen_size, Prot_write | Prot_read, map_shared, FD, 0);

if (!FBP)

Goto Mmap_err;




Generate the corresponding variable

Cinfo.err = Jpeg_std_error (&jerr);

jpeg_create_decompress (&cinfo);

while (1)

{




Open picture File

if (infile = fopen (Tbmp[tpos], "rb") = = = NULL) {


fprintf (stderr, "can ' t open%s\n", "tu.jpg");

exit (1);

}

Tpos + +;

if (tpos>=11)

Tpos = 0;


Get header information

Jpeg_stdio_src=\ ' #\ ' "infile);

Jpeg_read_header (&cinfo, TRUE);

Allocating memory Storage bytes

Rdata= (char*) calloc (cinfo.image_width*cinfo.image_height*cinfo.num_components,1);

Start unpacking

Jpeg_start_decompress (&cinfo);

Jsamprow Row_pointer[1];

while (Cinfo.output_scanline < cinfo.output_height)

{

row_pointer[0] = & rdata[(cinfo.output_scanline) *cinfo.image_width*cinfo.num_components];

Jpeg_read_scanlines (&cinfo,row_pointer, 1);


}

End Decompression

Jpeg_finish_decompress (&cinfo);

Framebuffer fills the bytes just allocated

pos = 0;

for (i=0;i<var.yres;i++)

for (j=0;j<var.xres;j++)

{

rgb888 Turn rgb565

Value= ((rdata[pos]>>3) <<11) | ((rdata[pos+1]>>2) <<5) | (rdata[pos+2]>>3);

* (fbp+i*var.xres+j) = value;

POS +=3;

}

Sleep (3);

Fclose (infile);

}

Jpeg_destroy_decompress (&cinfo);

Munmap (FBP, screen_size);

Close (FD);

return 0;


Mmap_err:

Perror ("mmap\n");

return-1;

}




NOTE: JPG default decompression is rgb888



Used with dynamic libraries and static libraries


Static Library

At this point the test.c directory has test.c libjpeg.a

Jconfig.h jerror.h jmorecfg.h jpeglib.h


ARM-LINUX-GCC Test.c-o test-l./-ljpeg


Generate test put to board execution




Dynamic Library

At this time the test.c directory has test.c

Jconfig.h jerror.h jmorecfg.h jpeglib.h libjpeg.9.so.1.0


ARM-LINUX-GCC Test.c-o test-l./-l:libjpeg.9.so.1.0


Change the libjpeg.9.so.1.0 to libjpeg.9.so and put it in the Development Board/usr/lib directory


Generate test put to board execution




This article is from the "Guo Di Temple Technology Road" blog, please be sure to keep this source http://6902621.blog.51cto.com/6892621/1688052

Linux---libjpeg use (jpg to RGB)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.