Update of /cvsroot/gtkpod/libgpod/src
In directory sc8-pr-cvs11.sourceforge.net:/tmp/cvs-serv17392/src

Modified Files:
        db-artwork-writer.c db-image-parser.c itdb.h ithumb-writer.c 
Log Message:
* src/db-artwork-writer.c
  src/db-image-parser.c
  src/itdb.h
  src/ithumb-writer.c: Hopefully do padding right:

   - read padding fields from mhni header and store them with
     each thumbnail 
   - calculate padding for PhotoDB only (padding for iTunesDB
     Artwork does not seem to be necessary)
   - include the padding into the total width/height

   It seems to work well on my iPod Nano -- feedback appreciated.



Index: db-artwork-writer.c
===================================================================
RCS file: /cvsroot/gtkpod/libgpod/src/db-artwork-writer.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- db-artwork-writer.c 1 Jun 2006 15:45:27 -0000       1.19
+++ db-artwork-writer.c 2 Jun 2006 18:08:13 -0000       1.20
@@ -432,7 +432,6 @@
        unsigned int total_bytes;
        int bytes_written;
        iPodBuffer *sub_buffer;
-       const Itdb_ArtworkFormat *format;
 
        if (thumb == NULL) {
                return -1;
@@ -458,17 +457,10 @@
        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) {

Index: db-image-parser.c
===================================================================
RCS file: /cvsroot/gtkpod/libgpod/src/db-image-parser.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- db-image-parser.c   1 Jun 2006 15:45:27 -0000       1.12
+++ db-image-parser.c   2 Jun 2006 18:08:13 -0000       1.13
@@ -101,6 +101,10 @@
        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);

Index: itdb.h
===================================================================
RCS file: /cvsroot/gtkpod/libgpod/src/itdb.h,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- itdb.h      1 Jun 2006 15:45:27 -0000       1.34
+++ itdb.h      2 Jun 2006 18:08:13 -0000       1.35
@@ -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 @@
     guint32 size;
     gint16 width;
     gint16 height;
+    gint16 horizontal_padding;
+    gint16 vertical_padding;
 };
 
 typedef enum { 

Index: ithumb-writer.c
===================================================================
RCS file: /cvsroot/gtkpod/libgpod/src/ithumb-writer.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- ithumb-writer.c     1 Jun 2006 15:45:28 -0000       1.16
+++ ithumb-writer.c     2 Jun 2006 18:08:13 -0000       1.17
@@ -47,6 +47,7 @@
        FILE *f;
         gchar *filename;
        Itdb_ArtworkFormat *img_info;
+        DbType db_type;
         guint byte_order;
        GHashTable *cache;
 };
@@ -58,7 +59,8 @@
  * 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 @@
        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 @@
         * 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 @@
                        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 @@
                        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 @@
                  "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 @@
 
 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 @@
                                               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 @@
                    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);
                        }



_______________________________________________
gtkpod-cvs2 mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2

Reply via email to