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. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -185,49 +185,49 @@ identify_tiff_header(BPositionIO *inSource, BMessage *ioExtension,
return B_NO_TRANSLATOR; return B_NO_TRANSLATOR;
// count number of documents // count number of documents
int32 document_count = 0, document_index = 1; int32 documentCount = 0, documentIndex = 1;
do { do {
document_count++; documentCount++;
} while (TIFFReadDirectory(tif)); } while (TIFFReadDirectory(tif));
if (ioExtension) { 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 // Check if a document index has been specified
status_t fnd = ioExtension->FindInt32(DOCUMENT_INDEX, &document_index); if (ioExtension->FindInt32(DOCUMENT_INDEX, &documentIndex) != B_OK)
if (fnd == B_OK && (document_index < 1 || document_index > document_count)) documentIndex = 1;
// If a document index has been supplied, and it is an invalid value,
// return failure if (documentIndex < 1 || documentIndex > documentCount) {
// document index is invalid
return B_NO_TRANSLATOR; return B_NO_TRANSLATOR;
else if (fnd != B_OK) }
// If FindInt32 failed, make certain the document index
// is the default value
document_index = 1;
} }
// identify the document the user specified or the first document // identify the document the user specified or the first document
// if the user did not specify which document they wanted to identify // if the user did not specify which document they wanted to identify
if (!TIFFSetDirectory(tif, document_index - 1)) if (!TIFFSetDirectory(tif, documentIndex - 1))
return B_NO_TRANSLATOR; return B_NO_TRANSLATOR;
if (ioExtension) {
// add page count to ioExtension
ioExtension->RemoveName(DOCUMENT_COUNT);
ioExtension->AddInt32(DOCUMENT_COUNT, documentCount);
}
if (outInfo) { if (outInfo) {
outInfo->type = B_TIFF_FORMAT; outInfo->type = B_TIFF_FORMAT;
outInfo->group = B_TRANSLATOR_BITMAP; outInfo->group = B_TRANSLATOR_BITMAP;
outInfo->quality = TIFF_IN_QUALITY; outInfo->quality = TIFF_IN_QUALITY;
outInfo->capability = TIFF_IN_CAPABILITY; outInfo->capability = TIFF_IN_CAPABILITY;
strcpy(outInfo->MIME, "image/tiff"); strcpy(outInfo->MIME, "image/tiff");
sprintf(outInfo->name, "TIFF image (page %d of %d)", sprintf(outInfo->name, "TIFF image");
static_cast<int>(document_index), static_cast<int>(document_count));
} }
if (!poutTIFF) if (!poutTIFF) {
// close TIFF if caller is not interested in TIFF handle // close TIFF if caller is not interested in TIFF handle
TIFFClose(tif); TIFFClose(tif);
else } else {
// leave TIFF open and return handle if caller needs it // leave TIFF open and return handle if caller needs it
*poutTIFF = tif; *poutTIFF = tif;
}
return B_OK; return B_OK;
} }