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

Modified Files:
        db-artwork-parser.c db-artwork-writer.c db-image-parser.c 
        db-image-parser.h itdb.h itdb_itunesdb.c 
Log Message:
        * overall changes to support itdb_image_get_gdk_pixbuf(). Run
        "tests/test-thumbnails <ipod_mount> to copy all thumbnails into
        the current directory.



Index: db-artwork-parser.c
===================================================================
RCS file: /cvsroot/gtkpod/libgpod/src/db-artwork-parser.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- db-artwork-parser.c 23 Nov 2005 18:21:52 -0000      1.7
+++ db-artwork-parser.c 24 Nov 2005 13:31:23 -0000      1.8
@@ -22,6 +22,12 @@
  *
  */
 
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string.h>
+
 #include "itdb.h"
 #include "db-artwork-debug.h"
 #include "db-artwork-parser.h"
@@ -98,8 +104,32 @@
        
 }
 
+static char *
+mhod3_get_ithmb_filename (MhodHeaderArtworkType3 *mhod3, 
+                         Itdb_iTunesDB *db) 
+{
+       char *paths[] = {"iPod_Control", "Artwork", NULL, NULL};
+       char *filename;
+       char *result;
+
+       g_assert (mhod3 != NULL);
+       g_assert (db != NULL);
+       
+       filename = get_utf16_string (mhod3->string, mhod3->string_len);
+       if ((filename == NULL) || (strlen (filename) < 2)) {
+              return NULL;
+       }
+       
+       paths[2] = filename+1;
+       result = itdb_resolve_path (db->mountpoint, (const char **)paths);
+       g_free (filename);
+       return result;
+}
+
+
 static int
-parse_mhod_3 (DBParseContext *ctx, Itdb_Image *image, GError *error)
+parse_mhod_3 (DBParseContext *ctx, Itdb_iTunesDB *db, 
+             Itdb_Image *image, GError *error)
 {
        MhodHeader *mhod;
        MhodHeaderArtworkType3 *mhod3;
@@ -117,7 +147,7 @@
        if ((GINT_FROM_LE (mhod3->type) & 0x00FFFFFF) != 
MHOD_ARTWORK_TYPE_FILE_NAME) {
                return -1;
        }
-       image->filename = get_utf16_string (mhod3->string, mhod3->string_len);
+       image->filename = mhod3_get_ithmb_filename (mhod3, db);
        dump_mhod_type_3 (mhod3);
        return 0;
 }
@@ -145,7 +175,7 @@
        if (mhod_ctx == NULL) {
          return -1;
        }
-       parse_mhod_3 (mhod_ctx, thumb, error);
+       parse_mhod_3 (mhod_ctx, song->itdb, thumb, error);
        g_free (mhod_ctx);
 
        return 0;

Index: db-artwork-writer.c
===================================================================
RCS file: /cvsroot/gtkpod/libgpod/src/db-artwork-writer.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- db-artwork-writer.c 23 Nov 2005 18:21:52 -0000      1.9
+++ db-artwork-writer.c 24 Nov 2005 13:31:24 -0000      1.10
@@ -241,31 +241,6 @@
 #define RETURN_SIZE_FOR(id, size) if (strncmp (id, header_id, 4) == 0) return 
(size)
 
 
-static const IpodArtworkFormat *
-get_artwork_info (IpodDevice *ipod, int image_type)
-{
-       const IpodArtworkFormat *formats;
-       
-       if (ipod == NULL) {
-               return NULL;
-       }
-
-       g_object_get (G_OBJECT (ipod), "artwork-formats", &formats, NULL);
-       if (formats == NULL) {
-               return NULL;
-       }
-       
-       while ((formats->type != -1) && (formats->type != image_type)) {
-               formats++;
-       }
-
-       if (formats->type == -1) {
-               return NULL;
-       }
-
-       return formats;
-}
-
 
 /* Returns the "real" size for a header, ie the size iTunes uses for it 
  * (padding included)
@@ -477,7 +452,8 @@
                        return -1;
                }
                thumb = (Itdb_Image *)it->data;
-               img_info = get_artwork_info (song->itdb->device, thumb->type);
+               img_info = ipod_get_artwork_info_from_type (
+                   song->itdb->device, thumb->type);
                if (img_info == NULL) {
                        return -1;
                }
@@ -571,7 +547,7 @@
        }
        mhif->total_len = mhif->header_len;
        
-       img_info = get_artwork_info (db->device, type);
+       img_info = ipod_get_artwork_info_from_type (db->device, type);
        if (img_info == NULL) {
                return -1;
        }

Index: db-image-parser.c
===================================================================
RCS file: /cvsroot/gtkpod/libgpod/src/db-image-parser.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- db-image-parser.c   23 Nov 2005 18:21:52 -0000      1.6
+++ db-image-parser.c   24 Nov 2005 13:31:24 -0000      1.7
@@ -31,6 +31,10 @@
 
 #include "db-artwork-parser.h"
 #include "db-image-parser.h"
+#if HAVE_GDKPIXBUF
+#include <gdk-pixbuf/gdk-pixbuf.h>
+#endif
+#include <glib/gi18n-lib.h>
 
 static unsigned char *
 unpack_RGB_565 (gushort *pixels, unsigned int bytes_len)
@@ -123,14 +127,59 @@
 
        return pixels;
 
-       /*      return  gdk_pixbuf_new_from_data (pixels, GDK_COLORSPACE_RGB, 
FALSE,
-                                         8, image->width, image->height, 
-                                         image->width * 3, 
-                                         (GdkPixbufDestroyNotify)g_free, 
-                                         NULL);
-       */
 }
 
