The TIFF translator overwrote the document count before it was clear that it could

handle the image.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20576 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2007-04-05 13:17:55 +00:00
parent 9468eca38a
commit ce694927b7
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2006, Haiku, Inc. All Rights Reserved.
* Copyright 2003-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -183,34 +183,34 @@ identify_tiff_header(BPositionIO *inSource, BMessage *ioExtension,
tiff_size_proc, tiff_map_file_proc, tiff_unmap_file_proc);
if (!tif)
return B_NO_TRANSLATOR;
// count number of documents
int32 document_count = 0, document_index = 1;
int32 documentCount = 0, documentIndex = 1;
do {
document_count++;
documentCount++;
} while (TIFFReadDirectory(tif));
if (ioExtension) {
// Check if a document index has been specified
if (ioExtension->FindInt32(DOCUMENT_INDEX, &documentIndex) != B_OK)
documentIndex = 1;
if (documentIndex < 1 || documentIndex > documentCount) {
// document index is invalid
return B_NO_TRANSLATOR;
}
}
// identify the document the user specified or the first document
// if the user did not specify which document they wanted to identify
if (!TIFFSetDirectory(tif, documentIndex - 1))
return B_NO_TRANSLATOR;
if (ioExtension) {
// add page count to ioExtension
ioExtension->RemoveName(DOCUMENT_COUNT);
ioExtension->AddInt32(DOCUMENT_COUNT, document_count);
// Check if a document index has been specified
status_t fnd = ioExtension->FindInt32(DOCUMENT_INDEX, &document_index);
if (fnd == B_OK && (document_index < 1 || document_index > document_count))
// If a document index has been supplied, and it is an invalid value,
// return failure
return B_NO_TRANSLATOR;
else if (fnd != B_OK)
// If FindInt32 failed, make certain the document index
// is the default value
document_index = 1;
ioExtension->AddInt32(DOCUMENT_COUNT, documentCount);
}
// identify the document the user specified or the first document
// if the user did not specify which document they wanted to identify
if (!TIFFSetDirectory(tif, document_index - 1))
return B_NO_TRANSLATOR;
if (outInfo) {
outInfo->type = B_TIFF_FORMAT;
@@ -218,17 +218,17 @@ identify_tiff_header(BPositionIO *inSource, BMessage *ioExtension,
outInfo->quality = TIFF_IN_QUALITY;
outInfo->capability = TIFF_IN_CAPABILITY;
strcpy(outInfo->MIME, "image/tiff");
sprintf(outInfo->name, "TIFF image (page %d of %d)",
static_cast<int>(document_index), static_cast<int>(document_count));
sprintf(outInfo->name, "TIFF image");
}
if (!poutTIFF)
if (!poutTIFF) {
// close TIFF if caller is not interested in TIFF handle
TIFFClose(tif);
else
} else {
// leave TIFF open and return handle if caller needs it
*poutTIFF = tif;
}
return B_OK;
}