Libjpeg Installation and use

Source: Internet
Author: User
Tags comments error handling win32
turn from: http://blog.csdn.net/ice__snow/article/details/52563944, there are a few places to make a part of the modification First, compile

Download Address http://www.ijg.org/ 1, download and unzip, put in a easy to find directory on the line:

2, enter jpeg-9b, find Jconfig.vc, copy and rename to Jconfig.h, otherwise it will generate Jconfig warning

3, find makefile.vc This file, open (any text editor) find this line


Change the path to WIN32.MK on your computer, each person may not be the same, the path difference may not be very big, my is C:\Program Files (x86) \microsoft Sdks\windows\v7.1a\include\ Win32.mak, instead
4, ready to compile, I use the VS2015 command prompt, do not choose Arm, select VS2015 x86 x64 compatible tool command Prompt

5, enter the jpeg-9b directory, input compile command to start compiling


command: Nmake-f makefile.vc 6, compiled after the directory found in the library Libjpeg.lib on the compilation succeeded. Second, use

Specific use in the directory of the EXAMPLE.C, the comments are very thin, see the basic will be used. Here I'm simply talking about usage. 1. Use configuration

There are two ways of doing this:
First: Add the path of the Libjpeg header file and the path of the Lib to the VS Project, the project properties page
, and then in

Add Libjpeg.lib in

The second kind: the use of the header files and Libjpeg.lib to your project, only in the project to do the first third step to add libjpeg.lib on the line. 2. Use

The program contains the header file # include <jpeglib.h> on the line.
Most of the copy, the details can be seen inside the English notes, the main changes in several places on the line, see the following Chinese comments:

These are related to error handling, without tube struct my_error_mgr {struct jpeg_error_mgr pub;  /* "Public" fields */Jmp_buf setjmp_buffer;

/* for return to caller */};

typedef struct MY_ERROR_MGR * MY_ERROR_PTR;
    METHODDEF (void) my_error_exit (j_common_ptr cinfo) {my_error_ptr myerr = (my_error_ptr) cinfo->err; (*cinfo->err->output_message)
    (Cinfo);
LONGJMP (Myerr->setjmp_buffer, 1); 
    }///Read image function//I added a parameter that is the Zmatrix class object in my library to hold the read image data GLOBAL (int) read_jpeg_file (char * filename, z::matrix8u & img) {
    struct Jpeg_decompress_struct cinfo;
    struct My_error_mgr jerr;      
    FILE * infile;      
    Jsamparray buffer; 

    int row_stride;
        if (infile = fopen (filename, "RB")) = = NULL) {fprintf (stderr, "can ' t open%s\n", filename);
    return 0;
    } Cinfo.err = Jpeg_std_error (&jerr.pub);
    Jerr.pub.error_exit = My_error_exit;
        if (setjmp (Jerr.setjmp_buffer)) {jpeg_destroy_decompress (&cinfo);
        Fclose (infile); RetUrn 0;

    } jpeg_create_decompress (&cinfo);

    JPEG_STDIO_SRC (&cinfo, infile);
    This function gets the information to read the picture, including the high and wide (void) Jpeg_read_header (&cinfo, TRUE) of the image;

    Add your own code here, get or user-to-image information Img.create (Cinfo.image_height, Cinfo.image_width, 3);

    (void) jpeg_start_decompress (&cinfo);
    Row_stride = Cinfo.output_width * cinfo.output_components;

    Buffer = (*cinfo.mem->alloc_sarray) ((j_common_ptr) &cinfo, Jpool_image, Row_stride, 1); while (Cinfo.output_scanline < cinfo.output_height) {//a line reads (void) Jpeg_read_scanlines (&cinfo,

        buffer, 1); Add code here to get a picture of the pixel data//buffer saved the reading of the current row of data, save order is RGB//Output_scanline is already read the number of lines for (int i = 0; i < Img.cols;
            ++i) {Img[cinfo.output_scanline-1][i * 3 + 2] = buffer[0][i * 3 + 0];
            Img[cinfo.output_scanline-1][i * 3 + 1] = buffer[0][i * 3 + 1];
      Img[cinfo.output_scanline-1][i * 3 + 0] = buffer[0][i * 3 + 2];  }} (void) jpeg_finish_decompress (&cinfo);
    Jpeg_destroy_decompress (&cinfo);
    Fclose (infile);
return 1; }

Code: Https://github.com/ffiirree/zMatrix/blob/master/zMatrix/zgui/zgui.cpp

Installation under LINUX

1. Download under Libjpeg to/usr/local/bin

2./configure--enable-shared--prefix= $CONFIGURE _prefix
3. Make

4. Make install

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.