import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.test.InstrumentationTestCase;
+import android.util.Log;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
while (type != IfdParser.TYPE_END && type != IfdParser.TYPE_NEXT_IFD) {
type = ifdParser.next();
}
- // We should meet next_ifd before end
- assertTrue(type != IfdParser.TYPE_END);
-
+ if (type == IfdParser.TYPE_END) {
+ Log.i(TAG, "No Thumbnail");
+ return;
+ }
IfdParser ifd1Parser = ifdParser.parseIfdBlock();
int thumbOffset = 0;
int thumbSize = 0;
- int width = 0;
- int height = 0;
boolean isFinishRead = false;
while (!isFinishRead) {
switch (ifd1Parser.next()) {
long unsignedInt = ifdParser.readUnsignedInt();
assertTrue(unsignedInt <= Integer.MAX_VALUE);
thumbSize = (int) unsignedInt;
- } else if (tag.getTagId() == ExifTag.TIFF_TAG.TAG_IMAGE_WIDTH) {
- long unsigned = tag.getDataType() == ExifTag.TYPE_INT ?
- ifd1Parser.readUnsignedInt() : ifd1Parser.readUnsignedShort();
- assertTrue(unsigned <= (tag.getDataType() == ExifTag.TYPE_INT ?
- Integer.MAX_VALUE: Short.MAX_VALUE));
- width = (int) unsigned;
- } else if (tag.getTagId() == ExifTag.TIFF_TAG.TAG_IMAGE_HEIGHT) {
- long unsigned = tag.getDataType() == ExifTag.TYPE_INT ?
- ifd1Parser.readUnsignedInt() : ifd1Parser.readUnsignedShort();
- assertTrue(unsigned <= (tag.getDataType() == ExifTag.TYPE_INT ?
- Integer.MAX_VALUE: Short.MAX_VALUE));
- height = (int) unsigned;
}
- isFinishRead = thumbOffset != 0 && thumbSize != 0 && width != 0 && height != 0;
+ isFinishRead = thumbOffset != 0 && thumbSize != 0;
break;
case IfdParser.TYPE_END:
fail("No thumbnail information found");
Bitmap bmp = BitmapFactory.decodeByteArray(buf, 0, thumbSize);
// Check correctly decoded
assertTrue(bmp != null);
- assertEquals(width, bmp.getWidth());
- assertEquals(height, bmp.getHeight());
}
@Override