Revision: 1753
          http://gtkpod.svn.sourceforge.net/gtkpod/?rev=1753&view=rev
Author:   jcsjcs
Date:     2007-11-03 17:48:12 -0700 (Sat, 03 Nov 2007)

Log Message:
-----------
        Added support for video output of photos for iPod Nano Videos and
        iPod Classics.

        * src/ithumb-writer.c
          (pack_I420): added packer for iPod Nano Video and iPod Classic
          TV output photo format.
          (itdb_write_ithumb_files): make sure only valid thumbnail types
          are written.

        * src/db-image-parser.h: added declaration for
          itdb_thumb_type_is_valid_for_db() 

        * src/itdb_photoalbum.c (itdb_photodb_add_photo_internal): make
          sure only photo thumbnails are added.

        * src/db-artwork-writer.c

          (write_mhii): correctly skip unneeded thumbnails (thumbnails not
          relevant for the current iPod type).

          (should_write): renamed to itdb_thumb_type_is_valid_for_db()

          src/itdb.h
          src/itdb_artwork.c: minor formatting.

Modified Paths:
--------------
    libgpod/trunk/ChangeLog
    libgpod/trunk/src/db-artwork-writer.c
    libgpod/trunk/src/db-image-parser.h
    libgpod/trunk/src/itdb.h
    libgpod/trunk/src/itdb_artwork.c
    libgpod/trunk/src/itdb_photoalbum.c
    libgpod/trunk/src/ithumb-writer.c

Modified: libgpod/trunk/ChangeLog
===================================================================
--- libgpod/trunk/ChangeLog     2007-11-03 11:48:38 UTC (rev 1752)
+++ libgpod/trunk/ChangeLog     2007-11-04 00:48:12 UTC (rev 1753)
@@ -1,3 +1,30 @@
+2007-11-04  Jorg Schuler <jcsjcs at users.sourceforge.net>
+
+       Added support for video output of photos for iPod Nano Videos and
+       iPod Classics.
+
+       * src/ithumb-writer.c
+         (pack_I420): added packer for iPod Nano Video and iPod Classic
+         TV output photo format.
+         (itdb_write_ithumb_files): make sure only valid thumbnail types
+         are written.
+
+       * src/db-image-parser.h: added declaration for
+         itdb_thumb_type_is_valid_for_db() 
+
+       * src/itdb_photoalbum.c (itdb_photodb_add_photo_internal): make
+         sure only photo thumbnails are added.
+
+       * src/db-artwork-writer.c
+
+         (write_mhii): correctly skip unneeded thumbnails (thumbnails not
+         relevant for the current iPod type).
+
+         (should_write): renamed to itdb_thumb_type_is_valid_for_db()
+
+         src/itdb.h
+         src/itdb_artwork.c: minor formatting.
+
 2007-10-30  Christophe Fergeau  <[EMAIL PROTECTED]>
 
        Additional clean-ups after the glib requirement bumping pointed out by
@@ -12,7 +39,7 @@
        * src/itdb_photoalbum.c:
        * src/itdb_private.h:
        * src/ithumb-writer.c: get rid of glib-compat.h since we raised the
-       minimum version to 2.8
+         minimum version to 2.8
 
 2007-10-30  Christophe Fergeau <[EMAIL PROTECTED]>
 
@@ -24,7 +51,7 @@
 
        * src/itdb_artwork.c:
        * src/ithumb-writer.c: replace // comments with /* */ pairs, fixes
-       compilation on my machine
+         compilation on my machine
 
 2007-10-29  Christophe Fergeau <[EMAIL PROTECTED]>
 
@@ -38,12 +65,12 @@
 2007-10-29  Christophe Fergeau <[EMAIL PROTECTED]>
 
        * src/itdb_device.c: the iPod Touch probably uses the same image format
-       as the iPhone
+         as the iPhone
 
 2007-10-29  Christophe Fergeau <[EMAIL PROTECTED]>
 
        * configure.ac: raise glib requirement to 2.8 (because of
-       g_file_set_contents)
+         g_file_set_contents)
 
 2007-10-29  Christophe Fergeau <[EMAIL PROTECTED]>
 
