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

  • 相关阅读:
    简单的模板解析函数
    HTML通过事件传递参数到js 二 event
    HTML通过事件传递参数到js一
    通过this获取当前点击选项相关数据
    LeetCode 20. 有效的括号(Valid Parentheses)
    LeetCode 459. 重复的子字符串(Repeated Substring Pattern)
    LeetCode 14. 最长公共前缀(Longest Common Prefix)
    LeetCode 168. Excel表列名称(Excel Sheet Column Title)
    LeetCode 171. Excel表列序号(Excel Sheet Column Number) 22
    LeetCode 665. 非递减数列(Non-decreasing Array)
  • 原文地址:https://www.cnblogs.com/black-mamba/p/6115445.html
Copyright © 2011-2022 走看看