Author: jwilcox
Date: 2006-06-29 14:18:46 -0400 (Thu, 29 Jun 2006)
New Revision: 62145
Modified:
trunk/ipod-sharp/ChangeLog
trunk/ipod-sharp/src/Device.cs
trunk/ipod-sharp/src/PhotoDatabase.cs
trunk/ipod-sharp/src/Thumbnail.cs
trunk/ipod-sharp/src/TrackDatabase.cs
trunk/ipod-sharp/tools/PhotoAdder.cs
trunk/ipod-sharp/ui/ArtworkHelpers.cs
Log:
2006-06-29 James Willcox <[EMAIL PROTECTED]>
* ui/ArtworkHelpers.cs: remove the SetCoverArt/SetThumbnail methods,
and just have ToBytes/ToPixbuf. Also, do a better job of figuring
out the endianess needed for the RGB565 images and handle rotation.
* src/TrackDatabase.cs: when opening files for read-only access,
just use File.OpenRead.
* src/Device.cs: add the new Size and ImageType properties
to ArtworkFormat
* src/Thumbnail.cs: use the new Size property to ensure that the
correct amount of data is received in SetData.
Modified: trunk/ipod-sharp/ChangeLog
===================================================================
--- trunk/ipod-sharp/ChangeLog 2006-06-29 16:37:54 UTC (rev 62144)
+++ trunk/ipod-sharp/ChangeLog 2006-06-29 18:18:46 UTC (rev 62145)
@@ -1,3 +1,18 @@
+2006-06-29 James Willcox <[EMAIL PROTECTED]>
+
+ * ui/ArtworkHelpers.cs: remove the SetCoverArt/SetThumbnail methods,
+ and just have ToBytes/ToPixbuf. Also, do a better job of figuring
+ out the endianess needed for the RGB565 images and handle rotation.
+
+ * src/TrackDatabase.cs: when opening files for read-only access,
+ just use File.OpenRead.
+
+ * src/Device.cs: add the new Size and ImageType properties
+ to ArtworkFormat
+
+ * src/Thumbnail.cs: use the new Size property to ensure that the
+ correct amount of data is received in SetData.
+
2006-06-27 James Willcox <[EMAIL PROTECTED]>
* src/TrackDatabase.cs: remove the length check in TrackRecord when
Modified: trunk/ipod-sharp/src/Device.cs
===================================================================
--- trunk/ipod-sharp/src/Device.cs 2006-06-29 16:37:54 UTC (rev 62144)
+++ trunk/ipod-sharp/src/Device.cs 2006-06-29 18:18:46 UTC (rev 62145)
@@ -23,15 +23,25 @@
PhotoTvScreen
}
+ public enum ImageType : int {
+ Rgb565,
+ Rgb56590,
+ Rgb565BE,
+ Rgb565BE90,
+ IYUV
+ }
+
public class ArtworkFormat {
- private ArtworkType type;
+ private ArtworkType artType;
private short width;
private short height;
private short correlationId;
+ private int size;
+ private ImageType imgType;
- public ArtworkType Type {
- get { return type; }
+ public ArtworkType ArtworkType {
+ get { return artType; }
}
public short Width {
@@ -42,15 +52,26 @@
get { return height; }
}
+ public int Size {
+ get { return size; }
+ }
+
+ public ImageType ImageType {
+ get { return imgType; }
+ }
+
internal short CorrelationId {
get { return correlationId; }
}
-
- internal ArtworkFormat (ArtworkType type, short width, short height,
short correlationId) {
- this.type = type;
+
+ internal ArtworkFormat (ArtworkType artType, short width, short
height, short correlationId,
+ int size, ImageType imgType) {
+ this.artType = artType;
this.width = width;
this.height = height;
this.correlationId = correlationId;
+ this.size = size;
+ this.imgType = imgType;
}
}
@@ -333,10 +354,10 @@
int offset = 0;
while (true) {
- int type = Marshal.ReadInt32 (array, offset);
+ int artType = Marshal.ReadInt32 (array, offset);
offset += 4;
- if (type == -1)
+ if (artType == -1)
break;
short width = Marshal.ReadInt16 (array, offset);
@@ -346,11 +367,16 @@
offset += 2;
short correlationId = Marshal.ReadInt16 (array, offset);
- offset += 2;
+ offset += 4;
+
+ int size = Marshal.ReadInt32 (array, offset);
+ offset += 4;
+
+ int imgType = Marshal.ReadInt32 (array, offset);
+ offset += 4;
- offset += 2; // two bytes of padding after the struct; if you
read it, it's always 0xffff
-
- formats[correlationId] = new ArtworkFormat ((ArtworkType)
type, width, height, correlationId);
+ formats[correlationId] = new ArtworkFormat ((ArtworkType)
artType, width, height, correlationId,
+ size, (ImageType)
imgType);
}
}
@@ -359,7 +385,7 @@
public ArtworkFormat LookupFormat (ArtworkType type) {
foreach (ArtworkFormat format in formats.Values) {
- if (format.Type == type)
+ if (format.ArtworkType == type)
return format;
}
Modified: trunk/ipod-sharp/src/PhotoDatabase.cs
===================================================================
--- trunk/ipod-sharp/src/PhotoDatabase.cs 2006-06-29 16:37:54 UTC (rev
62144)
+++ trunk/ipod-sharp/src/PhotoDatabase.cs 2006-06-29 18:18:46 UTC (rev
62145)
@@ -1067,7 +1067,7 @@
if (createFresh || !File.Exists (PhotoDbPath))
return;
- using (BinaryReader reader = new BinaryReader (File.Open
(PhotoDbPath, FileMode.Open))) {
+ using (BinaryReader reader = new BinaryReader (File.OpenRead
(PhotoDbPath))) {
dfr.Read (reader);
PhotoDataSetRecord albumSet = dfr[PhotoDataSetIndex.AlbumList];
Modified: trunk/ipod-sharp/src/Thumbnail.cs
===================================================================
--- trunk/ipod-sharp/src/Thumbnail.cs 2006-06-29 16:37:54 UTC (rev 62144)
+++ trunk/ipod-sharp/src/Thumbnail.cs 2006-06-29 18:18:46 UTC (rev 62145)
@@ -87,18 +87,17 @@
}
public void SetData (byte[] data) {
- int expectedLength = photo.PhotoDatabase.GetThumbSize
(format.CorrelationId);
- if (expectedLength > 0 && data.Length != expectedLength)
+ if (data.Length < format.Size)
throw new ArgumentException (String.Format ("Expected data
length of {0}, but got {1}",
- expectedLength,
data.Length));
+ format.Size,
data.Length));
Stream stream = photo.PhotoDatabase.GetTempFile ();
stream.Seek (0, SeekOrigin.End);
record.ThumbnailOffset = (int) stream.Position;
- record.ImageSize = data.Length;
+ record.ImageSize = format.Size;
- stream.Write (data, 0, data.Length);
+ stream.Write (data, 0, format.Size);
record.Dirty = true;
}
Modified: trunk/ipod-sharp/src/TrackDatabase.cs
===================================================================
--- trunk/ipod-sharp/src/TrackDatabase.cs 2006-06-29 16:37:54 UTC (rev
62144)
+++ trunk/ipod-sharp/src/TrackDatabase.cs 2006-06-29 18:18:46 UTC (rev
62145)
@@ -1561,6 +1561,10 @@
get { return ControlPath + "iTunes/Play Counts"; }
}
+ public Device Device {
+ get { return device; }
+ }
+
public IList<Track> Tracks {
get {
return new ReadOnlyCollection<Track> (tracks);
@@ -1618,8 +1622,7 @@
if (!info.Exists || info.Length == 0)
return;
- using (BinaryReader reader = new
- BinaryReader (File.Open (PlayCountsPath, FileMode.Open,
FileAccess.Read))) {
+ using (BinaryReader reader = new BinaryReader (File.OpenRead
(PlayCountsPath))) {
byte[] header = reader.ReadBytes (96);
int entryLength = dbrec.ToInt32 (header, 8);
@@ -1663,7 +1666,7 @@
List<Track> otgtracks = new List<Track> ();
- using (BinaryReader reader = new BinaryReader (File.Open (path,
FileMode.Open, FileAccess.Read))) {
+ using (BinaryReader reader = new BinaryReader (File.OpenRead
(path))) {
byte[] header = reader.ReadBytes (20);
@@ -1712,7 +1715,7 @@
return;
}
- using (BinaryReader reader = new BinaryReader (File.Open
(TrackDbPath, FileMode.Open, FileAccess.Read))) {
+ using (BinaryReader reader = new BinaryReader (File.OpenRead
(TrackDbPath))) {
dbrec = new DatabaseRecord (useBE);
dbrec.Read (null, reader);
@@ -1808,7 +1811,7 @@
long count = 0;
double lastPercent = 0.0;
- reader = new BinaryReader (new BufferedStream (File.Open
(track.FileName, FileMode.Open, FileAccess.Read)));
+ reader = new BinaryReader (new BufferedStream (File.OpenRead
(track.FileName)));
writer = new BinaryWriter (new BufferedStream (File.Open
(dest, FileMode.Create)));
do {
Modified: trunk/ipod-sharp/tools/PhotoAdder.cs
===================================================================
--- trunk/ipod-sharp/tools/PhotoAdder.cs 2006-06-29 16:37:54 UTC (rev
62144)
+++ trunk/ipod-sharp/tools/PhotoAdder.cs 2006-06-29 18:18:46 UTC (rev
62145)
@@ -11,8 +11,8 @@
private static void AddThumbnails (Device device, Photo photo, Gdk.Pixbuf
pixbuf) {
foreach (ArtworkFormat format in device.ArtworkFormats) {
- if (format.Type != ArtworkType.PhotoSmall && format.Type !=
ArtworkType.PhotoLarge &&
- format.Type != ArtworkType.PhotoFullScreen && format.Type !=
ArtworkType.PhotoTvScreen)
+ if (format.ArtworkType != ArtworkType.PhotoSmall &&
format.ArtworkType != ArtworkType.PhotoLarge &&
+ format.ArtworkType != ArtworkType.PhotoFullScreen &&
format.ArtworkType != ArtworkType.PhotoTvScreen)
continue;
Thumbnail thumbnail = photo.CreateThumbnail ();
@@ -20,7 +20,7 @@
thumbnail.Width = format.Width;
thumbnail.Height = format.Height;
- ArtworkHelpers.SetThumbnail (thumbnail, pixbuf);
+ thumbnail.SetData (ArtworkHelpers.ToBytes (thumbnail.Format,
pixbuf));
}
}
@@ -37,7 +37,7 @@
photo.FullSizeFileName = file;
album.Add (photo);
} catch (Exception e) {
- Console.Error.WriteLine (e.Message);
+ Console.Error.WriteLine (e);
}
}
Modified: trunk/ipod-sharp/ui/ArtworkHelpers.cs
===================================================================
--- trunk/ipod-sharp/ui/ArtworkHelpers.cs 2006-06-29 16:37:54 UTC (rev
62144)
+++ trunk/ipod-sharp/ui/ArtworkHelpers.cs 2006-06-29 18:18:46 UTC (rev
62145)
@@ -194,35 +194,77 @@
}
}
- private static Gdk.Pixbuf ToPixbuf (ArtworkFormat format, byte[] data)
{
+ public static Gdk.Pixbuf ToPixbuf (ArtworkFormat format, byte[] data) {
Gdk.Pixbuf pixbuf = new Gdk.Pixbuf (Gdk.Colorspace.Rgb, false, 8,
format.Width, format.Height);
-
- if (format.Type == ArtworkType.PhotoTvScreen) {
+ Gdk.Pixbuf rotated = null;
+
+ switch (format.ImageType) {
+ case ImageType.Rgb565:
+ UnpackRgb565 (data, pixbuf, false);
+ break;
+ case ImageType.Rgb56590:
+ UnpackRgb565 (data, pixbuf, false);
+ rotated = pixbuf.RotateSimple (Gdk.PixbufRotation.Clockwise);
+ pixbuf.Dispose ();
+ pixbuf = rotated;
+ break;
+ case ImageType.Rgb565BE:
+ UnpackRgb565 (data, pixbuf, true);
+ break;
+ case ImageType.Rgb565BE90:
+ UnpackRgb565 (data, pixbuf, true);
+ rotated = pixbuf.RotateSimple (Gdk.PixbufRotation.Clockwise);
+ pixbuf.Dispose ();
+ pixbuf = rotated;
+ break;
+ case ImageType.IYUV:
UnpackIYUV (data, pixbuf);
- } else {
- // FIXME: this is totally lame
- UnpackRgb565 (data, pixbuf, format.Width == 176);
+ break;
+ default:
+ throw new ApplicationException ("Unknown image type: " +
format.ImageType);
}
return pixbuf;
}
- private static byte[] ToBytes (ArtworkFormat format, Gdk.Pixbuf
pixbuf) {
+ public static byte[] ToBytes (ArtworkFormat format, Gdk.Pixbuf pixbuf)
{
bool disposePixbuf = false;
+
+ if (format.ImageType == ImageType.Rgb56590 || format.ImageType ==
ImageType.Rgb565BE90) {
+ pixbuf = pixbuf.RotateSimple
(Gdk.PixbufRotation.Counterclockwise);
+ disposePixbuf = true;
+ }
// FIXME: preserve aspect ratio
if (pixbuf.Height > format.Height || pixbuf.Width > format.Width) {
- pixbuf = pixbuf.ScaleSimple (format.Width, format.Height,
- Gdk.InterpType.Bilinear);
+ Gdk.Pixbuf scaled = pixbuf.ScaleSimple (format.Width,
format.Height,
+
Gdk.InterpType.Bilinear);
+
+ if (disposePixbuf) {
+ pixbuf.Dispose ();
+ }
+
+ pixbuf = scaled;
+
disposePixbuf = true;
}
- byte[] data;
- if (format.Type == ArtworkType.PhotoTvScreen) {
+ byte[] data = null;
+
+ switch (format.ImageType) {
+ case ImageType.Rgb565:
+ case ImageType.Rgb56590:
+ data = PackRgb565 (pixbuf, false);
+ break;
+ case ImageType.Rgb565BE:
+ case ImageType.Rgb565BE90:
+ data = PackRgb565 (pixbuf, true);
+ break;
+ case ImageType.IYUV:
data = PackIYUV (pixbuf);
- } else {
- // FIXME: this is totally lame
- data = PackRgb565 (pixbuf, format.Width == 176);
+ break;
+ default:
+ throw new ApplicationException ("Unknown image type: " +
format.ImageType);
}
if (disposePixbuf) {
@@ -231,31 +273,5 @@
return data;
}
-
- public static Gdk.Pixbuf GetCoverArt (Track track, ArtworkFormat
format) {
- byte[] data = track.GetCoverArt (format);
- if (data == null)
- return null;
-
- return ToPixbuf (format, data);
- }
-
- public static void SetCoverArt (Track track, ArtworkFormat format,
Gdk.Pixbuf pixbuf) {
- byte[] data = ToBytes (format, pixbuf);
- track.SetCoverArt (format, data);
- }
-
- public static Gdk.Pixbuf GetThumbnail (Thumbnail thumbnail) {
- byte[] data = thumbnail.GetData ();
- if (data == null)
- return null;
-
- return ToPixbuf (thumbnail.Format, data);
- }
-
- public static void SetThumbnail (Thumbnail thumbnail, Gdk.Pixbuf
pixbuf) {
- byte[] data = ToBytes (thumbnail.Format, pixbuf);
- thumbnail.SetData (data);
- }
}
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches