LIBJPG
+ -

libjpg编译

2024-08-19 12 0

本人下载的是jpeg-9b版本
将下载来下来的文件解压后:

  • 将文件内部的jconfig.vms文件名改为jconfig.h
    • 将makefile.vc中第12行的!include <win32.mak>改为!include <C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include\win32.mak>
      然后打开vs2019的编译环境:
      121648408423
      切换到源文件目录,执行命令
      nmake -f makefile.vc
      
      编译
      121925203009
  • 编译后会生成x64的libjpeg.lib
    121905677170

测试工程

  • 工程中配置VC的头文件和lib文件目录
#include <stdio.h>
#include <string.h>
#include <jpeglib.h>

#pragma comment(lib,"libjpeg.lib")
#define JPEG_QUALITY 100 //图片质量

int savejpg(char* pdata, char* jpg_file, int width, int height)
{  //分别为RGB数据,要保存的jpg文件名,图片长宽
    int depth = 3;
    JSAMPROW row_pointer[1];//指向一行图像数据的指针
    struct jpeg_compress_struct cinfo;
    struct jpeg_error_mgr jerr;
    FILE* outfile;

    cinfo.err = jpeg_std_error(&jerr);//要首先初始化错误信息
    //* Now we can initialize the JPEG compression object.
    jpeg_create_compress(&cinfo);

    if ((outfile = fopen(jpg_file, "wb")) == NULL)
    {
        fprintf(stderr, "can't open %s\n", jpg_file);
        return -1;
    }
    jpeg_stdio_dest(&cinfo, outfile);

    cinfo.image_width = width;             //* image width and height, in pixels
    cinfo.image_height = height;
    cinfo.input_components = depth;    //* # of color components per pixel
    cinfo.in_color_space = JCS_RGB;     //* colorspace of input image
    jpeg_set_defaults(&cinfo);

    jpeg_set_quality(&cinfo, JPEG_QUALITY, TRUE); //* limit to baseline-JPEG values
    jpeg_start_compress(&cinfo, TRUE);

    int row_stride = width * 3;
    while (cinfo.next_scanline < cinfo.image_height)
    {
        row_pointer[0] = (JSAMPROW)(pdata + cinfo.next_scanline * row_stride);//一行一行数据的传,jpeg为大端数据格式
        jpeg_write_scanlines(&cinfo, row_pointer, 1);
    }

    jpeg_finish_compress(&cinfo);
    jpeg_destroy_compress(&cinfo);//这几个函数都是固定流程
    fclose(outfile);
    return 0;
}


int main(int argc, char* argv)
{
    char* pData = new char[100 * 255*4];
    memset(pData, 0, 100 * 255 * 3);

    long red = 0xff000000;

    for (int h = 0; h < 255; h++)
    {
        char* pColor = (char*)(pData + h * 100 * 3);
        for (int w = 0; w < 100; w++)
        {
            pColor[0] = 255;
            pColor[1] = 0;
            pColor[2] = 0;

            pColor+=3;
        }
    }
    char pfile[] = { "1.jpg" };
    savejpg(pData, pfile, 100, 255);

    return 0;
}

运行生成一个100x255的红色JPG图片

0 篇笔记 写笔记

libjpg
libjpg是处理JPG格式机关的。官网链接:http://libjpeg.sourceforge.net/下载链接:http://www.ijg.org/files/......
libjpg编译
本人下载的是jpeg-9b版本将下载来下来的文件解压后:将文件内部的jconfig.vms文件名改为jconfig.h将makefile.vc中第12行的!include 改为!include
函数代码:#define JPEG_QUALITY 100 //图片质量int savejpg2(char* pRGB, unsigned char* &jpeg_data, unsigned long& jpeg_size, int width, int height){......
打开Developer Command Prompt for VS 2019切换到libjpg解压后的目录C:UsersmypcDesktopjpegsrc.v9e.tarjpeg-9e>`此时请将下面的代码通过txt另存为:Win32.Mak,放在C:Usersmypc......
作者信息
站长漫谈
取消
感谢您的支持,我会继续努力的!
扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

您的支持,是我们前进的动力!