~ubuntu-branches/ubuntu/jaunty/beagle/jaunty-security

« back to all changes in this revision

Viewing changes to Util/F-Spot/Bim.cs

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Ebner
  • Date: 2008-05-04 00:31:32 UTC
  • mfrom: (1.1.21 upstream)
  • Revision ID: james.westby@ubuntu.com-20080504003132-2tkm5o8moo5952ri
Tags: 0.3.7-2ubuntu1
 * Merge from Debian unstable. (LP: #225746) Remaining Ubuntu changes:
  - debian/control:
    + Rename ice{weasel,dove}-beagle to {mozilla,thunderbird}-beagle and
      and update the dependencies accordingly.
    + Change Maintainer to Ubuntu Mono Team.
  - debian/rules:
    + Install the mozilla-beagle and thunderbird-beagle extensions.
  - ice{dove,weasel}.dirs:
    + Renamed to {mozilla,thunderbird}-beagle.dirs.
    + Fixed paths to point to usr/lib/{firefox,thunderbird}

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//
2
 
// Bim.cs
3
 
//
4
 
// Authors:
5
 
//     Larry Ewing <lewing@novell.com>
6
 
//
7
 
//
8
 
// Copyright (C) 2004 - 2006 Novell, Inc (http://www.novell.com)
9
 
//
10
 
// Permission is hereby granted, free of charge, to any person obtaining
11
 
// a copy of this software and associated documentation files (the
12
 
// "Software"), to deal in the Software without restriction, including
13
 
// without limitation the rights to use, copy, modify, merge, publish,
14
 
// distribute, sublicense, and/or sell copies of the Software, and to
15
 
// permit persons to whom the Software is furnished to do so, subject to
16
 
// the following conditions:
17
 
// 
18
 
// The above copyright notice and this permission notice shall be
19
 
// included in all copies or substantial portions of the Software.
20
 
// 
21
 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22
 
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23
 
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24
 
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25
 
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26
 
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27
 
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
 
//
29
 
 
30
 
namespace Beagle.Util.Bim {
31
 
        public enum EntryType : ushort {
32
 
                ObsoleteImageInfo = 0x03e8,  
33
 
                MacPrintManager = 0x03e9,
34
 
                MacPrintXML = 0x03ea,
35
 
                ObsoleteIndexedColorTable = 0x03eb,
36
 
                ResolutionInfo = 0x03ed,
37
 
                AlphaChannelNames = 0x03ee,
38
 
                DisplayInfo = 0x03ef,
39
 
                Caption = 0x03f0,
40
 
                Border = 0x03f1,
41
 
                BackgroundColor = 0x03f2,
42
 
                PrintFlags = 0x03f3,
43
 
                GrayHalftone = 0x03f4,
44
 
                ColorHalftone = 0x03f5,
45
 
                DuotoneHalftone = 0x03f6,
46
 
                GrayTransfer = 0x03f7,
47
 
                ColorTransfer = 0x03f8,
48
 
                DuotoneTransfer = 0x03f9,
49
 
                DuotoneInformation = 0x03fa,
50
 
                BWDot = 0x03fb,
51
 
                ObsoleteUnknown1 = 0x03fc,
52
 
                LayerState = 0x0400,
53
 
                WorkingPath = 0x0401,
54
 
                LayerGroupInfomation = 0x0402,
55
 
                ObsoleteUnknown2 = 0x0403,
56
 
                IPTCNAA = 0x0404,
57
 
                RawImageMode = 0x0405,
58
 
                JpegQuality = 0x0406,
59
 
                GridGuideInformation = 0x0408,
60
 
                ThumbnailResource = 0x0409,
61
 
                CopyrightFlag = 0x040a,
62
 
                URL = 0x040b,
63
 
                ThumbnailResource2 = 0x040c,
64
 
                GlobalAngle = 0x040d,
65
 
                ColorSamplers = 0x040e,
66
 
                ICCProfile = 0x040f,
67
 
                Watermark = 0x0410,
68
 
                ICCUntagged = 0x0411,
69
 
                EffectsVisible = 0x0412,
70
 
                SpotHalftone = 0x0413,
71
 
                LastID = 0x0414,
72
 
                UnicodeAlphaNames = 0x0415,
73
 
                IndexedColorTable = 0x0416,
74
 
                TransparentIndex = 0x0417,
75
 
                GlobalAltitude = 0x0419,
76
 
                Slices = 0x041a,
77
 
                WorkflowURL = 0x041b,
78
 
                XPEPJump = 0x041c,
79
 
                AlphaIdentifiers = 0x041d,
80
 
                URLList = 0x041e,
81
 
                VersionInfo = 0x0421,
82
 
                XMP = 0x0424,
83
 
                FirstPath = 0x07d0,
84
 
                LastPAth = 0x0bb6,
85
 
                ClippingPathName = 0x0bb7,
86
 
                PrintFlags2 = 0x2710,
87
 
        }
88
 
 
89
 
        /*
90
 
          From what I can see it looks like these resources are a just
91
 
          a list of records starting with a 8Bim\0 followed by a 16 bit
92
 
          value that is the record type then a 8 bit offset and 32bit length. IPTC data is
93
 
          type 0x0404, I don't know any other types at the moment.
94
 
 
95
 
          see http://www.fine-view.com/jp/lab/doc/ps6ffspecsv2.pdf and the section on image resource blocks.
96
 
        */
97
 
 
98
 
        public class Entry
99
 
        {
100
 
                public ushort  Type;
101
 
                public string  Name;
102
 
                public byte [] Data;
103
 
 
104
 
                const string Marker = "8BIM";
105
 
                public Entry ()
106
 
                {
107
 
 
108
 
                }
109
 
 
110
 
                public int Load (System.IO.Stream stream)
111
 
                {
112
 
                        byte [] header = new byte [6];
113
 
                        
114
 
                        stream.Read (header, 0, header.Length);
115
 
                        if (System.Text.Encoding.ASCII.GetString (header, 0, 4) != Marker)
116
 
                                throw new System.Exception ("missing header");
117
 
                        
118
 
                        Type = BitConverter.ToUInt16 (header, 4, false);
119
 
 
120
 
                        int name_length = stream.ReadByte ();
121
 
                        if (name_length > 0) {
122
 
                                byte [] name_data = new byte [name_length];
123
 
                                stream.Read (name_data, 0, name_length);
124
 
                                Name = System.Text.Encoding.ASCII.GetString (name_data);
125
 
                        }
126
 
                        
127
 
                        if (name_length % 2 == 0)
128
 
                                stream.ReadByte ();
129
 
 
130
 
                        stream.Read (header, 0, 4);
131
 
                        uint length = BitConverter.ToUInt32 (header, 0, false);
132
 
 
133
 
                        Data = new byte [length];
134
 
                        stream.Read (Data, 0, Data.Length);
135
 
 
136
 
                        if (Data.Length % 2 > 0)
137
 
                                stream.ReadByte ();
138
 
 
139
 
                        return header.Length + Data.Length;
140
 
                }
141
 
                
142
 
                public void Save (System.IO.Stream stream) 
143
 
                {
144
 
                        byte [] tmp;
145
 
                        tmp = System.Text.Encoding.ASCII.GetBytes (Marker);
146
 
                        stream.Write (tmp, 0, tmp.Length);
147
 
                        tmp = BitConverter.GetBytes (Type, false);
148
 
                        stream.Write (tmp, 0, tmp.Length);
149
 
 
150
 
                        // Write the name
151
 
                        stream.WriteByte ((byte)Name.Length);
152
 
                        tmp = System.Text.Encoding.ASCII.GetBytes (Name);
153
 
                        stream.Write (tmp, 0, tmp.Length);
154
 
 
155
 
                        // Pad the name
156
 
                        if (tmp.Length % 2 == 0)
157
 
                                stream.WriteByte (0);
158
 
 
159
 
                        // Write the data
160
 
                        tmp  = BitConverter.GetBytes ((uint)Data.Length, false);
161
 
                        stream.Write (tmp, 0, tmp.Length);
162
 
 
163
 
                        stream.Write (Data, 0, Data.Length);
164
 
                        // Pad the data
165
 
                        if (Data.Length % 2 > 0)
166
 
                                stream.WriteByte (0);
167
 
                }
168
 
        }
169
 
 
170
 
        public class BimFile : SemWeb.StatementSource
171
 
        {
172
 
                // False seems a safe default
173
 
                public bool Distinct {
174
 
                        get { return false; }
175
 
                }
176
 
 
177
 
                System.Collections.ArrayList entries = new System.Collections.ArrayList ();
178
 
 
179
 
                public BimFile (System.IO.Stream stream)
180
 
                {
181
 
                        Load (stream);
182
 
                }
183
 
                
184
 
                public void Select (SemWeb.StatementSink sink)
185
 
                {
186
 
                        foreach (Entry e in entries) {
187
 
                                EntryType type = (EntryType) e.Type;
188
 
 
189
 
                                switch (type) {
190
 
                                case EntryType.IPTCNAA:
191
 
                                        System.IO.Stream iptcstream = new System.IO.MemoryStream (e.Data);
192
 
                                        Iptc.IptcFile iptc = new Iptc.IptcFile (iptcstream);
193
 
                                        iptc.Select (sink);
194
 
                                        break;
195
 
                                case EntryType.XMP:
196
 
                                        System.IO.Stream xmpstream = new System.IO.MemoryStream (e.Data);
197
 
                                        Xmp.XmpFile xmp = new Xmp.XmpFile (xmpstream);
198
 
                                        xmp.Select (sink);
199
 
                                        break;
200
 
                                default:
201
 
                                        break;
202
 
                                }
203
 
                        }
204
 
                }
205
 
 
206
 
                public Entry FindEntry (EntryType type)
207
 
                {
208
 
                        foreach (Entry current in entries)
209
 
                                if (current.Type == (ushort)type)
210
 
                                        return current;
211
 
 
212
 
                        return null;
213
 
                }
214
 
 
215
 
                public void Load (System.IO.Stream stream)
216
 
                {
217
 
                        while (stream.Position < stream.Length)
218
 
                        {
219
 
                                Entry current = new Entry ();
220
 
                                current.Load (stream);
221
 
                                //System.Console.WriteLine ("read {0} - {1}", ((EntryType)current.Type).ToString (), current.Name);
222
 
                                try {
223
 
                                        //System.Console.WriteLine (System.Text.Encoding.ASCII.GetString (current.Data));
224
 
                                } catch (System.Exception e) {
225
 
                                        System.Console.WriteLine (e.ToString ());
226
 
                                }
227
 
                                entries.Add (current);
228
 
                        }
229
 
                }
230
 
 
231
 
                public void Save (System.IO.Stream stream)
232
 
                {
233
 
                        foreach (Entry e in entries) {
234
 
                                e.Save (stream);
235
 
                        }
236
 
                }
237
 
        }
238
 
}
239
 
 
240
 
 
241