+/* Convert the pixeldata in @image to a GdkPixbuf.
+   Since we want to have gdk-pixbuf dependency optional, a generic
+   gpointer is returned which you have to cast to (GdkPixbuf *)
+   yourself. If gdk-pixbuf is not installed the NULL pointer is
+   returned.
+   The returned GdkPixbuf must be freed with gdk_pixbuf_unref() after
+   use. */
+gpointer
+itdb_image_get_gdk_pixbuf (Itdb_iTunesDB *itdb, Itdb_Image *image)
+{
+#if HAVE_GDKPIXBUF
+    GdkPixbuf *result;
+    guchar *pixels;
+    const IpodArtworkFormat *img_info;
+
+    g_return_val_if_fail (itdb, NULL);
+    g_return_val_if_fail (image, NULL);
+
+    pixels = itdb_image_get_rgb_data (image);
+    if (pixels == NULL)
+    {
+       return NULL;
+    }
+
+    img_info = ipod_get_artwork_info_from_type (itdb->device,
+                                               image->type);
+
+    if (img_info == NULL)
+    {
+       g_print (_("Unable to obtain image info on image (type: %d, filename: 
'%s'\n)"), image->type, image->filename);
+       g_free (pixels);
+       return NULL;
+    }
+
+    result = gdk_pixbuf_new_from_data (pixels, GDK_COLORSPACE_RGB, FALSE,
+                                      8, image->width, image->height,
+                                      img_info->width*3,
+                                      (GdkPixbufDestroyNotify)g_free,
+                                      NULL);
+
+    /* !! do not g_free(pixels) here: it will be freed when doing a
+     * gdk_pixbuf_unref() on the GdkPixbuf !! */
+
+    return result;
+#else
+    return NULL;
+#endif
+}
+
+
+
 static int
 image_type_from_corr_id (IpodDevice *ipod, int corr_id)
 {
@@ -155,6 +204,32 @@
        return -1;
 }
 
+
+G_GNUC_INTERNAL const IpodArtworkFormat *
+ipod_get_artwork_info_from_type (IpodDevice *ipod, int image_type)
+{
+       const IpodArtworkFormat *formats;
+       
+       if (ipod == NULL) {
+               return NULL;
+       }
+
+       g_object_get (G_OBJECT (ipod), "artwork-formats", &formats, NULL);
+       if (formats == NULL) {
+               return NULL;
+       }
+       
+       while ((formats->type != -1) && (formats->type != image_type)) {
+               formats++;
+       }
+
+       if (formats->type == -1) {
+               return NULL;
+       }
+
+       return formats;
+}
+
 G_GNUC_INTERNAL Itdb_Image *
 ipod_image_new_from_mhni (MhniHeader *mhni, Itdb_iTunesDB *db)
 {

Index: db-image-parser.h
===================================================================
RCS file: /cvsroot/gtkpod/libgpod/src/db-image-parser.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- db-image-parser.h   23 Nov 2005 18:21:52 -0000      1.3
+++ db-image-parser.h   24 Nov 2005 13:31:24 -0000      1.4
@@ -46,5 +46,7 @@
 G_GNUC_INTERNAL int itdb_write_ithumb_files (Itdb_iTunesDB *db, 
                                             const char *mount_point);
 
+G_GNUC_INTERNAL const IpodArtworkFormat *ipod_get_artwork_info_from_type (
+    IpodDevice *ipod, int image_type);
 
 #endif

Index: itdb.h
===================================================================
RCS file: /cvsroot/gtkpod/libgpod/src/itdb.h,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- itdb.h      23 Nov 2005 18:21:52 -0000      1.22
+++ itdb.h      24 Nov 2005 13:31:24 -0000      1.23
@@ -1,4 +1,4 @@
-/* Time-stamp: <2005-11-19 16:26:13 jcs>
+/* Time-stamp: <2005-11-24 21:34:51 jcs>
 |
 |  Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net>
 |  Part of the gtkpod project.
@@ -312,16 +312,17 @@
 
 
 /* This structure can represent two slightly different images:
- *   - an image before it's transferred to the iPod (it will then be scaled
- *     as necessary to generate the 2 thumbnails needed by the iPod), 
- *     for such images, filename points to a 'real' image file, offset is
- *     not significant, size, width and height may or may not be set
- *     and id corresponds to the image id to write in mhii records of the 
- *     photo database
- * 
- *   - a thumbnail (big or small) stored on a database in the iPod.
- *     For such images, id isn't significant, filename point to a .ithmb file
- *     on the iPod
+
+   - an image before it's transferred to the iPod (it will then be
+     scaled as necessary to generate the 2 thumbnails needed by the
+     iPod), for such images, filename points to a 'real' image file,
+     offset is not significant, size, width and height may or may not
+     be set and id corresponds to the image id to write in mhii
+     records of the photo database
+ 
+   - a thumbnail (big or small) stored on a database in the iPod.  For
+     such images, id isn't significant, filename point to a .ithmb
+     file on the iPod
  */
 struct _Itdb_Image {
        int type;
@@ -733,7 +734,9 @@
 int itdb_track_set_thumbnail (Itdb_Track *song, const char *filename);
 void itdb_track_remove_thumbnail (Itdb_Track *song);
 void itdb_track_free_generated_thumbnails (Itdb_Track *track);
-
+/* the following funciton returns a pointer to a GdkPixbuf if
+   gdk-pixbuf is installed -- a NULL pointer otherwise. */
+gpointer itdb_image_get_gdk_pixbuf (Itdb_iTunesDB *itdb, Itdb_Image *image);
 /* time functions */
 guint64 itdb_time_get_mac_time (void);
 time_t itdb_time_mac_to_host (guint64 mactime);

Index: itdb_itunesdb.c
===================================================================
RCS file: /cvsroot/gtkpod/libgpod/src/itdb_itunesdb.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- itdb_itunesdb.c     19 Nov 2005 08:07:12 -0000      1.32
+++ itdb_itunesdb.c     24 Nov 2005 13:31:24 -0000      1.33
@@ -1,4 +1,4 @@
-/* Time-stamp: <2005-11-19 17:05:44 jcs>
+/* Time-stamp: <2005-11-20 16:06:58 jcs>
 |
 |  Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net>
 |  Part of the gtkpod project.



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
gtkpod-cvs2 mailing list
gtkpod-cvs2@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2

Reply via email to