1 /**********************************************\
2 *
3 *  Simple Viewer GL edition
4 *  by Andrey A. Ugolnik
5 *  http://www.ugolnik.info
6 *  andrey@ugolnik.info
7 *
8 \**********************************************/
9 
10 #pragma once
11 
12 #include "format.h"
13 
14 #include <string>
15 
16 class cFile;
17 struct IcoDirentry;
18 
19 class cFormatIco final : public cFormat
20 {
21 public:
22     explicit cFormatIco(iCallbacks* callbacks);
23     ~cFormatIco();
24 
25     bool isSupported(cFile& file, Buffer& buffer) const override;
26 
27 private:
28     virtual bool LoadImpl(const char* filename, sBitmapDescription& desc) override;
29     virtual bool LoadSubImageImpl(unsigned current, sBitmapDescription& desc) override;
30 
31 private:
32     bool load(uint32_t current, sBitmapDescription& desc);
33     bool loadOrdinaryFrame(sBitmapDescription& desc, cFile& file, const IcoDirentry* image);
34     bool loadPngFrame(sBitmapDescription& desc, cFile& file, const IcoDirentry* image);
35     int calcIcoPitch(uint32_t bppImage, uint32_t width);
36     uint32_t getBit(const uint8_t* data, uint32_t bit, uint32_t width);
37     uint32_t getNibble(const uint8_t* data, uint32_t nibble, uint32_t width);
38     uint32_t getByte(const uint8_t* data, uint32_t byte, uint32_t width);
39 
40 private:
41     std::string m_filename;
42 };
43