5
// Larry Ewing <lewing@novell.com>
8
// Copyright (C) 2004 - 2006 Novell, Inc (http://www.novell.com)
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:
18
// The above copyright notice and this permission notice shall be
19
// included in all copies or substantial portions of the Software.
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.
30
namespace Beagle.Util.Bim {
31
public enum EntryType : ushort {
32
ObsoleteImageInfo = 0x03e8,
33
MacPrintManager = 0x03e9,
35
ObsoleteIndexedColorTable = 0x03eb,
36
ResolutionInfo = 0x03ed,
37
AlphaChannelNames = 0x03ee,
41
BackgroundColor = 0x03f2,
43
GrayHalftone = 0x03f4,
44
ColorHalftone = 0x03f5,
45
DuotoneHalftone = 0x03f6,
46
GrayTransfer = 0x03f7,
47
ColorTransfer = 0x03f8,
48
DuotoneTransfer = 0x03f9,
49
DuotoneInformation = 0x03fa,
51
ObsoleteUnknown1 = 0x03fc,
54
LayerGroupInfomation = 0x0402,
55
ObsoleteUnknown2 = 0x0403,
57
RawImageMode = 0x0405,
59
GridGuideInformation = 0x0408,
60
ThumbnailResource = 0x0409,
61
CopyrightFlag = 0x040a,
63
ThumbnailResource2 = 0x040c,
65
ColorSamplers = 0x040e,
69
EffectsVisible = 0x0412,
70
SpotHalftone = 0x0413,
72
UnicodeAlphaNames = 0x0415,
73
IndexedColorTable = 0x0416,
74
TransparentIndex = 0x0417,
75
GlobalAltitude = 0x0419,
79
AlphaIdentifiers = 0x041d,
85
ClippingPathName = 0x0bb7,
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.
95
see http://www.fine-view.com/jp/lab/doc/ps6ffspecsv2.pdf and the section on image resource blocks.
104
const string Marker = "8BIM";
110
public int Load (System.IO.Stream stream)
112
byte [] header = new byte [6];
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");
118
Type = BitConverter.ToUInt16 (header, 4, false);
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);
127
if (name_length % 2 == 0)
130
stream.Read (header, 0, 4);
131
uint length = BitConverter.ToUInt32 (header, 0, false);
133
Data = new byte [length];
134
stream.Read (Data, 0, Data.Length);
136
if (Data.Length % 2 > 0)
139
return header.Length + Data.Length;
142
public void Save (System.IO.Stream stream)
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);
151
stream.WriteByte ((byte)Name.Length);
152
tmp = System.Text.Encoding.ASCII.GetBytes (Name);
153
stream.Write (tmp, 0, tmp.Length);
156
if (tmp.Length % 2 == 0)
157
stream.WriteByte (0);
160
tmp = BitConverter.GetBytes ((uint)Data.Length, false);
161
stream.Write (tmp, 0, tmp.Length);
163
stream.Write (Data, 0, Data.Length);
165
if (Data.Length % 2 > 0)
166
stream.WriteByte (0);
170
public class BimFile : SemWeb.StatementSource
172
// False seems a safe default
173
public bool Distinct {
174
get { return false; }
177
System.Collections.ArrayList entries = new System.Collections.ArrayList ();
179
public BimFile (System.IO.Stream stream)
184
public void Select (SemWeb.StatementSink sink)
186
foreach (Entry e in entries) {
187
EntryType type = (EntryType) e.Type;
190
case EntryType.IPTCNAA:
191
System.IO.Stream iptcstream = new System.IO.MemoryStream (e.Data);
192
Iptc.IptcFile iptc = new Iptc.IptcFile (iptcstream);
196
System.IO.Stream xmpstream = new System.IO.MemoryStream (e.Data);
197
Xmp.XmpFile xmp = new Xmp.XmpFile (xmpstream);
206
public Entry FindEntry (EntryType type)
208
foreach (Entry current in entries)
209
if (current.Type == (ushort)type)
215
public void Load (System.IO.Stream stream)
217
while (stream.Position < stream.Length)
219
Entry current = new Entry ();
220
current.Load (stream);
221
//System.Console.WriteLine ("read {0} - {1}", ((EntryType)current.Type).ToString (), current.Name);
223
//System.Console.WriteLine (System.Text.Encoding.ASCII.GetString (current.Data));
224
} catch (System.Exception e) {
225
System.Console.WriteLine (e.ToString ());
227
entries.Add (current);
231
public void Save (System.IO.Stream stream)
233
foreach (Entry e in entries) {