summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/db-artwork-writer.c16
-rw-r--r--src/db-image-parser.c4
-rw-r--r--src/itdb.h4
-rw-r--r--src/ithumb-writer.c86
4 files changed, 65 insertions, 45 deletions
diff --git a/src/db-artwork-writer.c b/src/db-artwork-writer.c
index 38ec1f8..0f21f22 100644
--- a/src/db-artwork-writer.c
+++ b/src/db-artwork-writer.c
@@ -432,7 +432,6 @@ write_mhni (Itdb_DB *db, Itdb_Thumb *thumb, int correlation_id, iPodBuffer *buff
unsigned int total_bytes;
int bytes_written;
iPodBuffer *sub_buffer;
- const Itdb_ArtworkFormat *format;
if (thumb == NULL) {
return -1;
@@ -458,17 +457,10 @@ write_mhni (Itdb_DB *db, Itdb_Thumb *thumb, int correlation_id, iPodBuffer *buff
mhni->ithmb_offset = get_gint32 (thumb->offset,
buffer->byte_order);
- /* Work out the image padding */
- format = itdb_get_artwork_info_from_type (
- db_get_device(db), thumb->type);
- g_return_val_if_fail (format, 0);
-
- mhni->vertical_padding = get_gint16 (
- format->height - thumb->height,
- buffer->byte_order);
- mhni->horizontal_padding = get_gint16 (
- format->width - thumb->width,
- buffer->byte_order);
+ mhni->vertical_padding =
+ get_gint16 (thumb->vertical_padding, buffer->byte_order);
+ mhni->horizontal_padding =
+ get_gint16 (thumb->horizontal_padding, buffer->byte_order);
sub_buffer = ipod_buffer_get_sub_buffer (buffer, total_bytes);
if (sub_buffer == NULL) {
diff --git a/src/db-image-parser.c b/src/db-image-parser.c
index 64c23a3..e845b92 100644
--- a/src/db-image-parser.c
+++ b/src/db-image-parser.c
@@ -101,6 +101,10 @@ ipod_image_new_from_mhni (MhniHeader *mhni, Itdb_DB *db)
img->offset = get_guint32_db (db, mhni->ithmb_offset);
img->width = get_gint16_db (db, mhni->image_width);
img->height = get_gint16_db (db, mhni->image_height);
+ img->horizontal_padding =
+ get_gint16_db (db, mhni->horizontal_padding);
+ img->vertical_padding =
+ get_gint16_db (db, mhni->vertical_padding);
device = db_get_device (db);
g_return_val_if_fail (device, NULL);
diff --git a/src/itdb.h b/src/itdb.h
index c7ec9c6..8c30d33 100644
--- a/src/itdb.h
+++ b/src/itdb.h
@@ -1,4 +1,4 @@
-/* Time-stamp: <2006-06-01 23:07:57 jcs>
+/* Time-stamp: <2006-06-03 02:25:03 jcs>
|
| Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net>
| Part of the gtkpod project.
@@ -110,6 +110,8 @@ struct _Itdb_Thumb {
guint32 size;
gint16 width;
gint16 height;
+ gint16 horizontal_padding;
+ gint16 vertical_padding;
};
typedef enum {
diff --git a/src/ithumb-writer.c b/src/ithumb-writer.c
index 88e1b95..58fd279 100644
--- a/src/ithumb-writer.c
+++ b/src/ithumb-writer.c
@@ -47,6 +47,7 @@ struct _iThumbWriter {
FILE *f;
gchar *filename;
Itdb_ArtworkFormat *img_info;
+ DbType db_type;
guint byte_order;
GHashTable *cache;
};
@@ -58,7 +59,8 @@ typedef struct _iThumbWriter iThumbWriter;
* square
*/
static guint16 *
-pack_RGB_565 (GdkPixbuf *pixbuf, iThumbWriter *writer )
+pack_RGB_565 (GdkPixbuf *pixbuf, iThumbWriter *writer,
+ gint horizontal_padding, gint vertical_padding)
{
guchar *pixels;
guint16 *result;
@@ -68,8 +70,6 @@ pack_RGB_565 (GdkPixbuf *pixbuf, iThumbWriter *writer )
gint height;
gint w;
gint h;
- gint horizontal_padding;
- gint vertical_padding;
gint byte_order;
g_object_get (G_OBJECT (pixbuf),
@@ -81,7 +81,7 @@ pack_RGB_565 (GdkPixbuf *pixbuf, iThumbWriter *writer )
* hardcoded in libipoddevice code, so dst_width * dst_height * 2 can't
* overflow, even on an iPod containing malicious data
*/
- result = g_malloc0 ( writer->img_info->width * writer->img_info->height * 2);
+ result = g_malloc0 (writer->img_info->width * writer->img_info->height * 2);
/* Swap the byte order on full screen nano photos */
byte_order = writer->byte_order;
@@ -92,10 +92,8 @@ pack_RGB_565 (GdkPixbuf *pixbuf, iThumbWriter *writer )
byte_order = G_LITTLE_ENDIAN;
}
- horizontal_padding = (writer->img_info->width - width)/2;
- vertical_padding = (writer->img_info->height - height)/2;
-
for (h = 0; h < height; h++) {
+ gint line = (h+vertical_padding)*writer->img_info->width;
for (w = 0; w < width; w++) {
gint r;
gint g;
@@ -111,8 +109,8 @@ pack_RGB_565 (GdkPixbuf *pixbuf, iThumbWriter *writer )
r = (r << RED_SHIFT) & RED_MASK;
g = (g << GREEN_SHIFT) & GREEN_MASK;
b = (b << BLUE_SHIFT) & BLUE_MASK;
- result[(h+vertical_padding)*writer->img_info->width + w + horizontal_padding]
- = get_gint16 (r | g | b, byte_order);
+ result[line + w + horizontal_padding] =
+ get_gint16 (r | g | b, byte_order);
}
}
return result;
@@ -236,28 +234,51 @@ ithumb_writer_write_thumbnail (iThumbWriter *writer,
"height", &height,
NULL);
- thumb->width = width;
- thumb->height = height;
- thumb->offset = writer->cur_offset;
- thumb->size = writer->img_info->width * writer->img_info->height * 2;
-
/* FIXME: under certain conditions (probably related to
* writer->offset getting too big), this should be :F%04u_2.ithmb
* and so on
*/
- if( thumb->type == ITDB_THUMB_PHOTO_LARGE
- || thumb->type == ITDB_THUMB_PHOTO_SMALL
- || thumb->type == ITDB_THUMB_PHOTO_FULL_SCREEN )
- {
- thumb->filename = g_strdup_printf (":Thumbs:F%04u_1.ithmb",
- writer->img_info->correlation_id);
+ if( thumb->type == ITDB_THUMB_PHOTO_LARGE ||
+ thumb->type == ITDB_THUMB_PHOTO_SMALL ||
+ thumb->type == ITDB_THUMB_PHOTO_FULL_SCREEN )
+ {
+ thumb->filename = g_strdup_printf (":Thumbs:F%04u_1.ithmb",
+ writer->img_info->correlation_id);
+
+ } else {
+ thumb->filename = g_strdup_printf (":F%04u_1.ithmb",
+ writer->img_info->correlation_id);
+ }
- } else {
- thumb->filename = g_strdup_printf (":F%04u_1.ithmb",
- writer->img_info->correlation_id);
- }
- pixels = pack_RGB_565 (pixbuf, writer );
- g_object_unref (G_OBJECT (pixbuf));
+ switch (writer->db_type)
+ {
+ case DB_TYPE_PHOTO:
+ thumb->horizontal_padding = (writer->img_info->width - width)/2;
+ thumb->vertical_padding = (writer->img_info->height - height)/2;
+ break;
+ case DB_TYPE_ITUNES:
+ /* IPOD_COVER_LARGE will be centered automatically using
+ the info in mhni->width/height. Free space around
+ IPOD_COVER_SMALL will be used to display track
+ information -> no padding (tested on iPod
+ Nano). mhni->hor_/ver_padding is working */
+ thumb->horizontal_padding = 0;
+ thumb->vertical_padding = 0;
+ break;
+ default:
+ g_return_val_if_reached (FALSE);
+ }
+
+ /* The thumbnail width/height is inclusive padding */
+ thumb->width = thumb->horizontal_padding + width;
+ thumb->height = thumb->vertical_padding + height;
+ thumb->offset = writer->cur_offset;
+ thumb->size = writer->img_info->width * writer->img_info->height * 2;
+
+ pixels = pack_RGB_565 (pixbuf, writer,
+ thumb->horizontal_padding,
+ thumb->vertical_padding);
+ g_object_unref (G_OBJECT (pixbuf));
if (pixels == NULL)
{
@@ -298,9 +319,9 @@ write_thumbnail (gpointer _writer, gpointer _artwork)
static iThumbWriter *
ithumb_writer_new (const char *mount_point,
- const Itdb_ArtworkFormat *info,
- DbType db_type,
- guint byte_order)
+ const Itdb_ArtworkFormat *info,
+ DbType db_type,
+ guint byte_order)
{
char *filename;
iThumbWriter *writer;
@@ -313,6 +334,7 @@ ithumb_writer_new (const char *mount_point,
g_free, NULL);
writer->byte_order = byte_order;
+ writer->db_type = db_type;
filename = ipod_image_get_ithmb_filename (mount_point,
info->correlation_id,
@@ -704,9 +726,9 @@ itdb_write_ithumb_files (Itdb_DB *db)
ithmb_rearrange_existing_thumbnails (db,
format );
writer = ithumb_writer_new (mount_point,
- format,
- db->db_type,
- device->byte_order);
+ format,
+ db->db_type,
+ device->byte_order);
if (writer != NULL) {
writers = g_list_prepend (writers, writer);
}