zoukankan      html  css  js  c++  java
  • ffffff

    http://www.ibm.com/developerworks/cn/linux/l-cn-linuxglb/

    http://blog.csdn.net/wocjj/article/details/7867191

    int read_JPEG_file (char * filename)
    {
    struct jpeg_decompress_struct cinfo;
    struct jpeg_error_mgr jerr;
    FILE * infile; /* source file */
    FILE * outfile; /* source file */
    JSAMPARRAY buffer; /* Output row buffer */
    int row_stride; /* physical row width in output buffer */
    //unsigned int nWidth = 1280;
    //unsigned int nHeight = 720;
    unsigned char* pcOutBuf = NULL;
    char* pcRowBuf = NULL;

    if ((infile = fopen(filename, "rb")) == NULL)
    {
    fprintf(stderr, "can't open %s ", filename);
    return 0;
    }

    cinfo.err = jpeg_std_error(&jerr);

    jpeg_create_decompress(&cinfo);

    jpeg_stdio_src(&cinfo, infile);

    (void) jpeg_read_header(&cinfo, TRUE);
    printf("width=%d, height=%d ", cinfo.image_width, cinfo.image_height);
    printf("color components:%d, jpeg color space:%d ", cinfo.num_components, cinfo.jpeg_color_space);

    printf("decompress--->color components:%d, jpeg color space:%d ", cinfo.out_color_components, cinfo.out_color_space);
    //printf("out_width=%d, out_height=%d ", cinfo.output_width, cinfo.output_height);
    //printf("component=%d ", cinfo.output_components);

    cinfo.out_color_space=JCS_GRAYSCALE;
    cinfo.out_color_components = 1;
    //jpeg_set_colorspace(&cinfo, JCS_GRAYSCALE);
    //执行jpeg_start_decompress后才能获取到上面的打印信息
    (void) jpeg_start_decompress(&cinfo);

    printf("out_width=%d, out_height=%d ", cinfo.output_width, cinfo.output_height);
    printf("component=%d ", cinfo.output_components);
    printf("decompress--->color components:%d, jpeg color space:%d ", cinfo.out_color_components, cinfo.out_color_space);

    row_stride = cinfo.output_width * cinfo.output_components;
    pcOutBuf = (unsigned char*)malloc(cinfo.output_width*cinfo.output_height*cinfo.output_components);
    pcRowBuf = (char*)malloc(row_stride);

    if ((outfile = fopen("xxx.gray", "wb")) == NULL)
    {
    fprintf(stderr, "can't open %s ", "xxx.gray");
    return 0;
    }

    while (cinfo.output_scanline < cinfo.output_height)
    {
    (void) jpeg_read_scanlines(&cinfo, &pcRowBuf, 1);
    memcpy(pcOutBuf, pcRowBuf, row_stride);
    pcOutBuf += row_stride;

    fwrite(pcRowBuf,1, row_stride, outfile);
    // printf("cinfo.output_scanline=%d ", cinfo.output_scanline);
    }

    fclose(infile);
    fclose(outfile);


    if (NULL != pcOutBuf)
    free(pcOutBuf);

    return 0;
    }

  • 相关阅读:
    什么是Referer?Referer的作用?空Referer是怎么回事?
    http状态码301和302详解及区别——辛酸的探索之路
    linux下redis的安装、启动、关闭和卸载
    Ubuntu下的redis安装过程
    apt-get build-dep命令详解
    apt 和 apt-get的区别
    Cortex-M3 入门指南(三):时钟总线与复位时钟控制器
    objdump命令解析
    ubuntu gcc 安装 使用
    你知道 GNU Binutils 吗?【binutils】
  • 原文地址:https://www.cnblogs.com/black-mamba/p/6115445.html
Copyright © 2011-2022 走看看