Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: Source/core/platform/image-decoders/ico/ICOImageDecoder.h

Issue 99103006: Moving GraphicsContext and dependencies from core to platform. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Final patch - fixes Android Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2008, 2009, Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #ifndef ICOImageDecoder_h
32 #define ICOImageDecoder_h
33
34 #include "core/platform/image-decoders/bmp/BMPImageReader.h"
35
36 namespace WebCore {
37
38 class PNGImageDecoder;
39
40 // This class decodes the ICO and CUR image formats.
41 class ICOImageDecoder : public ImageDecoder {
42 public:
43 ICOImageDecoder(ImageSource::AlphaOption, ImageSource::GammaAndColorProf ileOption, size_t maxDecodedBytes);
44 virtual ~ICOImageDecoder();
45
46 // ImageDecoder
47 virtual String filenameExtension() const { return "ico"; }
48 virtual void setData(SharedBuffer*, bool allDataReceived);
49 virtual bool isSizeAvailable();
50 virtual IntSize size() const;
51 virtual IntSize frameSizeAtIndex(size_t) const;
52 virtual bool setSize(unsigned width, unsigned height);
53 virtual size_t frameCount();
54 virtual ImageFrame* frameBufferAtIndex(size_t);
55 // CAUTION: setFailed() deletes all readers and decoders. Be careful to
56 // avoid accessing deleted memory, especially when calling this from
57 // inside BMPImageReader!
58 virtual bool setFailed();
59 virtual bool hotSpot(IntPoint&) const;
60
61 private:
62 enum ImageType {
63 Unknown,
64 BMP,
65 PNG,
66 };
67
68 enum FileType {
69 ICON = 1,
70 CURSOR = 2,
71 };
72
73 struct IconDirectoryEntry {
74 IntSize m_size;
75 uint16_t m_bitCount;
76 IntPoint m_hotSpot;
77 uint32_t m_imageOffset;
78 };
79
80 // Returns true if |a| is a preferable icon entry to |b|.
81 // Larger sizes, or greater bitdepths at the same size, are preferable.
82 static bool compareEntries(const IconDirectoryEntry& a, const IconDirect oryEntry& b);
83
84 inline uint16_t readUint16(int offset) const
85 {
86 return BMPImageReader::readUint16(m_data.get(), m_decodedOffset + of fset);
87 }
88
89 inline uint32_t readUint32(int offset) const
90 {
91 return BMPImageReader::readUint32(m_data.get(), m_decodedOffset + of fset);
92 }
93
94 // If the desired PNGImageDecoder exists, gives it the appropriate data.
95 void setDataForPNGDecoderAtIndex(size_t);
96
97 // Decodes the entry at |index|. If |onlySize| is true, stops decoding
98 // after calculating the image size. If decoding fails but there is no
99 // more data coming, sets the "decode failure" flag.
100 void decode(size_t index, bool onlySize);
101
102 // Decodes the directory and directory entries at the beginning of the
103 // data, and initializes members. Returns true if all decoding
104 // succeeded. Once this returns true, all entries' sizes are known.
105 bool decodeDirectory();
106
107 // Decodes the specified entry.
108 bool decodeAtIndex(size_t);
109
110 // Processes the ICONDIR at the beginning of the data. Returns true if
111 // the directory could be decoded.
112 bool processDirectory();
113
114 // Processes the ICONDIRENTRY records after the directory. Keeps the
115 // "best" entry as the one we'll decode. Returns true if the entries
116 // could be decoded.
117 bool processDirectoryEntries();
118
119 // Stores the hot-spot for |index| in |hotSpot| and returns true,
120 // or returns false if there is none.
121 bool hotSpotAtIndex(size_t index, IntPoint& hotSpot) const;
122
123 // Reads and returns a directory entry from the current offset into
124 // |data|.
125 IconDirectoryEntry readDirectoryEntry();
126
127 // Determines whether the desired entry is a BMP or PNG. Returns true
128 // if the type could be determined.
129 ImageType imageTypeAtIndex(size_t);
130
131 // An index into |m_data| representing how much we've already decoded.
132 // Note that this only tracks data _this_ class decodes; once the
133 // BMPImageReader takes over this will not be updated further.
134 size_t m_decodedOffset;
135
136 // Which type of file (ICO/CUR) this is.
137 FileType m_fileType;
138
139 // The headers for the ICO.
140 typedef Vector<IconDirectoryEntry> IconDirectoryEntries;
141 IconDirectoryEntries m_dirEntries;
142
143 // The image decoders for the various frames.
144 typedef Vector<OwnPtr<BMPImageReader> > BMPReaders;
145 BMPReaders m_bmpReaders;
146 typedef Vector<OwnPtr<PNGImageDecoder> > PNGDecoders;
147 PNGDecoders m_pngDecoders;
148
149 // Valid only while a BMPImageReader is decoding, this holds the size
150 // for the particular entry being decoded.
151 IntSize m_frameSize;
152 };
153
154 } // namespace WebCore
155
156 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698