libtiff错误:未配置旧式JPEG压缩支持 [英] libtiff error: Old-style JPEG compression support is not configured

查看:539
本文介绍了libtiff错误:未配置旧式JPEG压缩支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Mac OS X上使用libtiff将TIFF转换为BMP时,出现以下错误:

While converting TIFF to BMP using libtiff on Mac OS X, I got these errors:

scannerdata.tif: Old-style JPEG compression support is not configured.

scannerdata.tif: Sorry, requested compression method is not configured.

我目前在Mac OS X中使用libtiff.

I am currently using libtiff in Mac OS X.

我将tiff转换为bmp:

My implementation of tiff to bmp:

static void tifftobmp(char *colorMode){

    DBG(1, ">> tifftobmp \n");

    /* For files and file header */
    char infile[PATH_MAX] = {0};
    char outfile[PATH_MAX] = {0};
    char tempfile[PATH_MAX] = {0};
    TIFF *tifFile;
    FILE *bmpFile, *tmpBitmapFile;
    uint32 image_width, image_height, long_val, short_val;

    /* For Colour table */
    unsigned char padding;
    unsigned short i;
    unsigned char value;

    /* For image information */
    Image_Information *image_info;
    image_info = (Image_Information *)malloc(sizeof(Image_Information));

    sprintf(infile, TIFF_IMAGE_DATA);
    sprintf(outfile, BMP_IMAGE_DATA);
    sprintf(tempfile, TEMP_IMAGE_DATA);

    /* Open necessary files */
    tifFile = TIFFOpen(infile, "r");
    if (!tifFile){
        DBG(128, "Can't open %s for reading\n", infile);
        TIFFClose(tifFile);
    }

    bmpFile = fopen(outfile, "wb");
    if (!bmpFile){
        DBG(128, "Can't open %s for writing\n", outfile);
        fclose(bmpFile);
    }

    tmpBitmapFile = fopen(tempfile, "wb");
    if (!tmpBitmapFile){
        DBG(128, "Can't open %s for writing\n", tempfile);
        fclose(tmpBitmapFile);
    }

    TIFFGetField(tifFile, TIFFTAG_IMAGELENGTH, &image_height);
    TIFFGetField(tifFile, TIFFTAG_IMAGEWIDTH, &image_width);

    image_info->img_height = image_height;
    image_info->img_width = image_width;

    /* Get Image Info Color */
    if(strcmp(colorMode,"COLOR") == 0){
        get_image_info_color(image_info);

    }else if (strcmp(colorMode,"GRAY") == 0){
        get_image_info_gray(image_info);

    }else if(strcmp(colorMode,"MONO") == 0){
        get_image_info_mono(image_info);

    }

    /* Set Header */
    fwrite("BM", 1, 2, bmpFile);        /* Signature */

    long_val = sizeof(BITMAPFILEHEADER)  + sizeof(BITMAPINFOHEADER) + image_info->img_scansize * image_info->img_height;
    fwrite(&long_val, 4, 1, bmpFile);   /* Size in bytes of the bitmap file */

    short_val = 0;
    fwrite(&short_val, 2, 1, bmpFile);  /* Reserved, set as 0 */
    fwrite(&short_val, 2, 1, bmpFile);  /* Reserved, set as 0 */

    if(strcmp(colorMode,"COLOR") == 0){ /* Offset of the image from file start */
        long_val = 54;

    }else{
        long_val = 54 + (4 * (1 << image_info->img_bits_per_pixel));
    }
    fwrite(&long_val, 4, 1, bmpFile);

    long_val = sizeof(BITMAPINFOHEADER);  /* Size of BMPInfoHeader structure */
    fwrite(&long_val, 4, 1, bmpFile);
    fwrite(&image_info->img_width, 4, 1, bmpFile);
    fwrite(&image_info->img_height, 4, 1, bmpFile);

    short_val = 1;                  /* Number of image planes */
    fwrite(&short_val, 2, 1, bmpFile);

    if(strcmp(colorMode,"MONO") == 0){ /* Number of bits per pixel */
        short_val = image_info->img_bits_per_pixel;

    }else if (strcmp(colorMode,"COLOR") == 0){
        short_val = image_info->img_bits_per_pixel;

    }else if (strcmp(colorMode,"GRAY") == 0){
        short_val = image_info->img_bits_per_pixel;

    }
    fwrite(&short_val, 2, 1, bmpFile);
    long_val = 0;                   /* Compression method */
    fwrite(&long_val, 4, 1, bmpFile);
    long_val = 0;                   /* Size of uncompressed image in bytes */
    fwrite(&long_val, 4, 1, bmpFile);
    long_val = 0;                   /* X resolution, pixels per meter */
    fwrite(&long_val, 4, 1, bmpFile);
    long_val = 0;                   /* Y resolution, pixels per meter */
    fwrite(&long_val, 4, 1, bmpFile);

    if(strcmp(colorMode,"COLOR") == 0){  /* Size of colour table */
        long_val = 0;

    }else{
        long_val = 1 << image_info->img_bits_per_pixel;

    }
    fwrite(&long_val, 4, 1, bmpFile);

    long_val = 0;                   /* Number of important colours */
    fwrite(&long_val, 4, 1, bmpFile);

    /* Colour table */
    if(strcmp(colorMode,"MONO") == 0){
        value = 0xFF;
        padding = 0;

        /* white */
        fwrite(&value, 1, 1, bmpFile); /* R component */
        fwrite(&value, 1, 1, bmpFile); /* G component */
        fwrite(&value, 1, 1, bmpFile); /* B component */
        fwrite(&padding, 1, 1, bmpFile); /* padding */

        /* black */
        value = 0x00;
        fwrite(&value, 1, 1, bmpFile); /* R component */
        fwrite(&value, 1, 1, bmpFile); /* G component */
        fwrite(&value, 1, 1, bmpFile); /* B component */
        fwrite(&padding, 1, 1, bmpFile); /* padding */

    }else if (strcmp(colorMode,"GRAY") == 0){
        padding = 0;

        for ( i = 0; i <= 255; i++ ){
            fwrite(&i, 1, 1, bmpFile); /* R component */
            fwrite(&i, 1, 1, bmpFile); /* G component */
            fwrite(&i, 1, 1, bmpFile); /* B component */
            fwrite(&padding, 1, 1, bmpFile); /* padding */
        }

    }

    /* Read and write image */
    if(strcmp(colorMode,"MONO") == 0){
        read_mono_image(tifFile, tmpBitmapFile, image_info);

    }else if(strcmp(colorMode,"GRAY") == 0){
        read_gray_image(tifFile, tmpBitmapFile, image_info);

    }else if(strcmp(colorMode,"COLOR") == 0){
        read_color_image(tifFile, bmpFile, image_info);
    }

    if(strcmp(colorMode,"COLOR") != 0){
        fclose(tmpBitmapFile);
        flip_image(image_info, bmpFile);
    }

    fclose(bmpFile);
    TIFFClose(tifFile);

    DBG(1, "<< tifftobmp \n");

}

推荐答案

在"nmake.opt"中查看Libtiff的源代码

Take a look at the source code of Libtiff in "nmake.opt"

#
# Uncomment and edit following lines to enable JPEG support.
#
#JPEG_SUPPORT   = 1

...

!IFDEF JPEG_SUPPORT
LIBS        = $(LIBS) $(JPEG_LIB)
EXTRAFLAGS  = -DJPEG_SUPPORT -DOJPEG_SUPPORT $(EXTRAFLAGS)
!ENDIF

因此,默认情况下,不启用JPEG支持.

So, by default the JPEG support not enabled.

这篇关于libtiff错误:未配置旧式JPEG压缩支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