@@ -53,12 +80,12 @@
 2007-10-29  Christophe Fergeau <[EMAIL PROTECTED]>
 
        * src/db-artwork-writer.c: reread the pointer for memory mapped
-       buffers when it may have changed
+         buffers when it may have changed
            
-       Artwork writing works by mapping structs to memory and by directly 
-       accessing/modifying it. This works until we need to move the
-       mmap base address. This patch makes sure we reset the struct
-       mapping every time the mmap base pointer may have changed
+         Artwork writing works by mapping structs to memory and by
+         directly accessing/modifying it. This works until we need to
+         move the mmap base address. This patch makes sure we reset the
+         struct mapping every time the mmap base pointer may have changed
 
 2007-10-27 Jorg Schuler <jcsjcs at users.sourceforge.net>
 
@@ -80,9 +107,9 @@
 2007-10-24  Christophe Fergeau  <[EMAIL PROTECTED]>
 
        * src/db-artwork-writer.c: (write_mhif), (should_write),
-       (write_mhlf): don't hardcode the number of mhif entries we write, but
-       write as many entries as the number of thumbnail formats supported by
-       the device
+         (write_mhlf): don't hardcode the number of mhif entries we
+         write, but write as many entries as the number of thumbnail
+         formats supported by the device
 
 2007-10-24  Christophe Fergeau  <[EMAIL PROTECTED]>
 

Modified: libgpod/trunk/src/db-artwork-writer.c
===================================================================
--- libgpod/trunk/src/db-artwork-writer.c       2007-11-03 11:48:38 UTC (rev 
1752)
+++ libgpod/trunk/src/db-artwork-writer.c       2007-11-04 00:48:12 UTC (rev 
1753)
@@ -381,12 +381,11 @@
                                           buffer->byte_order);
        mhni->ithmb_offset =   get_gint32 (thumb->offset,
                                           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);
 
