Commit b194ce2b authored by W. Michael Petullo's avatar W. Michael Petullo
Browse files

Use GByteArray for DPAP thumbnail to couple thumbnail size with data


Signed-off-by: W. Michael Petullo's avatarW. Michael Petullo <mike@flyn.org>
parent 9d40c0fd
......@@ -52,7 +52,7 @@ handle_mlcl (DMAPConnection *connection, DMAPRecordFactory *factory, GNode *n, i
const gchar *format = NULL;
const gchar *comments = NULL;
const gchar *thumbnail = NULL;
const gchar *ptr = NULL;
const GByteArray *ptr = NULL;
gint creation_date = 0;
gint filesize = 0;
gint large_filesize = 0;
......@@ -113,8 +113,8 @@ handle_mlcl (DMAPConnection *connection, DMAPRecordFactory *factory, GNode *n, i
}
if (filesize) {
ptr = g_new (gchar, filesize);
memcpy (ptr, thumbnail, filesize);
ptr = g_byte_array_sized_new (filesize);
g_byte_array_append (ptr, thumbnail, filesize);
}
g_object_set (record,
......@@ -122,7 +122,6 @@ handle_mlcl (DMAPConnection *connection, DMAPRecordFactory *factory, GNode *n, i
"aspect-ratio", aspect_ratio,
"creation-date", creation_date,
"format", format,
"filesize", filesize,
"large-filesize", large_filesize,
"pixel-height", height,
"pixel-width", width,
......@@ -131,6 +130,10 @@ handle_mlcl (DMAPConnection *connection, DMAPRecordFactory *factory, GNode *n, i
"thumbnail", ptr,
NULL);
if (ptr) {
g_byte_array_unref (ptr);
}
_return:
return record;
}
......
......@@ -86,15 +86,6 @@ dpap_record_init (DPAPRecordIface *iface)
0,
G_PARAM_READWRITE));
g_object_interface_install_property (iface,
g_param_spec_int ("filesize",
"Photo file size",
"Photo file size",
0,
G_MAXINT,
0,
G_PARAM_READWRITE));
g_object_interface_install_property (iface,
g_param_spec_int ("creation-date",
"Photo creation date",
......
......@@ -411,9 +411,10 @@ add_entry_to_mlcl (gpointer id,
g_warning ("Format requested but not available");
}
if (_dmap_share_client_requested (mb->bits, PHOTO_IMAGEFILESIZE)) {
GByteArray *thumbnail = NULL;
gint filesize = 0;
g_object_get (record, "filesize", &filesize, NULL);
dmap_structure_add (mlit, DMAP_CC_PIFS, filesize);
g_object_get (record, "thumbnail", &thumbnail, NULL);
dmap_structure_add (mlit, DMAP_CC_PIFS, thumbnail ? thumbnail->len : 0);
}
if (_dmap_share_client_requested (mb->bits, PHOTO_IMAGELARGEFILESIZE)) {
gint large_filesize = 0;
......@@ -447,9 +448,15 @@ add_entry_to_mlcl (gpointer id,
if (_dmap_share_client_requested (mb->bits, PHOTO_FILEDATA)) {
size_t size = 0;
unsigned char *data = NULL;
GByteArray *thumbnail = NULL;
if (_dmap_share_client_requested (mb->bits, PHOTO_THUMB)) {
g_object_get (record, "thumbnail", &data, NULL);
g_object_get (record, "filesize", &size, NULL);
g_object_get (record, "thumbnail", &thumbnail, NULL);
if (thumbnail) {
data = thumbnail->data;
size = thumbnail->len;
} else {
data = size = 0;
}
} else {
/* Should be PHOTO_HIRES */
char *location = NULL;
......
......@@ -32,10 +32,10 @@ private class DPAPViewer {
db.foreach ((k, v) => {
Gdk.Pixbuf pixbuf = null;
if (((ValaDPAPRecord) v).filesize > 0) {
if (((ValaDPAPRecord) v).thumbnail != null) {
string path;
int fd = GLib.FileUtils.open_tmp ("dpapview.XXXXXX", out path);
GLib.FileUtils.set_data (path, ((ValaDPAPRecord) v).thumbnail);
GLib.FileUtils.set_data (path, ((ValaDPAPRecord) v).thumbnail.data);
GLib.FileUtils.close (fd);
pixbuf = new Gdk.Pixbuf.from_file (path);
GLib.FileUtils.unlink (path);
......
......@@ -21,7 +21,6 @@
#include "test-dpap-record.h"
struct TestDPAPRecordPrivate {
gint filesize;
gint largefilesize;
gint pixelheight;
gint pixelwidth;
......@@ -33,12 +32,11 @@ struct TestDPAPRecordPrivate {
char *filename;
char *format;
char *comments;
unsigned char *thumbnail;
GByteArray *thumbnail;
};
enum {
PROP_0,
PROP_FILESIZE,
PROP_LARGE_FILESIZE,
PROP_CREATION_DATE,
PROP_RATING,
......@@ -60,9 +58,6 @@ test_dpap_record_set_property (GObject *object,
TestDPAPRecord *record = TEST_DPAP_RECORD (object);
switch (prop_id) {
case PROP_FILESIZE:
record->priv->filesize = g_value_get_int (value);
break;
case PROP_LARGE_FILESIZE:
record->priv->largefilesize = g_value_get_int (value);
break;
......@@ -113,9 +108,6 @@ test_dpap_record_get_property (GObject *object,
TestDPAPRecord *record = TEST_DPAP_RECORD (object);
switch (prop_id) {
case PROP_FILESIZE:
g_value_set_int (value, record->priv->filesize);
break;
case PROP_LARGE_FILESIZE:
g_value_set_int (value, record->priv->largefilesize);
break;
......@@ -186,13 +178,11 @@ test_dpap_record_class_init (TestDPAPRecordClass *klass)
gobject_class->get_property = test_dpap_record_get_property;
gobject_class->finalize = test_dpap_record_finalize;
g_object_class_override_property (gobject_class, PROP_FILESIZE, "filesize");
g_object_class_override_property (gobject_class, PROP_LARGE_FILESIZE, "large-filesize");
g_object_class_override_property (gobject_class, PROP_CREATION_DATE, "creation-date");
g_object_class_override_property (gobject_class, PROP_RATING, "rating");
g_object_class_override_property (gobject_class, PROP_LOCATION, "location");
g_object_class_override_property (gobject_class, PROP_FILENAME, "filename");
g_object_class_override_property (gobject_class, PROP_FILESIZE, "filesize");
g_object_class_override_property (gobject_class, PROP_ASPECT_RATIO, "aspect-ratio");
g_object_class_override_property (gobject_class, PROP_PIXEL_HEIGHT, "pixel-height");
g_object_class_override_property (gobject_class, PROP_PIXEL_WIDTH, "pixel-width");
......@@ -233,7 +223,7 @@ test_dpap_record_finalize (GObject *object)
g_free (record->priv->filename);
g_free (record->priv->format);
g_free (record->priv->comments);
g_free (record->priv->thumbnail);
g_byte_array_unref (record->priv->thumbnail);
G_OBJECT_CLASS (test_dpap_record_parent_class)->finalize (object);
}
......@@ -276,13 +266,13 @@ test_dpap_record_new (void)
/* Normally, this data is scaled down to thumbnail size. I have not
* done this here because I don't want any external dependencies.
* In many cases the ImageMagick library is a good solution.
* In many cases the VIPS library is a good solution.
*/
path = g_strdup_printf ("%s/media/test.jpeg", g_get_current_dir ());
g_file_get_contents (path, (gchar **) &thumbnail, &size, &error);
g_free (path);
record->priv->filesize = size;
record->priv->thumbnail = thumbnail;
record->priv->thumbnail = g_byte_array_sized_new (size);
g_byte_array_append (record->priv->thumbnail, thumbnail, size);
return record;
}
......@@ -26,8 +26,7 @@ private class ValaDPAPRecord : GLib.Object, DMAP.Record, DPAP.Record {
private string _aspect_ratio;
private string _format;
private string _comments;
private uint8[] _thumbnail;
private int _filesize;
GLib.ByteArray _thumbnail;
private int _large_filesize;
private int _pixel_height;
private int _pixel_width;
......@@ -54,9 +53,12 @@ private class ValaDPAPRecord : GLib.Object, DMAP.Record, DPAP.Record {
set { _format = value; }
}
public uint8[] thumbnail {
public GLib.ByteArray thumbnail {
get { return _thumbnail; }
set { _thumbnail = value; }
set { /* C implementations just use g_byte_array_ref (value); */
_thumbnail = new GLib.ByteArray ();
_thumbnail.append (value.data);
}
}
public string comments {
......@@ -64,11 +66,6 @@ private class ValaDPAPRecord : GLib.Object, DMAP.Record, DPAP.Record {
set { _comments = value; }
}
public int filesize {
get { return _filesize; }
set { _filesize = value; }
}
public int large_filesize {
get { return _large_filesize; }
set { _large_filesize = value; }
......@@ -119,8 +116,10 @@ private class ValaDPAPRecord : GLib.Object, DMAP.Record, DPAP.Record {
_creation_date = 0;
string path = GLib.Environment.get_current_dir () + "/media/test.jpeg";
GLib.FileUtils.get_data (path, out _thumbnail);
_filesize = _thumbnail.length;
uint8[] data;
GLib.FileUtils.get_data (path, out data);
_thumbnail = new GLib.ByteArray ();
_thumbnail.append (data);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment