diff options
author | Jorg Schuler <jcsjcs@users.sourceforge.net> | 2007-11-04 00:48:12 +0000 |
---|---|---|
committer | Jorg Schuler <jcsjcs@users.sourceforge.net> | 2007-11-04 00:48:12 +0000 |
commit | 332d3a1fe2f6eb6d3aef6ca8b65b21507975608f (patch) | |
tree | 8231e3b68b07eb781f2f7c034967376dcc9f42f7 | |
parent | db1a26c4b6c2f920ad6e5a188a3304097211f250 (diff) | |
download | libgpod-tmz-332d3a1fe2f6eb6d3aef6ca8b65b21507975608f.tar.gz libgpod-tmz-332d3a1fe2f6eb6d3aef6ca8b65b21507975608f.tar.xz libgpod-tmz-332d3a1fe2f6eb6d3aef6ca8b65b21507975608f.zip |
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.
git-svn-id: https://gtkpod.svn.sf.net/svnroot/gtkpod/libgpod/trunk@1753 f01d2545-417e-4e96-918e-98f8d0dbbcb6
-rw-r--r-- | ChangeLog | 51 | ||||
-rw-r--r-- | src/db-artwork-writer.c | 43 | ||||
-rw-r--r-- | src/db-image-parser.h | 3 | ||||
-rw-r--r-- | src/itdb.h | 2 | ||||
-rw-r--r-- | src/itdb_artwork.c | 7 | ||||
-rw-r--r-- | src/itdb_photoalbum.c | 55 | ||||
-rw-r--r-- | src/ithumb-writer.c | 101 |
7 files changed, 172 insertions, 90 deletions
@@ -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 <christophe@anevia.com> 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 <teuf@gnome.org> @@ -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 <teuf@gnome.org> @@ -38,12 +65,12 @@ 2007-10-29 Christophe Fergeau <teuf@gnome.org> * src/itdb_device.c: the iPod Touch probably uses the same image format - as the iPhone + as the iPhone 2007-10-29 Christophe Fergeau <teuf@gnome.org> * configure.ac: raise glib requirement to 2.8 (because of - g_file_set_contents) + g_file_set_contents) 2007-10-29 Christophe Fergeau <teuf@gnome.org> @@ -53,12 +80,12 @@ 2007-10-29 Christophe Fergeau <teuf@gnome.org> * 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 <teuf@gnome.org> * 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 <teuf@gnome.org> diff --git a/src/db-artwork-writer.c b/src/db-artwork-writer.c index d8c017c..31fb226 100644 --- a/src/db-artwork-writer.c +++ b/src/db-artwork-writer.c @@ -381,11 +381,10 @@ write_mhni (Itdb_DB *db, Itdb_Thumb *thumb, int correlation_id, iPodBuffer *buff 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) { @@ -492,13 +491,21 @@ write_mhii (Itdb_DB *db, void *data, iPodBuffer *buffer) 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 @@ write_mhii (Itdb_DB *db, void *data, iPodBuffer *buffer) 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 @@ write_mhii (Itdb_DB *db, void *data, iPodBuffer *buffer) 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 @@ write_mhli (Itdb_DB *db, iPodBuffer *buffer ) 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 @@ write_mhif (Itdb_DB *db, iPodBuffer *buffer, 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 @@ write_mhlf (Itdb_DB *db, iPodBuffer *buffer) 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; } diff --git a/src/db-image-parser.h b/src/db-image-parser.h index bd06434..a9a3862 100644 --- a/src/db-image-parser.h +++ b/src/db-image-parser.h @@ -82,6 +82,9 @@ G_GNUC_INTERNAL Itdb_Thumb *ipod_image_new_from_mhni (MhniHeader *mhni, 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); @@ -447,7 +447,7 @@ struct _Itdb_SPLRules /* 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, diff --git a/src/itdb_artwork.c b/src/itdb_artwork.c index 1c2bcbf..2d8ce77 100644 --- a/src/itdb_artwork.c +++ b/src/itdb_artwork.c @@ -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 @@ itdb_thumb_get_byteorder (const ItdbThumbFormat format) 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 @@ itdb_thumb_get_byteorder (const ItdbThumbFormat format) 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 @@ itdb_thumb_get_byteorder (const ItdbThumbFormat format) 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); diff --git a/src/itdb_photoalbum.c b/src/itdb_photoalbum.c index 3533a56..001b86a 100644 --- a/src/itdb_photoalbum.c +++ b/src/itdb_photoalbum.c @@ -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,33 +417,33 @@ static Itdb_Artwork *itdb_photodb_add_photo_internal (Itdb_PhotoDB *db, 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 (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 (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); + } } } diff --git a/src/ithumb-writer.c b/src/ithumb-writer.c index 4f2e410..050671f 100644 --- a/src/ithumb-writer.c +++ b/src/ithumb-writer.c @@ -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 @@ pack_I420 (GdkPixbuf *orig_pixbuf, const Itdb_ArtworkFormat *img_info, 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 @@ itdb_write_ithumb_files (Itdb_DB *db) 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++; } |