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;
    }

  • 相关阅读:
    <Listener>HttpSessionListener和HttpSessionAttributeListener区别
    @WebFilter怎么控制多个filter的执行顺序
    Springboot+Mybatis+MySQL实例练习时踩坑记录
    Git学习篇之git remote add origin错误
    Springboot高版本中@ConfigurationProperties注解取消location属性
    mevan中GroupId和ArtifactId到底怎么填?
    sqrt()函数对素数判断的优化
    oj错误之char型超出范围
    排序算法之桶排序
    Spring中常用注解
  • 原文地址:https://www.cnblogs.com/black-mamba/p/6115445.html
Copyright © 2011-2022 走看看