Friday, May 7, 2010

thumbs116x116.dat reader

I know this is very ugly, and I wished that I have time to improve it.

If anyone can beautify it, please send me a copy, thanks.


public static Bitmap readThumbsAlternative(byte[] search, String szSearch) {
// file:///SDCard/BlackBerry/pictures/image.jpg
szSearch = szSearch.substring(szSearch.lastIndexOf('/')+1,szSearch.length());
// convert the search string to bytes for easier comparison
byte[] searchtmp = szSearch.getBytes();
int lastbyte = 0;
int endIndex = 0;
for (int x = 0; x < search.length; x++) {
boolean found = false;
// For the length of searchtmp trying to find a match in the byte file
// we could also have converted search to String [new String(search)]
// and have done an index of however I prefer direct byte access as lookups tend to be faster
for (int y = 0; y < searchtmp.length; y++) {
if (search[x + y] == searchtmp[y]) {
lastbyte = x + y + 1;
found = true;
} else {
found = false;
break;
}
}
if (found) {
for (int y = lastbyte; y < search.length; y++) {
byte first = search[y];
byte second = (y < search.length - 1) ? search[y + 1] : search[y];
String firstS = Integer.toString((first & 0xff) + 0x100, 16).substring(1);
String secondS = Integer.toString((second & 0xff) + 0x100, 16).substring(1);
if (firstS.equals("ff") && secondS.equals("d9")) {
endIndex = y + 1;
break;
}
}
if (endIndex>0) {
break;
}
}
}
if (lastbyte > 0 && endIndex > 0) {
byte[] b = new byte[lastbyte + endIndex];
int counter = 0;
for (int i = lastbyte; i <= endIndex; i++) {
b[counter] = search[i];
counter++;
}
EncodedImage ei = EncodedImage.createEncodedImage(b, 0, b.length);
Bitmap bt = ei.getBitmap();
return bt;
}
return _loadingImage;
}

Thursday, May 6, 2010

reading BBThumbs.dat thumbnail

Problem: Need a way to select images from the device, but takes forever to generate thumbnail at runtime.

Solution: Read the thumbnail generated by BlackBerry's image browser.

Here are the files of the thumbnails:
for newer OS:
1. file:///SDCard/BlackBerry/system/media/thumbs116x116.dat
2. file:///store/appdata/rim/media/thumbs116x116.dat

or thumbs480x360.dat if you want bigger thumbnails
*** I didn't need to use the .key file, if anyone knows what does the .key file do, would you please let me know?

read the file as EXIFs by stripping the data FFD8XXXX...XXXXFFD9

www.media.mit.edu/pia/Research/deepview/exif.html



for older OS:
3. file:///SDCard/BlackBerry/pictures/BBThumbs.dat
4. file:///store/home/user/pictures/BBThumbs.dat

read the file as PNGs by using the code snippet from

supportforums.blackberry.com/t5/Java-Development/Thumbnails-work-around/m-p/343870