-       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) {
                return  -1;
@@ -492,13 +491,21 @@
        mhii->digitized_date = get_guint32 (mactime, buffer->byte_order);
 
        mhii->orig_img_size = get_gint32 (artwork->artwork_size, 
buffer->byte_order);
-       it = artwork->thumbnails;
        num_children = 0;
-       while (it != NULL) {
+       for (it=artwork->thumbnails; it!=NULL; it=it->next)
+       {
                iPodBuffer *sub_buffer;
                Itdb_Thumb *thumb;
                const Itdb_ArtworkFormat *img_info;
 
+               thumb = (Itdb_Thumb *)it->data;
+               img_info = itdb_get_artwork_info_from_type (
+                   db_get_device(db), thumb->type);
+               if (img_info == NULL) {
+                   /* skip this thumb */
+                   continue;
+               }
+
                mhii->num_children = get_gint32 (num_children,
                                                 buffer->byte_order);
                mhii->total_len = get_gint32 (total_bytes, buffer->byte_order);
@@ -506,12 +513,6 @@
                if (sub_buffer == NULL) {
                        return -1;
                }
-               thumb = (Itdb_Thumb *)it->data;
-               img_info = itdb_get_artwork_info_from_type (
-                   db_get_device(db), thumb->type);
-               if (img_info == NULL) {
-                       return -1;
-               }
                bytes_written = write_mhod (db, thumb, img_info->correlation_id,
                                            sub_buffer);
                ipod_buffer_destroy (sub_buffer);
@@ -521,7 +522,6 @@
                total_bytes += bytes_written;
                mhii = ipod_buffer_get_pointer (buffer);
                num_children++;
-               it = it->next;
        }
 
        mhii->num_children = get_gint32 (num_children, buffer->byte_order);
@@ -561,7 +561,6 @@
                Itdb_Track *song;
                int bytes_written;
                iPodBuffer *sub_buffer;
-
                if (buffer->db_type == DB_TYPE_ITUNES) {
                        song = (Itdb_Track*)it->data;
                        if (!song->artwork || (song->artwork->id == 0)) {
@@ -742,24 +741,22 @@
        return get_gint32 (mhif->header_len, buffer->byte_order);
 }
 
-static gboolean
-should_write (const Itdb_ArtworkFormat *formats, DbType db_type)
+G_GNUC_INTERNAL gboolean
+itdb_thumb_type_is_valid_for_db (const ItdbThumbType thumb_type, DbType 
db_type)
 {
-        g_return_val_if_fail (formats->type != -1, FALSE);
-
-        switch (formats->type) {
+        switch (thumb_type) {
         case ITDB_THUMB_COVER_SMALL:
         case ITDB_THUMB_COVER_LARGE:
         case ITDB_THUMB_COVER_XLARGE:
         case ITDB_THUMB_COVER_MEDIUM:
         case ITDB_THUMB_COVER_SMEDIUM:
         case ITDB_THUMB_COVER_XSMALL:
-                return (db_type == DB_TYPE_ITUNES);
+           return (db_type == DB_TYPE_ITUNES);
         case ITDB_THUMB_PHOTO_SMALL:
         case ITDB_THUMB_PHOTO_LARGE:
         case ITDB_THUMB_PHOTO_FULL_SCREEN:
         case ITDB_THUMB_PHOTO_TV_SCREEN:
-                return (db_type == DB_TYPE_PHOTO);
+           return (db_type == DB_TYPE_PHOTO);
         }
 
         g_return_val_if_reached (FALSE);
@@ -790,7 +787,7 @@
 
         while (formats->type != -1) {
                iPodBuffer *sub_buffer;
-                if (!should_write (formats, buffer->db_type)) {
+                if (!itdb_thumb_type_is_valid_for_db (formats->type, 
buffer->db_type)) {
                         formats++;
                         continue;
                 }

Modified: libgpod/trunk/src/db-image-parser.h
===================================================================
--- libgpod/trunk/src/db-image-parser.h 2007-11-03 11:48:38 UTC (rev 1752)
+++ libgpod/trunk/src/db-image-parser.h 2007-11-04 00:48:12 UTC (rev 1753)
@@ -82,6 +82,9 @@
 
 G_GNUC_INTERNAL int itdb_write_ithumb_files (Itdb_DB *db);
 
+G_GNUC_INTERNAL gboolean
+itdb_thumb_type_is_valid_for_db (const ItdbThumbType thumb_type, DbType 
db_type);
+
 G_GNUC_INTERNAL
 const Itdb_ArtworkFormat *itdb_get_artwork_info_from_type (
     Itdb_Device *ipod, ItdbThumbType image_type);

Modified: libgpod/trunk/src/itdb.h
===================================================================
--- libgpod/trunk/src/itdb.h    2007-11-03 11:48:38 UTC (rev 1752)
+++ libgpod/trunk/src/itdb.h    2007-11-04 00:48:12 UTC (rev 1753)
@@ -447,7 +447,7 @@
 
 /* Types of thumbnails in Itdb_Image */
 typedef enum { 
-    ITDB_THUMB_COVER_SMALL,
+    ITDB_THUMB_COVER_SMALL = 0,
     ITDB_THUMB_COVER_LARGE,
     ITDB_THUMB_PHOTO_SMALL,
     ITDB_THUMB_PHOTO_LARGE,

Modified: libgpod/trunk/src/itdb_artwork.c
===================================================================
--- libgpod/trunk/src/itdb_artwork.c    2007-11-03 11:48:38 UTC (rev 1752)
+++ libgpod/trunk/src/itdb_artwork.c    2007-11-04 00:48:12 UTC (rev 1753)
@@ -1,5 +1,4 @@
-/* Time-stamp: <2007-10-27 21:54:23 jcs>
-|
+/*
 |  Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net>
 |  Part of the gtkpod project.
 | 
@@ -1214,6 +1213,7 @@
     switch (format)
     {
     case THUMB_FORMAT_UYVY_LE:
+    case THUMB_FORMAT_I420_LE:
     case THUMB_FORMAT_RGB565_LE:
     case THUMB_FORMAT_RGB565_LE_90:
     case THUMB_FORMAT_RGB555_LE:
@@ -1223,9 +1223,9 @@
     case THUMB_FORMAT_REC_RGB555_LE:
     case THUMB_FORMAT_REC_RGB555_LE_90:
     case THUMB_FORMAT_EXPERIMENTAL_LE:
-       case THUMB_FORMAT_I420_LE:
        return G_LITTLE_ENDIAN;
     case THUMB_FORMAT_UYVY_BE:
+    case THUMB_FORMAT_I420_BE:
     case THUMB_FORMAT_RGB565_BE:
     case THUMB_FORMAT_RGB565_BE_90:
     case THUMB_FORMAT_RGB555_BE:
@@ -1235,7 +1235,6 @@
     case THUMB_FORMAT_REC_RGB555_BE:
     case THUMB_FORMAT_REC_RGB555_BE_90:
     case THUMB_FORMAT_EXPERIMENTAL_BE:
-       case THUMB_FORMAT_I420_BE:
        return G_BIG_ENDIAN;
     }
     g_return_val_if_reached (-1);

Modified: libgpod/trunk/src/itdb_photoalbum.c
===================================================================
--- libgpod/trunk/src/itdb_photoalbum.c 2007-11-03 11:48:38 UTC (rev 1752)
+++ libgpod/trunk/src/itdb_photoalbum.c 2007-11-04 00:48:12 UTC (rev 1753)
@@ -1,4 +1,4 @@
-/* Time-stamp: <2007-06-01 23:03:58 jcs>
+/* Time-stamp: <2007-11-03 20:27:36 jcs>
 |
 |  Copyright (C) 2002-2006 Jorg Schuler <jcsjcs at users sourceforge net>
 |  Part of the gtkpod project.
@@ -31,6 +31,7 @@
 #include "itdb_private.h"
 #include "itdb_device.h"
 #include "db-artwork-parser.h"
+#include "db-image-parser.h"
 #include <errno.h>
 #include <stdio.h>
 #include <string.h>
@@ -416,34 +417,34 @@
 
     for(result = TRUE; format->type != -1 && result == TRUE; format++)
     {
-       if((format->type == ITDB_THUMB_COVER_SMALL) ||
-          (format->type == ITDB_THUMB_COVER_LARGE))
-           continue;
-       if (filename)
+       if (itdb_thumb_type_is_valid_for_db (format->type, DB_TYPE_PHOTO))
        {
-           result = itdb_artwork_add_thumbnail (artwork,
-                                                format->type,
-                                                filename,
-                                                rotation,
-                                                error);
+           if (filename)
+           {
+               result = itdb_artwork_add_thumbnail (artwork,
+                                                    format->type,
+                                                    filename,
+                                                    rotation,
+                                                    error);
+           }
+           if (image_data)
+           {
+               result = itdb_artwork_add_thumbnail_from_data (artwork,
+                                                              format->type,
+                                                              image_data,
+                                                              image_data_len,
+                                                              rotation,
+                                                              error);
+           }
+           if (pixbuf) 
+           {
+               result = itdb_artwork_add_thumbnail_from_pixbuf (artwork,
+                                                                format->type, 
+                                                                pixbuf,
+                                                                rotation,
+                                                                error);
+           }
        }
-       if (image_data)
-       {
-           result = itdb_artwork_add_thumbnail_from_data (artwork,
-                                                          format->type,
-                                                          image_data,
-                                                          image_data_len,
-                                                          rotation,
-                                                          error);
-       }
-       if (pixbuf) 
-       {
-         result = itdb_artwork_add_thumbnail_from_pixbuf (artwork,
-                                                          format->type, 
-                                                          pixbuf,
-                                                          rotation,
-                                                          error);
-       }
     }
 
     if (result != TRUE)

Modified: libgpod/trunk/src/ithumb-writer.c
===================================================================
--- libgpod/trunk/src/ithumb-writer.c   2007-11-03 11:48:38 UTC (rev 1752)
+++ libgpod/trunk/src/ithumb-writer.c   2007-11-04 00:48:12 UTC (rev 1753)
@@ -1,4 +1,4 @@
-/*  Time-stamp: <2007-10-27 22:01:00 jcs>
+/*  Time-stamp: <2007-11-04 09:46:51 jcs>
  *
  *  Copyright (C) 2005 Christophe Fergeau
  *
@@ -303,9 +303,74 @@
           gint horizontal_padding, gint vertical_padding,
           guint32 *thumb_size)
 {
-       /* FIXME do something */
+    GdkPixbuf *pixbuf;
+    gint width, height;
+    gint orig_height, orig_width;
+    gint rowstride;
+    gint h, z;
+    guchar *pixels, *yuvdata;
+    gint yuvsize, halfyuv;
+    gint ustart, vstart;
+
     g_return_val_if_fail (img_info, NULL);
-    return NULL;
+
+    width = img_info->width;
+    height = img_info->height;
+
+    g_object_get (G_OBJECT (orig_pixbuf), 
+                 "height", &orig_height, "width", &orig_width, NULL);
+
+    /* copy into new pixmap with padding applied */
+    pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
+                            gdk_pixbuf_get_has_alpha (orig_pixbuf),
+                            8,
+                            width, height);
+    gdk_pixbuf_copy_area (orig_pixbuf, 0, 0, orig_width, orig_height,
+                         pixbuf, horizontal_padding, vertical_padding);
+
+    g_object_get (G_OBJECT (pixbuf), 
+                 "rowstride", &rowstride,
+                 "pixels", &pixels, NULL);
+
+    halfyuv = width*height;
+
+    yuvsize = 2*halfyuv;
+    *thumb_size = yuvsize;
+
+    yuvdata = g_malloc (yuvsize);
+
+    ustart = halfyuv;
+    vstart = ustart + halfyuv/4;
+
+    /* FIXME: consider rowstride -- currently we assume rowstride==width */
+    for (z=0,h=0; h < halfyuv; ++h)
+    {
+       gint r,g,b;
+       gint u, v, y;
+       gint row, col;
+
+       r = pixels[z];
+       g = pixels[z+1];
+       b = pixels[z+2];
+
+       y = (( 66*r + 129*g +  25*b + 128) >> 8) + 16;
+       u = ((-38*r -  74*g + 112*b + 128) >> 8) + 128;
+       v = ((112*r -  94*g -  18*b + 128) >> 8) + 128;
+
+       row = h / width;
+       col = h % width;
+
+       yuvdata[h] = y;
+       yuvdata[ustart + (row/2)*(width/2) + col/2] = u;
+       yuvdata[vstart + (row/2)*(width/2) + col/2] = v;
+
+       if (gdk_pixbuf_get_has_alpha(pixbuf))
+           z+=4;
+       else
+           z+=3;
+    }
+
+    return yuvdata;
 }
 
 /* pack_UYVY() is adapted from imgconvert.c from the GPixPod project
@@ -1212,26 +1277,16 @@
        while (format->type != -1) {
                iThumbWriter *writer;
 
-               switch (format->type) {
-               case ITDB_THUMB_COVER_XLARGE:
-               case ITDB_THUMB_COVER_MEDIUM:
-               case ITDB_THUMB_COVER_SMEDIUM:
-               case ITDB_THUMB_COVER_XSMALL:
-               case ITDB_THUMB_COVER_SMALL:
-               case ITDB_THUMB_COVER_LARGE:
-               case ITDB_THUMB_PHOTO_SMALL:
-               case ITDB_THUMB_PHOTO_LARGE:
-               case ITDB_THUMB_PHOTO_FULL_SCREEN:
-               case ITDB_THUMB_PHOTO_TV_SCREEN:
-                       ithmb_rearrange_existing_thumbnails (db, format );
-                       writer = ithumb_writer_new (mount_point, 
-                                                   format,
-                                                   db->db_type, 
-                                                   device->byte_order);
-                       if (writer != NULL) {
-                               writers = g_list_prepend (writers, writer);
-                       }
-                       break;
+               if (itdb_thumb_type_is_valid_for_db (format->type, db->db_type))
+               {
+                   ithmb_rearrange_existing_thumbnails (db, format );
+                   writer = ithumb_writer_new (mount_point, 
+                                               format,
+                                               db->db_type, 
+                                               device->byte_order);
+                   if (writer != NULL) {
+                       writers = g_list_prepend (writers, writer);
+                   }
                }
                format++;
        }


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
gtkpod-cvs2 mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2

Reply via email to