Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#4470 closed defect (fixed)

Record: Don't save preview encoded

Reported by: godiard Owned by: dsd
Priority: Unspecified by Maintainer Milestone:
Component: Record Version: Unspecified
Severity: Unspecified Keywords:
Cc: manuq, erikos Distribution/OS: Unspecified
Bug Status: Unconfirmed

Description

The preview in the journal metadata should not be saved encoded, in first place because need more space, in second place, in sugar jarabe/journal/expandedentry.py line 215 we have:

            if self._metadata['preview'][1:4] == 'PNG':
                preview_data = self._metadata['preview']
            else:
                # TODO: We are close to be able to drop this.
                import base64
                preview_data = base64.b64decode(
                        self._metadata['preview'])

Finally, having some previews encoded and other not, makes more difficult the work of other activities using the preview, like Portfolio or the new activity to share the journal content.

The problem space is in part due to the encoding, but also due to the need of save the preview in png format. In fact the preview is a lot bigger than the photo. To test it you can take a photo in record and put a title (in this case "mano"). After exit the activity do:

[olpc@xo-a7-32-6d ~]$ cd .sugar/default/datastore/

[olpc@xo-a7-32-6d datastore]$ grep -r mano */*/metadata/*
5b/5b1430b7-f128-4845-a0a4-baac8b5ccf9e/metadata/title:mano

[olpc@xo-a7-32-6d datastore]$ ls -l 5b/5b1430b7-f128-4845-a0a4-baac8b5ccf9e/metadata/preview
-rw-r--r-- 1 olpc olpc 143348 mar 20 11:19 preview

[olpc@xo-a7-32-6d datastore]$ ls -l 5b/5b1430b7-f128-4845-a0a4-baac8b5ccf9e/data
-r--r--r-- 1 olpc olpc 37873 mar 20 11:19 5b/5b1430b7-f128-4845-a0a4-baac8b5ccf9e/data

[olpc@xo-a7-32-6d datastore]$ file 5b/5b1430b7-f128-4845-a0a4-baac8b5ccf9e/metadata/preview 
5b/5b1430b7-f128-4845-a0a4-baac8b5ccf9e/metadata/preview: ASCII text, with very long lines, with no line terminators

[olpc@xo-a7-32-6d datastore]$ file 5b/5b1430b7-f128-4845-a0a4-baac8b5ccf9e/data
5b/5b1430b7-f128-4845-a0a4-baac8b5ccf9e/data: JPEG image data, JFIF standard 1.01

(the preview is 5 times bigger than the photo)

To compare, do the same with Paint activity:

[olpc@xo-a7-32-6d datastore]$ grep -r dibujo */*/metadata/*
c3/c3d6ea61-baf6-4065-bac0-ebec5e4fff7c/metadata/title:dibujo

[olpc@xo-a7-32-6d datastore]$ ls -l c3/c3d6ea61-baf6-4065-bac0-ebec5e4fff7c/metadata/preview
-rw-r--r-- 1 olpc olpc 8645 mar 20 11:33 preview

[olpc@xo-a7-32-6d datastore]$ ls -l c3/c3d6ea61-baf6-4065-bac0-ebec5e4fff7c/data
-rw-r--r-- 1 olpc olpc 50046 mar 20 11:33 c3/c3d6ea61-baf6-4065-bac0-ebec5e4fff7c/data

[olpc@xo-a7-32-6d datastore]$ file c3/c3d6ea61-baf6-4065-bac0-ebec5e4fff7c/data
c3/c3d6ea61-baf6-4065-bac0-ebec5e4fff7c/data: PNG image data, 1200 x 825, 8-bit/color RGB, non-interlaced

[olpc@xo-a7-32-6d datastore]$ file c3/c3d6ea61-baf6-4065-bac0-ebec5e4fff7c/metadata/preview 
c3/c3d6ea61-baf6-4065-bac0-ebec5e4fff7c/metadata/preview: PNG image data, 300 x 225, 8-bit/color RGBA, non-interlaced

The preview is a PNG file, and is 5 times smaller than the draw.

After the patch, the preview is saved as a png and you can see the preview is a little smaller:

[olpc@xo-a7-32-6d datastore]$ grep -r hand */*/metadata/*
9d/9d8b6a6e-ea8b-4e17-bac2-cdc0363d6ba0/metadata/title:hand

[olpc@xo-a7-32-6d datastore]$ ls -l 9d/9d8b6a6e-ea8b-4e17-bac2-cdc0363d6ba0/metadata/preview
-rw-r--r-- 1 olpc olpc 99717 mar 20 11:57 preview

[olpc@xo-a7-32-6d datastore]$ ls -l 9d/9d8b6a6e-ea8b-4e17-bac2-cdc0363d6ba0/data
-r--r--r-- 1 olpc olpc 36714 mar 20 11:57 9d/9d8b6a6e-ea8b-4e17-bac2-cdc0363d6ba0/data

[olpc@xo-a7-32-6d datastore]$ file  9d/9d8b6a6e-ea8b-4e17-bac2-cdc0363d6ba0/metadata/preview 
9d/9d8b6a6e-ea8b-4e17-bac2-cdc0363d6ba0/metadata/preview: PNG image data, 300 x 225, 8-bit/color RGB, non-interlaced

[olpc@xo-a7-32-6d datastore]$ file 9d/9d8b6a6e-ea8b-4e17-bac2-cdc0363d6ba0/data
9d/9d8b6a6e-ea8b-4e17-bac2-cdc0363d6ba0/data: JPEG image data, JFIF standard 1.01

We could save more space using jpeg as a format, but we need update the code in expandedentry.py to load any file format. Is easy to do, if we evaluate worth it, can be done, see [1]

Saving in jpeg format:

[olpc@xo-a7-32-6d datastore]$ grep -r jpeg-hand */*/metadata/*
a1/a187a2e3-e1a5-4be4-9c76-b9d3f346a523/metadata/title:jpeg-hand

[olpc@xo-a7-32-6d datastore]$ ls -l a1/a187a2e3-e1a5-4be4-9c76-b9d3f346a523/metadata/preview
-rw-r--r-- 1 olpc olpc 13361 mar 20 12:07 preview

[olpc@xo-a7-32-6d datastore]$ file  a1/a187a2e3-e1a5-4be4-9c76-b9d3f346a523/metadata/preview 
a1/a187a2e3-e1a5-4be4-9c76-b9d3f346a523/metadata/preview: JPEG image data, JFIF standard 1.01

[olpc@xo-a7-32-6d datastore]$ ls -l  a1/a187a2e3-e1a5-4be4-9c76-b9d3f346a523/data
-r--r--r-- 1 olpc olpc 59600 mar 20 12:07 a1/a187a2e3-e1a5-4be4-9c76-b9d3f346a523/data

[1] https://git.sugarlabs.org/paint/mainline/commit/16495674277dfed5241d0bf6711d475765e731a8

Attachments (1)

0001-Don-t-save-preview-encoded-SL-4470.patch (3.4 KB) - added by godiard 11 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 Changed 11 years ago by walter

Could we use this as an opportunity to increase the size of the preview image? This has been discussed on the devel list (favorably) [1] and manuq has a patch prepared [2].

[1] http://lists.sugarlabs.org/archive/sugar-devel/2013-February/041657.html
[2] http://lists.sugarlabs.org/archive/sugar-devel/attachments/20130204/0b77934c/attachment-0001.obj

comment:2 Changed 11 years ago by godiard

I agree. Anyway the pointed patch only define a variable with the image size, we need change it too.

If we allow record activity to save in jpeg format, the disk space issue is solved.

comment:3 Changed 11 years ago by manuq

For the preview file format:

Record is a special case as it uses very loosy compression if low quality is set for the taken picture.

As a rule of digital graphics, you don't want loosy compression in small images like thumbnails. See freedesktop.org spec as reference:

http://standards.freedesktop.org/thumbnail-spec/thumbnail-spec-0.8.0.html#AEN144

But if we enlarge the size of Sugar's preview, then I would favor a move to a loosy format like JPEG.

comment:4 Changed 11 years ago by dsd

  • Resolution set to fixed
  • Status changed from new to closed

Thanks, pushed!

comment:5 Changed 11 years ago by dnarvaez

  • Milestone 0.98 deleted

Milestone 0.98 deleted

Note: See TracTickets for help on using tickets.