~ubuntu-branches/ubuntu/quantal/ipod-sharp/quantal

« back to all changes in this revision

Viewing changes to src/Thumbnail.cs

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2006-11-13 12:36:39 UTC
  • mfrom: (1.1.4 upstream) (6.1.5 edgy)
  • Revision ID: james.westby@ubuntu.com-20061113123639-cynm2axegef1etff
* New upstream release
* debian/patches/01_fix-playcounts.patch:
  + Dropped, merged upstream
* debian/control:
  + Build depend on mono-gmcs, libmono-sharpzip2.84-cil, libmono2.0-cil,
    libglib2.0-dev and libipoddevice >= 0.5.0
  + Bumped Standards-Version to 3.7.2
  + Add ${misc:Depends} to Depends
  + Let libipodui-cil depend on libipod-cil
* debian/libipod-cil.install:
  + Add ipod-sharp-firmware.dll
* debian/patches/01_dllmap.patch:
  + Add dllmap to libgobject-2.0.so.0 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
using System;
 
2
using System.IO;
 
3
 
 
4
namespace IPod {
 
5
 
 
6
    /*
 
7
    public enum ThumbnailFormat {
 
8
        Rgb565,
 
9
        IYUV,
 
10
        Rgb565BE,
 
11
        Rgb565BE90
 
12
    }
 
13
    */
 
14
 
 
15
    public class Thumbnail {
 
16
 
 
17
        private Photo photo;
 
18
        private ImageNameRecord record;
 
19
 
 
20
        private ArtworkFormat format = null;
 
21
 
 
22
        public Photo Photo {
 
23
            get { return photo; }
 
24
        }
 
25
 
 
26
        public int Size {
 
27
            get { return record.ImageSize; }
 
28
            set { record.ImageSize = value; }
 
29
        }
 
30
 
 
31
        public short VerticalPadding {
 
32
            get { return record.VerticalPadding; }
 
33
            set { record.VerticalPadding = value; }
 
34
        }
 
35
 
 
36
        public short HorizontalPadding {
 
37
            get { return record.HorizontalPadding; }
 
38
            set { record.HorizontalPadding = value; }
 
39
        }
 
40
 
 
41
        public short Height {
 
42
            get { return record.ImageHeight; }
 
43
            set { record.ImageHeight = value; }
 
44
        }
 
45
 
 
46
        public short Width {
 
47
            get { return record.ImageWidth; }
 
48
            set { record.ImageWidth = value; }
 
49
        }
 
50
 
 
51
        public ArtworkFormat Format {
 
52
            get {
 
53
                return format;
 
54
            } set {
 
55
                if (value == null)
 
56
                    throw new ArgumentNullException ("Format cannot be null");
 
57
                
 
58
                format = value;
 
59
                record.CorrelationId = format.CorrelationId;
 
60
                record.SetThumbFileName (photo.PhotoDatabase.IsPhotoDatabase);
 
61
            }
 
62
        }
 
63
 
 
64
        internal ImageNameRecord Record {
 
65
            get { return record; }
 
66
        }
 
67
        
 
68
        internal Thumbnail (Photo photo, ImageNameRecord record) {
 
69
            this.photo = photo;
 
70
            this.record = record;
 
71
 
 
72
            if (record.CorrelationId > 0) {
 
73
                Format = photo.PhotoDatabase.Device.LookupArtworkFormat (record.CorrelationId);
 
74
            }
 
75
        }
 
76
 
 
77
        public byte[] GetData () {
 
78
            if (record.Dirty) {
 
79
                return record.GetData (photo.PhotoDatabase.GetTempFile ());
 
80
            } else {
 
81
                string file = photo.PhotoDatabase.GetThumbPath (Format);
 
82
                
 
83
                using (FileStream stream = File.Open (file, FileMode.Open, FileAccess.Read, FileShare.Read)) {
 
84
                    return record.GetData (stream);
 
85
                }
 
86
            }
 
87
        }
 
88
 
 
89
        public void SetData (byte[] data) {
 
90
            if (data.Length < format.Size)
 
91
                throw new ArgumentException (String.Format ("Expected data length of {0}, but got {1}",
 
92
                                                            format.Size, data.Length));
 
93
            
 
94
            Stream stream = photo.PhotoDatabase.GetTempFile ();
 
95
            stream.Seek (0, SeekOrigin.End);
 
96
            
 
97
            record.ThumbnailOffset = (int) stream.Position;
 
98
            record.ImageSize = format.Size;
 
99
            
 
100
            stream.Write (data, 0, format.Size);
 
101
            
 
102
            record.Dirty = true;
 
103
        }
 
104
    }
 
105
}