/** * itdb_track_get_thumbnail: * @track: an #Itdb_Track * @width: width of the pixbuf to retrieve, -1 for the biggest possible size * (with no scaling) * @height: height of the pixbuf to retrieve, -1 for the biggest possible size * (with no scaling) * * Get a thumbnail representing the cover associated with the current track, * scaling it if appropriate. If either height or width is -1, then the biggest * unscaled thumbnail available will be returned. * * Returns: a #GdkPixbuf that must be unreffed when no longer used, NULL * if no artwork could be found or if libgpod is compiled without GdkPixbuf * support * * Since: 0.7.0 */ gpointer itdb_track_get_thumbnail (Itdb_Track *track, gint width, gint height) { g_return_val_if_fail (track != NULL, NULL); if (!itdb_track_has_thumbnails (track)) { return NULL; } if (track->itdb != NULL) { return itdb_thumb_to_pixbuf_at_size (track->itdb->device, track->artwork->thumbnail, width, height); } else { return itdb_thumb_to_pixbuf_at_size (NULL, track->artwork->thumbnail, width, height); } }
void PropertiesDialog::display(Itdb_Track* track) { currentTrack=track; this->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(0); this->buttonBox->button(QDialogButtonBox::Apply); if(itdb_track_has_thumbnails(track)) { GdkPixbuf* cover=(GdkPixbuf*)itdb_track_get_thumbnail(track,128,128); gdk_pixbuf_save (cover, "tmpcover", "jpeg", NULL, "quality", "100", NULL); AlbumArt->setPixmap(QPixmap("tmpcover")); } else AlbumArt->setPixmap(QPixmap(":/images/no-cover-art.jpg")); AlbumBox->setText(QString(track->album)); ArtistBox->setText(QString(track->artist)); TitleBox->setText(QString(track->title)); this->show(); }
/* returns the highest assigned ID or 0 if no IDs were used */ static guint32 ipod_artwork_db_set_ids (Itdb_iTunesDB *db) { GList *gl; const guint32 min_id = 0x64; guint32 cur_id; cur_id = min_id; if (itdb_device_supports_sparse_artwork (db->device)) { GHashTable *id_hash; id_hash = g_hash_table_new (g_direct_hash, g_direct_equal); for (gl = db->tracks; gl != NULL; gl = gl->next) { Itdb_Track *song; Itdb_Artwork *artwork; song = gl->data; g_return_val_if_fail (song, -1); artwork = song->artwork; g_return_val_if_fail (artwork, -1); if (itdb_track_has_thumbnails (song) && (artwork->id != 0)) { gpointer orig_key; gpointer orig_val; if (g_hash_table_lookup_extended (id_hash, GINT_TO_POINTER (artwork->id), &orig_key, &orig_val)) { /* ID was encountered before */ artwork->id = GPOINTER_TO_INT (orig_val); artwork->dbid = 0; } else { /* first time we see this ID */ g_hash_table_insert (id_hash, GINT_TO_POINTER (artwork->id), GINT_TO_POINTER (cur_id)); artwork->id = cur_id++; artwork->dbid = song->dbid; } song->mhii_link = artwork->id; } else { song->mhii_link = 0; } } g_hash_table_destroy (id_hash); } else { /* iPod does not support sparse artwork -- just renumber */ for (gl = db->tracks; gl != NULL; gl = gl->next) { Itdb_Track *song; song = gl->data; g_return_val_if_fail (song, -1); g_return_val_if_fail (song->artwork, -1); song->mhii_link = 0; if (itdb_track_has_thumbnails (song)) { song->artwork->id = cur_id++; song->artwork->dbid = song->dbid; } song->mhii_link = song->artwork->id; } } if (cur_id == min_id) return 0; else return cur_id-1; }
/* for all tracks with new artwork (id == 0) do the following: - try to identify if this artwork is identical to previous artwork (within the same album) - if no: assign new ID - if yes: assign same ID Returns the highest ID used. */ static guint32 ipod_artwork_mark_new_doubles (Itdb_iTunesDB *itdb, guint max_id) { GList *gl; GHashTable *hash_file, *hash_memory, *hash_pixbuf; hash_file = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); hash_memory = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); hash_pixbuf = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); for (gl=itdb->tracks; gl; gl=gl->next) { Itdb_Artwork *artwork; Itdb_Track *track; track= gl->data; g_return_val_if_fail (track, max_id); artwork = track->artwork; g_return_val_if_fail (artwork, max_id); if ((artwork->id == 0) && itdb_track_has_thumbnails (track)) { const gchar *checkstring; GHashTable *hash=NULL; gpointer orig_val = NULL; Itdb_Thumb *thumb = artwork->thumbnail; GChecksum *checksum = g_checksum_new (G_CHECKSUM_SHA1); /* use the album name as part of the checksum */ if (track->album && *track->album) { g_checksum_update (checksum, (guchar *)track->album, strlen (track->album)); } switch (thumb->data_type) { case ITDB_THUMB_TYPE_MEMORY: { Itdb_Thumb_Memory *mthumb = (Itdb_Thumb_Memory *)thumb; g_checksum_update (checksum, mthumb->image_data, mthumb->image_data_len); hash = hash_memory; break; } case ITDB_THUMB_TYPE_PIXBUF: { Itdb_Thumb_Pixbuf *pthumb = (Itdb_Thumb_Pixbuf *)thumb; g_return_val_if_fail (pthumb->pixbuf, max_id); g_checksum_update (checksum, gdk_pixbuf_get_pixels (pthumb->pixbuf), gdk_pixbuf_get_height (pthumb->pixbuf) * gdk_pixbuf_get_rowstride (pthumb->pixbuf)); hash = hash_pixbuf; break; } case ITDB_THUMB_TYPE_FILE: { Itdb_Thumb_File *fthumb = (Itdb_Thumb_File *)thumb; g_return_val_if_fail (fthumb->filename, max_id); g_checksum_update (checksum, (guchar *)fthumb->filename, strlen (fthumb->filename)); hash = hash_file; break; } case ITDB_THUMB_TYPE_INVALID: /* programming error */ g_print ("encountered invalid thumb.\n"); g_return_val_if_reached (max_id); break; case ITDB_THUMB_TYPE_IPOD: /* thumbs on the iPod are definitely not expected to have an ID of 0 */ g_print ("encountered iPod thumb with ID = 0.\n"); g_return_val_if_reached (max_id); break; } checkstring = g_checksum_get_string (checksum); if (g_hash_table_lookup_extended (hash, checkstring, NULL, &orig_val)) { /* same artwork was used before */ Itdb_Artwork *previous_artwork = orig_val; artwork->id = previous_artwork->id; artwork->dbid = 0; } else { /* first occurence of this artwork */ artwork->id = ++max_id; artwork->dbid = track->dbid; g_hash_table_insert (hash, g_strdup (checkstring), artwork); } track->mhii_link = artwork->id; g_checksum_free (checksum); } } g_hash_table_destroy (hash_memory); g_hash_table_destroy (hash_file); g_hash_table_destroy (hash_pixbuf); return max_id; }