gpt4 book ai didi

c - libtiff 错误 : Old-style JPEG compression support is not configured

转载 作者:太空宇宙 更新时间:2023-11-04 00:05:40 25 4
gpt4 key购买 nike

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

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

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

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

我对 bmp 的 tiff 实现:

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的源代码

#
# 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 支持。

关于c - libtiff 错误 : Old-style JPEG compression support is not configured,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25359846/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com