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

  • 相关阅读:
    hibernate关联关系(多对多)
    hibernate关联关系(一对多)
    hibernate主键生成策略
    hibernate01
    利用Struts2拦截器完成文件上传功能
    layui的CRUD案列
    Struts2的CRUD
    Git中.gitignore文件不起作用
    在 Visual Studio 中使用 Q# 进行量子编程
    Elasticsearch 搜索
  • 原文地址:https://www.cnblogs.com/black-mamba/p/6115445.html
Copyright © 2011-2022 走看看