What is MINI_THUMB_MAGIC and how to use it?

Background

I noticed a strange column for MediaStore.Images.ImageColumns called " MINI_THUMB_MAGIC ".

The documentation states that:

Thumb ID

Type: INTEGER

Constant value: "mini_thumb_magic"

Question

I assume this field is related to MediaStore.Images.Thumbnails .

Is it correct? if not, what is it and how do you use it?

If this is correct, I have other questions related to it:

  • Is this a thumbnail of the original image? Does it use the same aspect ratio or does it crop in the center?

  • how is the "MICRO" size square (96 x 96) and the "MINI" size a rectangle without a square (512 x 384)?

  • How do you use it? I assume this is done using THUMB_DATA ", which is a blob, so you use it like this , but then what is getThumbnail used for " if you already have this field?

  • Is this a rotary image obtained if the orientation value is not 0? What if I want to show this, I don’t need to rotate the image?

  • Can I request images with their thumbnails? perhaps using an internal join?

  • Is it available for all Android devices and versions?

  • Why is it even called "magic"? Is it because it is also available for video (and for some reason doesn’t exist for music, as it could be a cover photo of an album, for example)?

+6
source share
3 answers

Check out this file: https://github.com/android/platform_packages_providers_mediaprovider/blob/master/src/com/android/providers/media/MediaThumbRequest.java in the Android source code. This value is a magic number that allows you to determine if a sketch is saved. I have not explored this file yet, but there should not be a problem for diving deeper. To your questions:

  • No, no mini size image
  • Well, I think this is a definition from Google that wants to have a square thumbnail for some lists, where only very small previews should be visible, and where many elements should fit on the screen, and there is another thumbnail format where the images are larger ...
  • I don’t know this, but according to a Google document, one (THUMB_DATA) represents only some array of raw thumbnail bytes (dunno in what format), and the other (getThumbnail) retrieves a full-fledged bitmap object ...
  • I do not know
  • I do not know
  • I assume this is part of the AOSP source code.
  • The word "magic" is often used for some kind of identifier. There are “magic packets” that can wake the computer from sleep or shutdown over the network, there are magic numbers on hard drives, where some sectors (for example, MBR) have hexadecimal values ​​AA 55 at the last two byte positions, there are also magic numbers in files images that help software packages determine the type of image (for example, GIF files start with GIF89a or GIF87a (ASCII), JPEG files start with hexadecimal FF D8), and there are many, many examples. So magic numbers are a very general term here :-)
+2
source

According to the source code at the following URL, Magic Number is the identifier of the source image * constant. This value is then used to check the long int. If the int was not as expected, it was considered not synchronized with the image environment.

http://grepcode.com/file/repo1.maven.org/maven2/org.robolectric/android-all/4.4_r1-robolectric-0/android/media/MiniThumbFile.java#MiniThumbFile.getMagic%28long%29

// Get the magic number for the specified id in the mini-thumb file. // Returns 0 if the magic is not available. public synchronized long getMagic(long id) { // check the mini thumb file for the right data. Right is // defined as having the right magic number at the offset // reserved for this "id". RandomAccessFile r = miniThumbDataFile(); if (r != null) { long pos = id * BYTES_PER_MINTHUMB; FileLock lock = null; try { mBuffer.clear(); mBuffer.limit(1 + 8); lock = mChannel.lock(pos, 1 + 8, true); // check that we can read the following 9 bytes // (1 for the "status" and 8 for the long) if (mChannel.read(mBuffer, pos) == 9) { mBuffer.position(0); if (mBuffer.get() == 1) { return mBuffer.getLong(); } } } catch (IOException ex) { Log.v(TAG, "Got exception checking file magic: ", ex); } catch (RuntimeException ex) { // Other NIO related exception like disk full, read only channel..etc Log.e(TAG, "Got exception when reading magic, id = " + id + ", disk full or mount read-only? " + ex.getClass()); } finally { try { if (lock != null) lock.release(); } catch (IOException ex) { // ignore it. } } } return 0; } 

I got an exception at runtime while trying to get the original thumbnail id by looking at the thumbnail track. (BTW, the disk is not full and it is not read-only.)

0
source

This is a bit weird parameter ...
Studying the source code of the gallery,
noticed that the value is read from the cursor, but then not used:

 @Override protected BaseImage loadImageFromCursor(Cursor cursor) { long id = cursor.getLong(INDEX_ID); String dataPath = cursor.getString(INDEX_DATA_PATH); long dateTaken = cursor.getLong(INDEX_DATE_TAKEN); if (dateTaken == 0) { dateTaken = cursor.getLong(INDEX_DATE_MODIFIED) * 1000; } 

// here they read ==== →

  long miniThumbMagic = cursor.getLong(INDEX_MINI_THUMB_MAGIC); int orientation = cursor.getInt(INDEX_ORIENTATION); String title = cursor.getString(INDEX_TITLE); String mimeType = cursor.getString(INDEX_MIME_TYPE); if (title == null || title.length() == 0) { title = dataPath; } 

// and do not use == →> at all

  return new Image(this, mContentResolver, id, cursor.getPosition(), contentUri(id), dataPath, mimeType, dateTaken, title, orientation); } 

Perhaps it was used in previous APIs.

ref: https://android.googlesource.com/platform/packages/apps/Gallery/+/android-8.0.0_r12/src/com/android/camera/gallery/ImageList.java?autodive=0%2F%2F .
and video list: https://android.googlesource.com/platform/packages/apps/Gallery/+/android-8.0.0_r12/src/com/android/camera/gallery/VideoList.java?autodive=0%2F% 2F

0
source

All Articles