DecodePNG.h
1 /*
2 
3 Copyright (c) 2018, Johnathan Corkery. (jcorkery@umich.edu)
4 All rights reserved.
5 
6 This file is part of the Dynacoe project (https://github.com/jcorks/Dynacoe)
7 Dynacoe was released under the MIT License, as detailed below.
8 
9 
10 
11 Permission is hereby granted, free of charge, to any person obtaining a copy
12 of this software and associated documentation files (the "Software"), to deal
13 in the Software without restriction, including without limitation the rights
14 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 copies of the Software, and to permit persons to whom the Software is furnished
16 to do so, subject to the following conditions:
17 
18 The above copyright notice and this permission notice shall
19 be 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 NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 DEALINGS IN THE SOFTWARE.
28 
29 
30 
31 */
32 
33 #ifndef H_DC_DECODE_PNG
34 #define H_DC_DECODE_PNG
35 
36 #include <Dynacoe/Decoders/Decoder.h>
37 
38 
39 /* Legacy decoder. Handles CIM, PNG, and BMP image reading */
40 namespace Dynacoe {
41 class DecodePNG : public Decoder{
42  public:
43  DecodePNG() : Decoder(Assets::Type::Image, std::vector<std::string>{"png"}){}
44 
45  Asset * operator()(
46  const std::string & name,
47  const std::string & extension,
48  const uint8_t * buffer,
49  uint64_t size
50  );
51 
52 
53 
54  private:
55 
56  /* Image storage */
57 
58  // IS MY UNCOMPRESSED IMAGE WELL-FORMED?
59  // Well, to be well-formed, it must have the following properties:
60  // -always RGBA, (4-component unsigned byte)
61  // -size of frame is always w * h * 4, any padding will be done internally by renderer
62  // -numFrames, w ,h are always positive
63  // -frames and frame data are accessible
64  // -frames is dynamically allocated as an array (new[])
65  // -frame data is dynamically allocated as an array
66  struct UncompressedFrame {
67  uint8_t * data;
68  };
69 
70  struct UncompressedImage {
71  UncompressedFrame * frames;
72  int numFrames;
73  int w;
74  int h;
75  };
76  /* Uncomp'd Image Utils */
77  // must have space for 32-bit image allocated already
78  void expandFromRGBtoRGBA(uint8_t *&, int size) ;
79  void convertFromBGRAtoRGBA(uint8_t *&, int size) ;
80 
81 
82  // get ridda that Uncomp'd image
83  void disposeOf(UncompressedImage *& img);
84  // make a well-formed Image instance.
85  // This requires interaction with the renderer
86  void makeImage(UncompressedImage * src, Image *& out, const std::string &);
87  // transforms each frame of the original image to
88  // be a series of miniature frames with a width and
89  // height given by the sub division of w and height with
90  // the number of slices given
91  void makeTileset(UncompressedImage *&, int xDiv, int yDiv);
92 
93 
94  // Uncompressed images and frames are only allocated by the designated uncompress fns
95  void uncompressPNG(const std::string &, const uint8_t *, uint64_t, UncompressedImage *&);
96 };
97 }
98 
99 
100 
101 #endif
Definition: AssetID.h:37