--- Begin Message ---
Package: libpano13-0
Version: 2.9.12.dfsg-3
Severity: normal
Tags: patch
libpano does not recognize an image type if the filename is not of the
correct form (i.e. with a 3 letter extension corresponding to the type).
My images are (unfortunately) named *.jpeg and so libpano does not
recognize them.
Fortunately for all the types of images that libpano knows of, the first
byte is different. I've done a patch (attached) that reads the first
byte of the file and calls the only possible reader. The changes are
minor.
There are two possible drawbacks (in addition to the bugs): it is
possible that the messages get strange if the file is not of the
"guessed" type and I may have broken Mac support (I don't think so
but it is possible).
Thank you,
Loïc
-- System Information:
Debian Release: lenny/sid
APT prefers testing
APT policy: (990, 'testing')
Architecture: amd64 (x86_64)
Kernel: Linux 2.6.26.5 (SMP w/2 CPU cores)
Locale: LANG=fr_FR.UTF-8, LC_CTYPE=fr_FR.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash
Versions of packages libpano13-0 depends on:
ii libc6 2.7-13 GNU C Library: Shared libraries
ii libjpeg62 6b-14 The Independent JPEG Group's JPEG
ii libpng12-0 1.2.27-1 PNG library - runtime
ii libtiff4 3.8.2-11 Tag Image File Format (TIFF) libra
libpano13-0 recommends no packages.
Versions of packages libpano13-0 suggests:
ii libpano13-bin 2.9.12.dfsg-3 panorama tools utilities
-- no debconf information
diff -ur libpano13-2.9.12.dfsg/bmp.c libpano13-2.9.12.dfsg.loic/bmp.c
--- libpano13-2.9.12.dfsg/bmp.c 2006-09-21 17:19:34.000000000 +0200
+++ libpano13-2.9.12.dfsg.loic/bmp.c 2008-09-26 22:06:34.000000000 +0200
@@ -3,7 +3,7 @@
#include "metadata.h"
#include "file.h"
-static int readBMPFileHeader(Image *im, file_spec input);
+static int readBMPFileHeader(Image *im, FILE *input);
#pragma pack(push, 1)
@@ -155,23 +155,14 @@
// Read bitmap file
-static int readBMP( Image *im, fullPath *sfile )
+static int readBMP( Image *im, FILE *input )
{
- file_spec input;
unsigned char *data, *buf;
int y;
int scanLength;
long count;
int reverse = 0;
- // Bitmap file open
- if( myopen( sfile, read_bin, input ) )
- {
- PrintError("readBMP, could not open file");
- return -1;
- }
-
-
// Read bitmap file header
if( readBMPFileHeader(im, input) )
@@ -212,7 +203,7 @@
for(y=0; y<im->height; y++)
{
count = scanLength;
- myread( input, count, buf );
+ count = fread( buf, 1, count, input );
if( count != scanLength )
{
PrintError("Error reading image data");
@@ -237,21 +228,21 @@
data += im->bytesPerLine;
}
- myclose(input);
+ fclose(input);
free( buf );
return 0;
}
// Read bitmap file header
-static int readBMPFileHeader(Image *im, file_spec input)
+static int readBMPFileHeader(Image *im, FILE *input)
{
win3xHead header; // First part of bitmap header
win3xBitmapInfoHeader iheader; // Second part of bitmap header
long count;
count = sizeof(header);
- myread( input, count, &header );
+ count = fread( &header, 1, count, input );
if( count != sizeof(header) )
{
PrintError("Error reading first BMP header segment");
@@ -266,7 +257,7 @@
count = sizeof(iheader);
- myread( input, count, &iheader );
+ count = read( &iheader, 1, count, input );
if( count != sizeof(iheader) )
{
PrintError("Error reading second BMP header segment");
@@ -313,11 +304,10 @@
}
-int panoBMPRead( Image *im, fullPath *sfile )
+int panoBMPRead( Image *im, FILE *input )
{
- if (readBMP(im, sfile) == 0) {
+ if (readBMP(im, input) == 0)
return panoMetadataUpdateFromImage(im);
- }
else
return FALSE;
}
diff -ur libpano13-2.9.12.dfsg/file.c libpano13-2.9.12.dfsg.loic/file.c
--- libpano13-2.9.12.dfsg/file.c 2007-01-28 00:21:42.000000000 +0100
+++ libpano13-2.9.12.dfsg.loic/file.c 2008-09-26 22:06:34.000000000 +0200
@@ -2408,51 +2408,108 @@
// Read an image
int panoImageRead(Image * im, fullPath * sfile)
{
- char *ext, extension[4];
- int i;
+ char *ext, extension[5];
+ int i, magic, ret = 0;
+ char filename[512];
+ FILE * infile;
assert(sfile != NULL);
assert(im != NULL);
printf("Filename %s\n", sfile->name);
ext = strrchr(sfile->name, '.');
+#if 0
if (ext == NULL || strlen(ext) != 4) {
PrintError("Unsupported file format [%s]: must have extension JPG, PNG, TIF, BMP or HDR", sfile);
return 0;
}
- ext++;
- strcpy(extension, ext);
+#endif
+ if (ext) {
+ strncpy(extension, ext+1, sizeof extension);
+ extension[sizeof(extension)-1] = '\0';
+ }
+ else
+ extension[0] = '\0';
+ /* extension can be used to help for ambiguous cases -- none yet */
// convert to lowercase
- for (i = 0; i < 3; i++)
+ for (i = 0; i < sizeof(extension)- 1; i++)
extension[i] = tolower(extension[i]);
+
+#ifdef __Mac__
+ unsigned char the_pcUnixFilePath[256];// added by Kekus Digital
+ Str255 the_cString;
+ Boolean the_bReturnValue;
+ CFStringRef the_FilePath;
+ CFURLRef the_Url;//till here
+#endif
+
+ if( GetFullPath (sfile, filename))
+ return -1;
+
+#ifdef __Mac__
+ CopyCStringToPascal(filename,the_cString);//Added by Kekus Digital
+ the_FilePath = CFStringCreateWithPascalString(kCFAllocatorDefault, the_cString, kCFStringEncodingUTF8);
+ the_Url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, the_FilePath, kCFURLHFSPathStyle, false);
+ the_bReturnValue = CFURLGetFileSystemRepresentation(the_Url, true, the_pcUnixFilePath, 256);
+
+ strcpy(filename, the_pcUnixFilePath);//till here
+#endif
+
+ if ((infile = fopen(filename, "rb")) == NULL)
+ {
+ PrintError("can't open %s", filename);
+ return FALSE;
+ }
+
+ magic = fgetc(infile);
+ (void)ungetc(magic, infile);
- if (strcmp(extension, "ppm") == 0) {
- return panoPPMRead(im, sfile);
- }
- else if (strcmp(extension, "jpg") == 0) {
- return panoJPEGRead(im, sfile);
- }
- else if (strcmp(extension, "tif") == 0) {
- return panoTiffRead(im, sfile->name);
- }
- else if (strcmp( extension, "bmp" ) == 0 ) {
+ switch (magic) {
+ case 'P':
+ if (1 || strcmp(extension, "ppm") == 0)
+ ret = panoPPMRead(im, infile);
+ break;
+
+ case 0xFF:
+ if (1 || strcmp(extension, "jpg") == 0 ||
+ strcmp(extension, "jpeg") == 0)
+ ret = panoJPEGRead(im, infile);
+ break;
+
+ case 'M':
+ case 'I':
+ if (1 || strcmp(extension, "tif") == 0 ||
+ strcmp(extension, "tiff") == 0) {
+ /* TIFF requires seekable file */
+ fclose(infile);
+ ret = panoTiffRead(im, sfile->name);
+ }
+ break;
+
+ case 'B':
+ if (1 || strcmp( extension, "bmp" ) == 0 ) {
#ifdef __Win__
- return panoBMPRead( im, sfile );
+ ret = panoBMPRead( im, infile );
#else
PrintError("BMP is not a supported format in this operating system");
return FALSE;
#endif
- }
- else if( strcmp( extension, "png" ) == 0 ) {
- return panoPNGRead(im, sfile );
- }
- else if (strcmp( extension, "hdr" ) == 0 ) {
- return panoHDRRead(im, sfile );
- }
- else {
- PrintError("Unsupported file format [%s]: must have extension JPG, PNG, TIF, BMP, PPM or HDR", sfile);
- return FALSE;
- }
+ }
+ break;
+
+ case 0x89:
+ if (1 || strcmp( extension, "png" ) == 0 )
+ ret = panoPNGRead(im, infile );
+ break;
+
+ case '#':
+ if (1 || strcmp( extension, "hdr" ) == 0 )
+ ret = panoHDRRead(im, infile );
+ break;
+ }
+ if (ret == 0)
+ PrintError("Unsupported file format [%s]: must be JPEG, PNG, TIFF, BMP, PPM or HDR", sfile);
+ return ret;
// it should never get here
assert(0);
}
diff -ur libpano13-2.9.12.dfsg/file.h libpano13-2.9.12.dfsg.loic/file.h
--- libpano13-2.9.12.dfsg/file.h 2006-12-16 22:21:04.000000000 +0100
+++ libpano13-2.9.12.dfsg.loic/file.h 2008-09-26 22:06:34.000000000 +0200
@@ -38,11 +38,11 @@
// and these are defined in bmp.c, jpeg.c, hdrfile.c, png.c, and ppm.c
// but there is no point in creating a file for each one of them
-int panoBMPRead(Image *im, fullPath *sfile );
-int panoJPEGRead(Image * im, fullPath * sfile);
-int panoHDRRead(Image *im, fullPath *sfile );
-int panoPNGRead(Image *im, fullPath *sfile );
-int panoPPMRead(Image * im, fullPath * sfile);
+int panoBMPRead(Image *im, FILE *sfile );
+int panoJPEGRead(Image * im, FILE * sfile);
+int panoHDRRead(Image *im, FILE *sfile );
+int panoPNGRead(Image *im, FILE *sfile );
+int panoPPMRead(Image * im, FILE * sfile);
typedef struct {
diff -ur libpano13-2.9.12.dfsg/filter.h libpano13-2.9.12.dfsg.loic/filter.h
--- libpano13-2.9.12.dfsg/filter.h 2007-01-28 00:21:42.000000000 +0100
+++ libpano13-2.9.12.dfsg.loic/filter.h 2008-09-26 22:06:34.000000000 +0200
@@ -649,11 +649,11 @@
int StringtoFullPath (fullPath *path, char *filename);
int IsTextFile ( char* fname );
int readPositions ( char* script, transformCoord *tP );
-int readJPEG ( Image *im, fullPath *sfile );
+int readJPEG ( Image *im, FILE *sfile );
int readTIFF ( Image *im, fullPath *sfile );
int writeJPEG ( Image *im, fullPath *sfile, int quality, int progressive );
int writePNG ( Image *im, fullPath *sfile );
-int readPNG ( Image *im, fullPath *sfile );
+int readPNG ( Image *im, FILE *sfile );
int LaunchAndSendScript(char* application, char* script);
aPrefs* readAdjustLine( fullPath *theScript );
@@ -669,7 +669,7 @@
// Read and Write Radiance HDR files
int writeHDR ( Image *im, fullPath *sfile );
-int readHDR ( Image *im, fullPath *sfile );
+int readHDR ( Image *im, FILE *sfile );
#define FullPathtoString( path, string ) GetFullPath( path, string)
diff -ur libpano13-2.9.12.dfsg/hdrfile.c libpano13-2.9.12.dfsg.loic/hdrfile.c
--- libpano13-2.9.12.dfsg/hdrfile.c 2006-09-21 17:19:33.000000000 +0200
+++ libpano13-2.9.12.dfsg.loic/hdrfile.c 2008-09-26 22:06:34.000000000 +0200
@@ -103,39 +103,12 @@
}
-int readHDR ( Image *im, fullPath *sfile )
+int readHDR ( Image *im, FILE * infile )
{
rgbe_header_info rgbe_h;
- FILE * infile;
float *srcdata, *fdata;
- char filename[256];
int i;
-#ifdef __Mac__
- unsigned char the_pcUnixFilePath[256];// added by Kekus Digital
- Str255 the_cString;
- Boolean the_bReturnValue;
- CFStringRef the_FilePath;
- CFURLRef the_Url;//till here
-#endif
-
- if( GetFullPath (sfile, filename))
- return -1;
-
-#ifdef __Mac__
- CopyCStringToPascal(filename,the_cString);//Added by Kekus Digital
- the_FilePath = CFStringCreateWithPascalString(kCFAllocatorDefault, the_cString, kCFStringEncodingUTF8);
- the_Url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, the_FilePath, kCFURLHFSPathStyle, false);
- the_bReturnValue = CFURLGetFileSystemRepresentation(the_Url, true, the_pcUnixFilePath, 256);
-
- strcpy(filename, the_pcUnixFilePath);//till here
-#endif
-
- if ((infile = fopen(filename, "rb")) == NULL)
- {
- PrintError("can't open %s", filename);
- return -1;
- }
SetImageDefaults( im );
RGBE_ReadHeader(infile,&im->width,&im->height,&rgbe_h);
@@ -169,9 +142,9 @@
return 0;
}
-int panoHDRRead(Image *im, fullPath *sfile )
+int panoHDRRead(Image *im, FILE *infile )
{
- if (readHDR(im, sfile) == 0) {
+ if (readHDR(im, infile) == 0) {
return panoMetadataUpdateFromImage(im);
} else
return FALSE;
diff -ur libpano13-2.9.12.dfsg/jpeg.c libpano13-2.9.12.dfsg.loic/jpeg.c
--- libpano13-2.9.12.dfsg/jpeg.c 2006-11-20 22:39:24.000000000 +0100
+++ libpano13-2.9.12.dfsg.loic/jpeg.c 2008-09-26 22:06:34.000000000 +0200
@@ -128,12 +128,10 @@
}
-int readJPEG(Image * im, fullPath * sfile)
+int readJPEG(Image * im, FILE * infile)
{
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
- FILE *infile;
- char filename[256];
int scan_lines_to_be_read, scan_lines_read;
unsigned int i, scanheight;
unsigned char *data;
@@ -141,18 +139,6 @@
JOCTET *ptr = NULL;
unsigned int size = 0;
-
-
-#ifdef __Mac__
- unsigned char the_pcUnixFilePath[256]; // added by Kekus Digital
- Str255 the_cString;
- Boolean the_bReturnValue;
- CFStringRef the_FilePath;
- CFURLRef the_Url; //till here
-#endif
-
- //PrintError("%s", sfile->name);
-
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_decompress(&cinfo);
@@ -160,29 +146,6 @@
// for further information
jpegICCSetupReadICCProfile(&cinfo);
- if (GetFullPath(sfile, filename))
- return -1;
-
-#ifdef __Mac__
- CopyCStringToPascal(filename, the_cString); //Added by Kekus Digital
- the_FilePath =
- CFStringCreateWithPascalString(kCFAllocatorDefault, the_cString,
- kCFStringEncodingUTF8);
- the_Url =
- CFURLCreateWithFileSystemPath(kCFAllocatorDefault, the_FilePath,
- kCFURLHFSPathStyle, false);
- the_bReturnValue =
- CFURLGetFileSystemRepresentation(the_Url, true, the_pcUnixFilePath,
- 256);
-
- strcpy(filename, the_pcUnixFilePath); //till here
-#endif
-
- if ((infile = fopen(filename, "rb")) == NULL) {
- PrintError("can't open %s", filename);
- return -1;
- }
-
jpeg_stdio_src(&cinfo, infile);
jpeg_read_header(&cinfo, TRUE);
@@ -256,9 +219,9 @@
// so it should be considered a hack until
// we are able to read all the JPEG metadata
-int panoJPEGRead(Image * im, fullPath * sfile)
+int panoJPEGRead(Image * im, FILE * input)
{
- if ( readJPEG(im, sfile) == 0) {
+ if ( readJPEG(im, input) == 0) {
return panoMetadataUpdateFromImage(im);
} else
return FALSE;
diff -ur libpano13-2.9.12.dfsg/png.c libpano13-2.9.12.dfsg.loic/png.c
--- libpano13-2.9.12.dfsg/png.c 2006-09-21 17:19:33.000000000 +0200
+++ libpano13-2.9.12.dfsg.loic/png.c 2008-09-26 22:06:34.000000000 +0200
@@ -111,42 +111,14 @@
-int readPNG ( Image *im, fullPath *sfile )
+int readPNG ( Image *im, FILE *infile )
{
- FILE * infile;
- char filename[256];
png_structp png_ptr;
png_infop info_ptr;
png_bytep *row_pointers;
int row;
unsigned long dataSize;
-#ifdef __Mac__
- unsigned char the_pcUnixFilePath[256];//added by Kekus Digital
- Str255 the_cString;
- Boolean the_bReturnValue;
- CFStringRef the_FilePath;
- CFURLRef the_Url;//till here
-#endif
-
- if( GetFullPath (sfile, filename))
- return -1;
-
-#ifdef __Mac__
- CopyCStringToPascal(filename,the_cString);//added by Kekus Digital
- the_FilePath = CFStringCreateWithPascalString(kCFAllocatorDefault, the_cString, kCFStringEncodingUTF8);
- the_Url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, the_FilePath, kCFURLHFSPathStyle, false);
- the_bReturnValue = CFURLGetFileSystemRepresentation(the_Url, true, the_pcUnixFilePath, 256);
-
- strcpy(filename, the_pcUnixFilePath);//till here
-#endif
-
- if ((infile = fopen(filename, "rb")) == NULL)
- {
- PrintError("can't open %s", filename);
- return -1;
- }
-
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
NULL, NULL, NULL);
@@ -300,9 +272,9 @@
-int panoPNGRead(Image *im, fullPath *sfile )
+int panoPNGRead(Image *im, FILE *infile )
{
- if (readPNG(im, sfile) == 0) {
+ if (readPNG(im, infile) == 0) {
return panoMetadataUpdateFromImage(im);
} else
return FALSE;
diff -ur libpano13-2.9.12.dfsg/ppm.c libpano13-2.9.12.dfsg.loic/ppm.c
--- libpano13-2.9.12.dfsg/ppm.c 2006-09-21 17:19:34.000000000 +0200
+++ libpano13-2.9.12.dfsg.loic/ppm.c 2008-09-26 22:06:34.000000000 +0200
@@ -24,27 +24,19 @@
#include "metadata.h"
#include "file.h"
-static int readPPMFileHeader(file_spec src, Image * im);
+static int readPPMFileHeader(FILE *src, Image * im);
// image is allocated, but not image data
-int readPPM(Image * im, fullPath * sfile)
+int readPPM(Image * im, FILE *src)
{
- file_spec src;
size_t count;
- if (myopen(sfile, read_bin, src))
- {
- PrintError("Error Opening Image File");
- return -1;
- }
-
-
if (readPPMFileHeader(src, im) != 0)
{
PrintError("Error Reading File Header");
- myclose(src);
+ fclose(src);
return -1;
}
@@ -57,28 +49,28 @@
if (im->data == NULL)
{
PrintError("Not enough memory");
- myclose(src);
+ fclose(src);
return -1;
}
count = (size_t) (im->width * im->height * 3);
- myread(src, count, *(im->data));
+ count = fread(*(im->data), 1, count, src);
if (count != im->width * im->height * 3)
{
PrintError("Error Reading Image Data");
- myclose(src);
+ fclose(src);
return -1;
}
- myclose(src);
+ fclose(src);
ThreeToFourBPP(im);
return 0;
}
-static int readPPMFileHeader(file_spec src, Image * im)
+static int readPPMFileHeader(FILE *src, Image * im)
{
int i;
char smallBuf[32], c;
@@ -89,7 +81,7 @@
im->height = -1;
while (im->height == -1)
{
- myread(src, count, &c);
+ count = fread(&c, 1, count, src);
if (count != 1)
return 1;
switch (c)
@@ -97,7 +89,7 @@
case '#':
/* comment line -- skip it */
while (c != 0x0A && c != 0x0D && count == 1)
- myread(src, count, &c);
+ count = fread(&c, 1, count, src);
break;
case ' ':
case '\012':
@@ -107,7 +99,7 @@
break;
case 'P':
/* magic number */
- myread(src, count, &c);
+ count = fread(&c, 1, count, src);
if (c != '6')
{
PrintError("Bad magic number in input file");
@@ -129,7 +121,7 @@
for (i = 0; isdigit(c) && (i + 1 < sizeof(smallBuf)); i++)
{
smallBuf[i] = c;
- myread(src, count, &c);
+ count = fread(&c, 1, count, src);
if (count != 1)
return -1;
}
@@ -141,13 +133,13 @@
smallBuf[i] = 0;
im->width = atoi(smallBuf);
/* read height */
- myread(src, count, &c);
+ count = fread(&c, 1, count, src);
if (count != 1)
return -1;
for (i = 0; isdigit(c) && (i + 1 < sizeof(smallBuf)); i++)
{
smallBuf[i] = c;
- myread(src, count, &c);
+ count = fread(&c, 1, count, src);
if (count != 1)
return -1;
}
@@ -159,13 +151,13 @@
smallBuf[i] = 0;
im->height = atoi(smallBuf);
/* read numColors */
- myread(src, count, &c);
+ count = fread(&c, 1, count, src);
if (count != 1)
return -1;
for (i = 0; isdigit(c) && (i + 1 < sizeof(smallBuf)); i++)
{
smallBuf[i] = c;
- myread(src, count, &c);
+ count = fread(&c, 1, count, src);
if (count != 1)
return -1;
}
@@ -251,9 +243,9 @@
}
-int panoPPMRead(Image * im, fullPath * sfile)
+int panoPPMRead(Image * im, FILE * src)
{
- if (readPPM(im, sfile) == 0) {
+ if (readPPM(im, src) == 0) {
return panoMetadataUpdateFromImage(im);
} else
return FALSE;
--- End Message ---