4 // Copyright (C) 2004 Novell, Inc.
8 // Permission is hereby granted, free of charge, to any person obtaining a
9 // copy of this software and associated documentation files (the "Software"),
10 // to deal in the Software without restriction, including without limitation
11 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 // and/or sell copies of the Software, and to permit persons to whom the
13 // Software is furnished to do so, subject to the following conditions:
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 // DEALINGS IN THE SOFTWARE.
35 namespace Beagle
.Filters
{
37 public class FilterPng
: FilterImage
{
39 public FilterPng () : base ()
41 AddSupportedFlavor (FilterFlavor
.NewFromMimeType ("image/png"));
44 protected override void PullImageProperties ()
46 PngHeader png
= new PngHeader (Stream
);
48 foreach (PngHeader
.Chunk chunk
in png
.Chunks
){
49 if (chunk
is PngHeader
.IhdrChunk
) {
50 PngHeader
.IhdrChunk ihdr
= (PngHeader
.IhdrChunk
)chunk
;
52 Width
= (int)ihdr
.Width
;
53 Height
= (int)ihdr
.Height
;
56 bool hasAlpha
= false;
57 string colorType
= null;
60 case PngHeader
.ColorType
.Gray
:
61 colorType
= "Greyscale";
64 case PngHeader
.ColorType
.Rgb
:
65 colorType
= "Truecolor";
68 case PngHeader
.ColorType
.Indexed
:
69 colorType
= "Indexed";
72 case PngHeader
.ColorType
.GrayAlpha
:
73 colorType
= "Greyscale";
76 case PngHeader
.ColorType
.RgbAlpha
:
77 colorType
= "Truecolor";
82 AddProperty (Beagle
.Property
.NewUnsearched ("fixme:colortype", colorType
));
83 AddProperty (Beagle
.Property
.NewBool ("fixme:hasalpha", hasAlpha
));
84 } else if (chunk
is PngHeader
.TextChunk
) {
85 ExtractTextProperty ((PngHeader
.TextChunk
) chunk
);
92 private void ExtractTextProperty (PngHeader
.TextChunk tchunk
)
94 switch (tchunk
.Keyword
) {
96 AddProperty (Beagle
.Property
.New ("dc:title", tchunk
.Text
));
99 AddProperty (Beagle
.Property
.New ("dc:creator", tchunk
.Text
));
102 AddProperty (Beagle
.Property
.New ("dc:rights", tchunk
.Text
));
105 AddProperty (Beagle
.Property
.New ("png:description", tchunk
.Text
));
108 AddProperty (Beagle
.Property
.New ("png:comment", tchunk
.Text
));
111 case "XML:com.adobe.xmp":
112 XmpFile xmp
= new XmpFile (new MemoryStream (tchunk
.TextData
));
113 AddXmpProperties (xmp
);
118 case "Creation Time":