"LodePNGTiny" (=>800% more Compact than libPNG)

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
KickinAezz
Posts: 328
Joined: Sun Jun 03, 2007 10:05 pm

"LodePNGTiny" (=>800% more Compact than libPNG)

Post by KickinAezz »

Source Page:
http://members.gamedev.net/lode/projects/LodePNG/

Could this be used with PSP's sdk?
I wish I could try this but... C++ isn't something I'm used to...

Code: Select all

#include <vector>

int decodePNG&#40;std&#58;&#58;vector<unsigned char>& out_image_32bit, unsigned long& image_width, unsigned long& image_height, const unsigned char* in_png, unsigned long in_size&#41;
&#123;
  // LodePNGTiny version 20070830
  // Copyright &#40;c&#41; 2005-2007 Lode Vandevenne
  //
  // This software is provided 'as-is', without any express or implied
  // warranty. In no event will the authors be held liable for any damages
  // arising from the use of this software.
  //
  // Permission is granted to anyone to use this software for any purpose,
  // including commercial applications, and to alter it and redistribute it
  // freely, subject to the following restrictions&#58;
  //
  //     1. The origin of this software must not be misrepresented; you must not
  //     claim that you wrote the original software. If you use this software
  //     in a product, an acknowledgment in the product documentation would be
  //     appreciated but is not required.
  //     2. Altered source versions must be plainly marked as such, and must not be
  //     misrepresented as being the original software.
  //     3. This notice may not be removed or altered from any source distribution.
  
  // LodePNGTiny is a PNG decoder in one C++ function. Needs header <vector> to compile.
  // Apologies for the compact code style, it's to make it tiny.
  
  static const unsigned long lengthbase&#91;29&#93; =  &#123;3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258&#125;;
  static const unsigned long lengthextra&#91;29&#93; = &#123;0,0,0,0,0,0,0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4,  4,  5,  5,  5,  5,  0&#125;;
  static const unsigned long distancebase&#91;30&#93; =  &#123;1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577&#125;;
  static const unsigned long distanceextra&#91;30&#93; = &#123;0,0,0,0,1,1,2, 2, 3, 3, 4, 4, 5, 5,  6,  6,  7,  7,  8,  8,   9,   9,  10,  10,  11,  11,  12,   12,   13,   13&#125;;
  static const unsigned long clcl&#91;19&#93; = &#123;16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15&#125;; //code length code lengths
  struct Zlib //nested functions for zlib decompression
  &#123;
    static unsigned long readBitFromStream&#40;size_t& bitp, const unsigned char* bits&#41; &#123; unsigned long result = &#40;bits&#91;bitp >> 3&#93; >> &#40;bitp & 0x7&#41;&#41; & 1; bitp++; return result;&#125;
    static unsigned long readBitsFromStream&#40;size_t& bitp, const unsigned char* bits, size_t nbits&#41;
    &#123;
      unsigned long result = 0;
      for&#40;size_t i = 0; i < nbits; i++&#41; result += &#40;readBitFromStream&#40;bitp, bits&#41;&#41; << i;
      return result;
    &#125;
    class HuffmanTree
    &#123;
      public&#58;
      int makeFromLengths&#40;const std&#58;&#58;vector<unsigned long>& bitlen, unsigned long maxbitlen&#41;
      &#123; //make tree given the lengths
        unsigned long numcodes = &#40;unsigned long&#41;&#40;bitlen.size&#40;&#41;&#41;, treepos = 0, nodefilled = 0;
        std&#58;&#58;vector<unsigned long> tree1d&#40;numcodes&#41;, blcount&#40;maxbitlen + 1, 0&#41;, nextcode&#40;maxbitlen + 1, 0&#41;;
        for&#40;unsigned long bits = 0; bits < numcodes; bits++&#41; blcount&#91;bitlen&#91;bits&#93;&#93;++; //count number of instances of each code length
        for&#40;unsigned long bits = 1; bits <= maxbitlen; bits++&#41; nextcode&#91;bits&#93; = &#40;nextcode&#91;bits - 1&#93; + blcount&#91;bits - 1&#93;&#41; << 1;
        for&#40;unsigned long n = 0; n < numcodes; n++&#41; if&#40;bitlen&#91;n&#93; != 0&#41; tree1d&#91;n&#93; = nextcode&#91;bitlen&#91;n&#93;&#93;++; //generate all the codes
        tree2d.clear&#40;&#41;; tree2d.resize&#40;numcodes * 2, 32767&#41;; //32767 here means the tree2d isn't filled there yet
        for&#40;unsigned long n = 0; n < numcodes; n++&#41; //the codes
        for&#40;unsigned long i = 0; i < bitlen&#91;n&#93;; i++&#41; //the bits for this code
        &#123;
          unsigned long bit = &#40;tree1d&#91;n&#93; >> &#40;bitlen&#91;n&#93; - i - 1&#41;&#41; & 1;
          if&#40;treepos > numcodes - 2&#41; return 55;
          if&#40;tree2d&#91;2 * treepos + bit&#93; == 32767&#41; //not yet filled in
          &#123;
            if&#40;i + 1 == bitlen&#91;n&#93;&#41; &#123; tree2d&#91;2 * treepos + bit&#93; = n; treepos = 0; &#125; //last bit
            else &#123; tree2d&#91;2 * treepos + bit&#93; = ++nodefilled + numcodes; treepos = nodefilled; &#125; //addresses are encoded as values > numcodes
          &#125;
          else treepos = tree2d&#91;2 * treepos + bit&#93; - numcodes; //subtract numcodes from address to get address value
        &#125;
        return 0;
      &#125;
      int decode&#40;bool& decoded, unsigned long& result, size_t& treepos, unsigned long bit&#41; const
      &#123; //Decodes a symbol from the tree
        unsigned long numcodes = &#40;unsigned long&#41;tree2d.size&#40;&#41; / 2;
        if&#40;treepos >= numcodes&#41; return 11; //error&#58; you appeared outside the codetree
        result = tree2d&#91;2 * treepos + bit&#93;;
        decoded = &#40;result < numcodes&#41;;
        treepos = decoded ? 0 &#58; result - numcodes;
        return 0;
      &#125;
      private&#58;
      std&#58;&#58;vector<unsigned long> tree2d; //2D representation of a huffman tree&#58; The one dimension is "0" or "1", the other contains all nodes and leaves of the tree.
    &#125;;
    class Inflator
    &#123;
      public&#58;
      int error;
      void inflate&#40;std&#58;&#58;vector<unsigned char>& out, const std&#58;&#58;vector<unsigned char>& in, size_t inpos = 0&#41;
      &#123;
        size_t bp = 0, pos = 0; //bit pointer and byte pointer
        error = 0;
        unsigned long BFINAL = 0;
        while&#40;!BFINAL && !error&#41;
        &#123;
          if&#40;bp >> 3 >= in.size&#40;&#41;&#41; &#123; error = 52; return; &#125; //error, bit pointer will jump past memory
          BFINAL = readBitFromStream&#40;bp, &in&#91;inpos&#93;&#41;;
          unsigned long BTYPE = readBitFromStream&#40;bp, &in&#91;inpos&#93;&#41;; BTYPE += 2 * readBitFromStream&#40;bp, &in&#91;inpos&#93;&#41;;
          if&#40;BTYPE == 3&#41; &#123; error = 20; return; &#125; //error&#58; invalid BTYPE
          else if&#40;BTYPE == 0&#41; inflateNoCompression&#40;out, &in&#91;inpos&#93;, bp, pos, in.size&#40;&#41;&#41;;
          else inflateHuffmanBlock&#40;out, &in&#91;inpos&#93;, bp, pos, in.size&#40;&#41;, BTYPE&#41;;
        &#125;
        if&#40;!error&#41; out.resize&#40;pos&#41;; //Only now we know the true size of out, resize it to that
      &#125;
      private&#58;
      void generateFixedTrees&#40;HuffmanTree& tree, HuffmanTree& treeD&#41; //get the tree of a deflated block with fixed tree
      &#123;
        std&#58;&#58;vector<unsigned long> bitlen&#40;288, 8&#41;, bitlenD&#40;32, 5&#41;;;
        for&#40;size_t i = 144; i <= 255; i++&#41; bitlen&#91;i&#93; = 9;
        for&#40;size_t i = 256; i <= 279; i++&#41; bitlen&#91;i&#93; = 7;
        tree.makeFromLengths&#40;bitlen, 15&#41;;
        treeD.makeFromLengths&#40;bitlenD, 15&#41;;
      &#125;
      HuffmanTree codetree, codetreeD, codelengthcodetree; //the code tree for Huffman codes, distance codes, and code length codes
      unsigned long huffmanDecodeSymbol&#40;const unsigned char* in, size_t& bp, const HuffmanTree& codetree, size_t inlength&#41;
      &#123; //decode a single symbol from given list of bits with given code tree. return value is the symbol
        bool decoded; unsigned long ct;
        for&#40;size_t treepos = 0;;&#41;
        &#123;
          if&#40;&#40;bp & 0x07&#41; == 0 && &#40;bp >> 3&#41; > inlength&#41; &#123; error = 10; return 0; &#125; //error&#58; end reached without endcode
          error = codetree.decode&#40;decoded, ct, treepos, readBitFromStream&#40;bp, in&#41;&#41;; if&#40;error&#41; return 0; //stop, an error happened
          if&#40;decoded&#41; return ct;
      &#125; &#125;
      void getTreeInflateDynamic&#40;HuffmanTree& tree, HuffmanTree& treeD, const unsigned char* in, size_t& bp, size_t inlength&#41;
      &#123; //get the tree of a deflated block with dynamic tree, the tree itself is also Huffman compressed with a known tree
        std&#58;&#58;vector<unsigned long> bitlen&#40;288, 0&#41;, bitlenD&#40;32, 0&#41;;
        if&#40;bp >> 3 >= inlength - 2&#41; &#123; error = 49; return; &#125; //the bit pointer is or will go past the memory
        size_t HLIT =  readBitsFromStream&#40;bp, in, 5&#41; + 257; //number of literal/length codes + 257
        size_t HDIST = readBitsFromStream&#40;bp, in, 5&#41; + 1; //number of distance codes + 1
        size_t HCLEN = readBitsFromStream&#40;bp, in, 4&#41; + 4; //number of code length codes + 4
        std&#58;&#58;vector<unsigned long> codelengthcode&#40;19&#41;; //lengths of tree to decode the lengths of the dynamic tree
        for&#40;size_t i = 0; i < 19; i++&#41; codelengthcode&#91;clcl&#91;i&#93;&#93; = &#40;i < HCLEN&#41; ? readBitsFromStream&#40;bp, in, 3&#41; &#58; 0;
        error = codelengthcodetree.makeFromLengths&#40;codelengthcode, 7&#41;; if&#40;error&#41; return;
        size_t i = 0, replength;
        while&#40;i < HLIT + HDIST&#41;
        &#123;
          unsigned long code = huffmanDecodeSymbol&#40;in, bp, codelengthcodetree, inlength&#41;; if&#40;error&#41; return;
          if&#40;code <= 15&#41;  &#123; if&#40;i < HLIT&#41; bitlen&#91;i++&#93; = code; else bitlenD&#91;i++ - HLIT&#93; = code; &#125; //a length code
          else if&#40;code == 16&#41; //repeat previous
          &#123;
            if&#40;bp >> 3 >= inlength&#41; &#123; error = 50; return; &#125; //error, bit pointer jumps past memory
            replength = 3 + readBitsFromStream&#40;bp, in, 2&#41;;
            unsigned long value; //set value to the previous code
            if&#40;&#40;i - 1&#41; < HLIT&#41; value = bitlen&#91;i - 1&#93;;
            else value = bitlenD&#91;i - HLIT - 1&#93;;
            for&#40;size_t n = 0; n < replength; n++&#41; //repeat this value in the next lengths
            &#123;
              if&#40;i >= HLIT + HDIST&#41; &#123; error = 13; return; &#125; //error&#58; i is larger than the amount of codes
              if&#40;i < HLIT&#41; bitlen&#91;i++&#93; = value; else bitlenD&#91;i++ - HLIT&#93; = value;
            &#125;
          &#125;
          else if&#40;code == 17&#41; //repeat "0" 3-10 times
          &#123;
            if&#40;bp >> 3 >= inlength&#41; &#123; error = 50; return; &#125; //error, bit pointer jumps past memory
            replength = 3 + readBitsFromStream&#40;bp, in, 3&#41;;
            for&#40;size_t n = 0; n < replength; n++&#41; //repeat this value in the next lengths
            &#123;
              if&#40;i >= HLIT + HDIST&#41; &#123; error = 14; return; &#125; //error&#58; i is larger than the amount of codes
              if&#40;i < HLIT&#41; bitlen&#91;i++&#93; = 0; else bitlenD&#91;i++ - HLIT&#93; = 0;
          &#125; &#125;
          else if&#40;code == 18&#41; //repeat "0" 11-138 times
          &#123;
            if&#40;bp >> 3 >= inlength&#41; &#123; error = 50; return; &#125; //error, bit pointer jumps past memory
            replength = 11 + readBitsFromStream&#40;bp, in, 7&#41;;
            for&#40;size_t n = 0; n < replength; n++&#41; //repeat this value in the next lengths
            &#123;
              if&#40;i >= HLIT + HDIST&#41; &#123; error = 15; return; &#125; //error&#58; i is larger than the amount of codes
              if&#40;i < HLIT&#41; bitlen&#91;i++&#93; = 0; else bitlenD&#91;i++ - HLIT&#93; = 0;
          &#125; &#125;
          else &#123; error = 16; return; &#125; //error&#58; somehow an unexisting code appeared. This can never happen.
        &#125;
        if&#40;bitlen&#91;256&#93; == 0&#41; &#123; error = 64; return; &#125; //the length of the end code 256 must be larger than 0
        error = tree.makeFromLengths&#40;bitlen, 15&#41;; if&#40;error&#41; return; //now we've finally got HLIT and HDIST, so generate the code trees, and the function is done
        error = treeD.makeFromLengths&#40;bitlenD, 15&#41;; if&#40;error&#41; return;
      &#125;
      void inflateHuffmanBlock&#40;std&#58;&#58;vector<unsigned char>& out, const unsigned char* in, size_t& bp, size_t& pos, size_t inlength, unsigned long btype&#41; 
      &#123;
        if&#40;btype == 1&#41; &#123; generateFixedTrees&#40;codetree, codetreeD&#41;; &#125;
        else if&#40;btype == 2&#41; &#123; getTreeInflateDynamic&#40;codetree, codetreeD, in, bp, inlength&#41;; if&#40;error&#41; return; &#125;
        for&#40;;;&#41;
        &#123;
          unsigned long code = huffmanDecodeSymbol&#40;in, bp, codetree, inlength&#41;; if&#40;error&#41; return;
          if&#40;code == 256&#41; return; //end code
          else if&#40;code <= 255&#41; //literal symbol
          &#123;
            if&#40;pos >= out.size&#40;&#41;&#41; out.resize&#40;&#40;pos + 1&#41; * 2&#41;; //reserve more room
            out&#91;pos++&#93; = &#40;unsigned char&#41;&#40;code&#41;;
          &#125;
          else if&#40;code >= 257 && code <= 285&#41; //length code
          &#123;
            size_t length = lengthbase&#91;code - 257&#93;, numextrabits = lengthextra&#91;code - 257&#93;;
            if&#40;&#40;bp >> 3&#41; >= inlength&#41; &#123; error = 51; return; &#125; //error, bit pointer will jump past memory
            length += readBitsFromStream&#40;bp, in, numextrabits&#41;;
            unsigned long codeD = huffmanDecodeSymbol&#40;in, bp, codetreeD, inlength&#41;; if&#40;error&#41; return;
            if&#40;codeD > 29&#41; &#123; error = 18; return; &#125; //error&#58; invalid distance code &#40;30-31 are never used&#41;
            unsigned long distance = distancebase&#91;codeD&#93;, numextrabitsD = distanceextra&#91;codeD&#93;;
            if&#40;&#40;bp >> 3&#41; >= inlength&#41; &#123; error = 51; return; &#125; //error, bit pointer will jump past memory
            distance += readBitsFromStream&#40;bp, in, numextrabitsD&#41;;
            size_t start = pos, backward = start - distance;
            if&#40;pos + length >= out.size&#40;&#41;&#41; out.resize&#40;&#40;pos + length&#41; * 2&#41;; //reserve more room
            for&#40;size_t forward = 0; forward < length; forward++&#41;
            &#123;
              out&#91;pos++&#93; = out&#91;backward++&#93;;
              if&#40;backward >= start&#41; backward = start - distance;
      &#125; &#125; &#125; &#125;
      void inflateNoCompression&#40;std&#58;&#58;vector<unsigned char>& out, const unsigned char* in, size_t& bp, size_t& pos, size_t inlength&#41;
      &#123;
        while&#40;&#40;bp & 0x7&#41; != 0&#41; bp++; //go to first boundary of byte
        size_t p = bp / 8;
        if&#40;p >= inlength - 4&#41; &#123; error = 52; return; &#125; //error, bit pointer will jump past memory
        unsigned long LEN = in&#91;p&#93; + 256 * in&#91;p + 1&#93;, NLEN = in&#91;p + 2&#93; + 256 * in&#91;p + 3&#93;; p += 4;
        if&#40;LEN + NLEN != 65535&#41; &#123; error = 21; return; &#125; //error&#58; NLEN is not one's complement of LEN
        if&#40;pos + LEN >= out.size&#40;&#41;&#41; out.resize&#40;pos + LEN&#41;;
        if&#40;p + LEN > inlength&#41; &#123; error = 23; return; &#125; //error&#58; reading outside of in buffer
        for&#40;unsigned long n = 0; n < LEN; n++&#41; out&#91;pos++&#93; = in&#91;p++&#93;; //read LEN bytes of literal data
        bp = p * 8;
      &#125;
    &#125;;
    int decompress&#40;std&#58;&#58;vector<unsigned char>& out, const std&#58;&#58;vector<unsigned char>& in&#41; //returns error value
    &#123;
      Inflator inflator;
      if&#40;in.size&#40;&#41; < 2&#41; &#123; return 53; &#125; //error, size of zlib data too small
      if&#40;&#40;in&#91;0&#93; * 256 + in&#91;1&#93;&#41; % 31 != 0&#41; &#123; return 24; &#125; //error&#58; 256 * in&#91;0&#93; + in&#91;1&#93; must be a multiple of 31, the FCHECK value is supposed to be made that way
      unsigned long CM = in&#91;0&#93; & 15, CINFO = &#40;in&#91;0&#93; >> 4&#41; & 15, FDICT = &#40;in&#91;1&#93; >> 5&#41; & 1;
      if&#40;CM != 8 || CINFO > 7&#41; &#123; return 25; &#125; //error&#58; only compression method 8&#58; inflate with sliding window of 32k is supported by the PNG spec
      if&#40;FDICT != 0&#41; &#123; return 26; &#125; //error&#58; the specification of PNG says about the zlib stream&#58; "The additional flags shall not specify a preset dictionary."
      inflator.inflate&#40;out, in, 2&#41;;
      return inflator.error; //note&#58; adler32 checksum was skipped and ignored
    &#125;
  &#125;;
  struct PNG //nested functions for PNG decoding
  &#123;
    struct Info
    &#123;
      unsigned long width, height, colorType, bitDepth, compressionMethod, filterMethod, interlaceMethod, key_r, key_g, key_b;
      bool key_defined; //is a transparent color key given?
      std&#58;&#58;vector<unsigned char> palette;
    &#125; info;
    int error;
    void decode&#40;std&#58;&#58;vector<unsigned char>& out, const unsigned char* in, unsigned long size&#41;
    &#123;
      error = 0; //in the beginning there is no error
      if&#40;size == 0 || in == 0&#41; &#123; error = 48; return; &#125; //the given data is empty
      readPngHeader&#40;&in&#91;0&#93;, size&#41;; if&#40;error&#41; return;
      size_t pos = 33; //first byte of the first chunk after the header
      std&#58;&#58;vector<unsigned char> idat; //the data from idat chunks
      bool IEND = false, known_type = true;
      info.key_defined = false;
      while&#40;!IEND&#41; //loop through the chunks, ignoring unknown chunks and stopping at IEND chunk. IDAT data is put at the start of the in buffer
      &#123;
        if&#40;pos + 8 >= size&#41; &#123; error = 30; return; &#125; //error&#58; size of the in buffer too small to contain next chunk
        size_t chunkLength = read32bitInt&#40;&in&#91;pos&#93;&#41;; pos += 4;
        if&#40;chunkLength > 2147483647&#41; &#123; error = 63; return; &#125;
        if&#40;pos + chunkLength >= size&#41; &#123; error = 35; return; &#125; //error&#58; size of the in buffer too small to contain next chunk

        if&#40;in&#91;pos + 0&#93; == 'I' && in&#91;pos + 1&#93; == 'D' && in&#91;pos + 2&#93; == 'A' && in&#91;pos + 3&#93; == 'T'&#41; //IDAT chunk, containing compressed image data
        &#123;
          idat.insert&#40;idat.end&#40;&#41;, &in&#91;pos + 4&#93;, &in&#91;pos + 4 + chunkLength&#93;&#41;;
          pos += &#40;4 + chunkLength&#41;;
        &#125;
        else if&#40;in&#91;pos + 0&#93; == 'I' && in&#91;pos + 1&#93; == 'E' && in&#91;pos + 2&#93; == 'N' && in&#91;pos + 3&#93; == 'D'&#41;  &#123; pos += 4; IEND = true; &#125;
        else if&#40;in&#91;pos + 0&#93; == 'P' && in&#91;pos + 1&#93; == 'L' && in&#91;pos + 2&#93; == 'T' && in&#91;pos + 3&#93; == 'E'&#41; //palette chunk &#40;PLTE&#41;
        &#123;
          pos += 4; //go after the 4 letters
          info.palette.resize&#40;4 * &#40;chunkLength / 3&#41;&#41;;
          if&#40;info.palette.size&#40;&#41; > &#40;4 * 256&#41;&#41; &#123; error = 38; return; &#125; //error&#58; palette too big
          for&#40;size_t i = 0; i < info.palette.size&#40;&#41;; i += 4&#41;
          &#123;
            for&#40;size_t j = 0; j < 3; j++&#41; info.palette&#91;i + j&#93; = in&#91;pos++&#93;; //RGB
            info.palette&#91;i + 3&#93; = 255; //alpha
        &#125; &#125;
        else if&#40;in&#91;pos + 0&#93; == 't' && in&#91;pos + 1&#93; == 'R' && in&#91;pos + 2&#93; == 'N' && in&#91;pos + 3&#93; == 'S'&#41; //palette transparency chunk &#40;tRNS&#41;
        &#123;
          pos += 4; //go after the 4 letters
          if&#40;info.colorType == 3&#41;
          &#123;
            if&#40;4 * chunkLength > info.palette.size&#40;&#41;&#41; &#123; error = 39; return; &#125; //error&#58; more alpha values given than there are palette entries
            for&#40;size_t i = 0; i < chunkLength; i++&#41; info.palette&#91;4 * i + 3&#93; = in&#91;pos++&#93;;
          &#125;
          else if&#40;info.colorType == 0&#41;
          &#123;
            if&#40;chunkLength != 2&#41; &#123; error = 40; return; &#125; //error&#58; this chunk must be 2 bytes for greyscale image
            info.key_defined = 1; info.key_r = info.key_g = info.key_b = 256 * in&#91;pos&#93; + in&#91;pos + 1&#93;; pos += 2;
          &#125;
          else if&#40;info.colorType == 2&#41;
          &#123;
            if&#40;chunkLength != 6&#41; &#123; error = 41; return; &#125; //error&#58; this chunk must be 6 bytes for RGB image
            info.key_defined = 1;
            info.key_r = 256 * in&#91;pos&#93; + in&#91;pos + 1&#93;; pos += 2;
            info.key_g = 256 * in&#91;pos&#93; + in&#91;pos + 1&#93;; pos += 2;
            info.key_b = 256 * in&#91;pos&#93; + in&#91;pos + 1&#93;; pos += 2;
          &#125;
          else &#123; error = 42; return; &#125; //error&#58; tRNS chunk not allowed for other color models
        &#125;
        else //it's not an implemented chunk type, so ignore it&#58; skip over the data
        &#123;
          if&#40;!&#40;in&#91;pos + 0&#93; & 32&#41;&#41; &#123; error = 69; return; &#125; //error&#58; unknown critical chunk &#40;5th bit of first byte of chunk type is 0&#41;
          pos += &#40;chunkLength + 4&#41;; //skip 4 letters and uninterpreted data of unimplemented chunk
          known_type = false;
        &#125;
        pos += 4; //step over CRC &#40;which is ignored&#41;
      &#125;
      unsigned long bpp = getBpp&#40;info&#41;;
      std&#58;&#58;vector<unsigned char> scanlines&#40;&#40;&#40;info.width * &#40;info.height * bpp + 7&#41;&#41; / 8&#41; + info.height&#41;; //now the out buffer will be filled
      Zlib zlib; //decompress with the Zlib decompressor
      error = zlib.decompress&#40;scanlines, idat&#41;; if&#40;error&#41; return; //stop if the zlib decompressor returned an error
      size_t bytewidth = &#40;bpp + 7&#41; / 8, outlength = &#40;info.height * info.width * bpp + 7&#41; / 8;
      out.resize&#40;outlength&#41;; //time to fill the out buffer
      unsigned char* out_ = outlength ? &out&#91;0&#93; &#58; 0; //use a regular pointer to the std&#58;&#58;vector for faster code if compiled without optimization
      if&#40;info.interlaceMethod == 0&#41; //no interlace, just filter
      &#123;
        size_t linestart = 0, linelength = &#40;info.width * bpp + 7&#41; / 8; //length in bytes of a scanline, excluding the filtertype byte
        if&#40;bpp >= 8&#41; //byte per byte
        for&#40;unsigned long y = 0; y < info.height; y++&#41;
        &#123;
          unsigned long filterType = scanlines&#91;linestart&#93;;
          const unsigned char* prevline = &#40;y == 0&#41; ? 0 &#58; &out_&#91;&#40;y - 1&#41; * info.width * bytewidth&#93;;
          unFilterScanline&#40;&out_&#91;linestart - y&#93;, &scanlines&#91;linestart + 1&#93;, prevline, bytewidth, filterType,  linelength&#41;; if&#40;error&#41; return;
          linestart += &#40;1 + linelength&#41;; //go to start of next scanline
        &#125;
        else //less than 8 bits per pixel, so fill it up bit per bit
        &#123;
          std&#58;&#58;vector<unsigned char> templine&#40;&#40;info.width * bpp + 7&#41; >> 3&#41;; //only used if bpp < 8
          for&#40;size_t y = 0, obp = 0; y < info.height; y++&#41;
          &#123;
            unsigned long filterType = scanlines&#91;linestart&#93;;
            const unsigned char* prevline = &#40;y == 0&#41; ? 0 &#58; &out_&#91;&#40;y - 1&#41; * info.width * bytewidth&#93;;
            unFilterScanline&#40;&templine&#91;0&#93;, &scanlines&#91;linestart + 1&#93;, prevline, bytewidth, filterType, linelength&#41;; if&#40;error&#41; return;
            for&#40;size_t bp = 0; bp < info.width * bpp;&#41; setBitOfReversedStream&#40;obp, out_, readBitFromReversedStream&#40;bp, &templine&#91;0&#93;&#41;&#41;;
            linestart += &#40;1 + linelength&#41;; //go to start of next scanline
      &#125; &#125; &#125;
      else //interlaceMethod is 1 &#40;Adam7&#41;
      &#123;
        size_t passw&#91;7&#93; = &#123; &#40;info.width + 7&#41; / 8, &#40;info.width + 3&#41; / 8, &#40;info.width + 3&#41; / 4, &#40;info.width + 1&#41; / 4, &#40;info.width + 1&#41; / 2, &#40;info.width + 0&#41; / 2, &#40;info.width + 0&#41; / 1 &#125;;
        size_t passh&#91;7&#93; = &#123; &#40;info.height + 7&#41; / 8, &#40;info.height + 7&#41; / 8, &#40;info.height + 3&#41; / 8, &#40;info.height + 3&#41; / 4, &#40;info.height + 1&#41; / 4, &#40;info.height + 1&#41; / 2, &#40;info.height + 0&#41; / 2 &#125;;
        size_t passstart&#91;7&#93; = &#123;0&#125;;
        size_t pattern&#91;28&#93; = &#123;0, 4, 0, 2, 0, 1, 0, 0, 0, 4, 0, 2, 0, 1, 8, 8, 4, 4, 2, 2, 1, 8, 8, 8, 4, 4, 2, 2&#125;; //values for the adam7 passes
        for&#40;int i = 0; i < 6; i++&#41; passstart&#91;i + 1&#93; = passstart&#91;i&#93; + passh&#91;i&#93; * &#40;&#40;passw&#91;i&#93; ? 1 &#58; 0&#41; + &#40;passw&#91;i&#93; * bpp + 7&#41; / 8&#41;;
        std&#58;&#58;vector<unsigned char> scanlineo&#40;&#40;info.width * bpp + 7&#41; / 8&#41;, scanlinen&#40;&#40;info.width * bpp + 7&#41; / 8&#41;; //"old" and "new" scanline
        for&#40;int i = 0; i < 7; i++&#41;
          adam7Pass&#40;&out_&#91;0&#93;, &scanlinen&#91;0&#93;, &scanlineo&#91;0&#93;, &scanlines&#91;passstart&#91;i&#93;&#93;, info.width, pattern&#91;i&#93;, pattern&#91;i + 7&#93;, pattern&#91;i + 14&#93;, pattern&#91;i + 21&#93;, passw&#91;i&#93;, passh&#91;i&#93;, bpp&#41;;
      &#125;
      if&#40;info.colorType != 6 || info.bitDepth != 8&#41; //conversion needed
      &#123;
        std&#58;&#58;vector<unsigned char> data = out;
        error = convert&#40;out, &data&#91;0&#93;, info, info.width, info.height&#41;;
    &#125; &#125;
    private&#58;
    void readPngHeader&#40;const unsigned char* in, size_t inlength&#41; //read the information from the header and store it in the Info
    &#123;
      if&#40;inlength < 29&#41; &#123; error = 27; return; &#125; //error&#58; the data length is smaller than the length of the header
      if&#40;in&#91;0&#93; != 137 || in&#91;1&#93; != 80 || in&#91;2&#93; != 78 || in&#91;3&#93; != 71 || in&#91;4&#93; != 13 || in&#91;5&#93; != 10 || in&#91;6&#93; != 26 || in&#91;7&#93; != 10&#41; &#123; error = 28; return; &#125; //no PNG signature
      if&#40;in&#91;12&#93; != 'I' || in&#91;13&#93; != 'H' || in&#91;14&#93; != 'D' || in&#91;15&#93; != 'R'&#41; &#123; error = 29; return; &#125; //error&#58; it doesn't start with a IHDR chunk!
      info.width = read32bitInt&#40;&in&#91;16&#93;&#41;; info.height = read32bitInt&#40;&in&#91;20&#93;&#41;;
      info.bitDepth = in&#91;24&#93;; info.colorType = in&#91;25&#93;;
      info.compressionMethod = in&#91;26&#93;; if&#40;in&#91;26&#93; != 0&#41; &#123; error = 32; return; &#125; //error&#58; only compression method 0 is allowed in the specification
      info.filterMethod = in&#91;27&#93;; if&#40;in&#91;27&#93; != 0&#41; &#123; error = 33; return; &#125; //error&#58; only filter method 0 is allowed in the specification
      info.interlaceMethod = in&#91;28&#93;; if&#40;in&#91;28&#93; > 1&#41; &#123; error = 34; return; &#125; //error&#58; only interlace methods 0 and 1 exist in the specification
      error = checkColorValidity&#40;info.colorType, info.bitDepth&#41;;
    &#125;
    void unFilterScanline&#40;unsigned char* recon, const unsigned char* scanline, const unsigned char* precon, size_t bytewidth, unsigned long filterType, size_t length&#41;
    &#123;
      switch&#40;filterType&#41;
      &#123;
        case 0&#58; for&#40;size_t i = 0; i < length; i++&#41; recon&#91;i&#93; = scanline&#91;i&#93;; break;
        case 1&#58;
          for&#40;size_t i =         0; i < bytewidth; i++&#41; recon&#91;i&#93; = scanline&#91;i&#93;;
          for&#40;size_t i = bytewidth; i <    length; i++&#41; recon&#91;i&#93; = scanline&#91;i&#93; + recon&#91;i - bytewidth&#93;;
          break;
        case 2&#58; 
          if&#40;precon&#41; for&#40;size_t i = 0; i < length; i++&#41; recon&#91;i&#93; = scanline&#91;i&#93; + precon&#91;i&#93;;
          else       for&#40;size_t i = 0; i < length; i++&#41; recon&#91;i&#93; = scanline&#91;i&#93;;
          break;
        case 3&#58;
          if&#40;precon&#41;
          &#123;
            for&#40;size_t i =         0; i < bytewidth; i++&#41; recon&#91;i&#93; = scanline&#91;i&#93; + precon&#91;i&#93; / 2;
            for&#40;size_t i = bytewidth; i <    length; i++&#41; recon&#91;i&#93; = scanline&#91;i&#93; + &#40;&#40;recon&#91;i - bytewidth&#93; + precon&#91;i&#93;&#41; / 2&#41;;
          &#125;
          else
          &#123;
            for&#40;size_t i =         0; i < bytewidth; i++&#41; recon&#91;i&#93; = scanline&#91;i&#93;;
            for&#40;size_t i = bytewidth; i <    length; i++&#41; recon&#91;i&#93; = scanline&#91;i&#93; + recon&#91;i - bytewidth&#93; / 2;
          &#125;
          break;
        case 4&#58;
          if&#40;precon&#41;
          &#123;
            for&#40;size_t i =         0; i < bytewidth; i++&#41; recon&#91;i&#93; = &#40;unsigned char&#41;&#40;scanline&#91;i&#93; + paethPredictor&#40;0, precon&#91;i&#93;, 0&#41;&#41;;
            for&#40;size_t i = bytewidth; i <    length; i++&#41; recon&#91;i&#93; = &#40;unsigned char&#41;&#40;scanline&#91;i&#93; + paethPredictor&#40;recon&#91;i - bytewidth&#93;, precon&#91;i&#93;, precon&#91;i - bytewidth&#93;&#41;&#41;;
          &#125;
          else
          &#123;
            for&#40;size_t i =         0; i < bytewidth; i++&#41; recon&#91;i&#93; = scanline&#91;i&#93;;
            for&#40;size_t i = bytewidth; i <    length; i++&#41; recon&#91;i&#93; = &#40;unsigned char&#41;&#40;scanline&#91;i&#93; + paethPredictor&#40;recon&#91;i - bytewidth&#93;, 0, 0&#41;&#41;;
          &#125;
          break;
        default&#58; error = 36; return; //error&#58; unexisting filter type given
    &#125; &#125;
    void adam7Pass&#40;unsigned char* out, unsigned char* linen, unsigned char* lineo, const unsigned char* in, unsigned long w, size_t passleft, size_t passtop, size_t spacex, size_t spacey, size_t passw, size_t passh, unsigned long bpp&#41;
    &#123; //filter and reposition the pixels into the output when the image is Adam7 interlaced. This function can only do it after the full image is already decoded. The out buffer must have the correct allocated memory size already.
      if&#40;passw == 0&#41; return;
      size_t bytewidth = &#40;bpp + 7&#41; / 8, linelength = 1 + &#40;&#40;bpp * passw + 7&#41; / 8&#41;;
      for&#40;unsigned long y = 0; y < passh; y++&#41;
      &#123;
        unsigned char filterType = in&#91;y * linelength&#93;, *prevline = &#40;y == 0&#41; ? 0 &#58; lineo;
        unFilterScanline&#40;linen, &in&#91;y * linelength + 1&#93;, prevline, bytewidth, filterType, &#40;w * bpp + 7&#41; / 8&#41;; if&#40;error&#41; return;
        if&#40;bpp >= 8&#41; for&#40;size_t i = 0; i < passw; i++&#41; for&#40;size_t b = 0; b < bytewidth; b++&#41; //b = current byte of this pixel
          out&#91;bytewidth * w * &#40;passtop + spacey * y&#41; + bytewidth * &#40;passleft + spacex * i&#41; + b&#93; = linen&#91;bytewidth * i + b&#93;;
        else for&#40;size_t i = 0; i < passw; i++&#41;
        &#123;
          size_t obp = bpp * w * &#40;passtop + spacey * y&#41; + bpp * &#40;passleft + spacex * i&#41;, bp = i * bpp;
          for&#40;size_t b = 0; b < bpp; b++&#41; setBitOfReversedStream&#40;obp, out, readBitFromReversedStream&#40;bp, &linen&#91;0&#93;&#41;&#41;;
        &#125;
        unsigned char* temp = linen; linen = lineo; lineo = temp; //swap the two buffer pointers "line old" and "line new"
    &#125; &#125;
    static unsigned long readBitFromReversedStream&#40;size_t& bitp, const unsigned char* bits&#41; &#123; unsigned long result = &#40;bits&#91;bitp >> 3&#93; >> &#40;7 - bitp & 0x7&#41;&#41; & 1; bitp++; return result;&#125;
    static unsigned long readBitsFromReversedStream&#40;size_t& bitp, const unsigned char* bits, unsigned long nbits&#41;
    &#123;
      unsigned long result = 0;
      for&#40;size_t i = nbits - 1; i < nbits; i--&#41; result += &#40;&#40;readBitFromReversedStream&#40;bitp, bits&#41;&#41; << i&#41;;
      return result;
    &#125;
    void setBitOfReversedStream&#40;size_t& bitp, unsigned char* bits, unsigned long bit&#41; &#123; bits&#91;bitp >> 3&#93; |=  &#40;bit << &#40;7 - bitp & 0x7&#41;&#41;; bitp++; &#125;
    unsigned long read32bitInt&#40;const unsigned char* buffer&#41; &#123; return &#40;buffer&#91;0&#93; << 24&#41; | &#40;buffer&#91;1&#93; << 16&#41; | &#40;buffer&#91;2&#93; << 8&#41; | buffer&#91;3&#93;; &#125;
    int checkColorValidity&#40;unsigned long colorType, unsigned long bd&#41; //return type is a LodePNG error code
    &#123;
      if&#40;&#40;colorType == 2 || colorType == 4 || colorType == 6&#41;&#41; if&#40;!&#40;bd == 8 || bd == 16&#41;&#41; return 37;
      else if&#40;colorType == 0&#41; if&#40;!&#40;bd == 1 || bd == 2 || bd == 4 || bd == 8 || bd == 16&#41;&#41; return 37;
      else if&#40;colorType == 3&#41; if&#40;!&#40;bd == 1 || bd == 2 || bd == 4 || bd == 8            &#41;&#41; return 37;
      else return 31; //unexisting color type
      return 0; //allowed color type / bits combination
    &#125;
    unsigned long getBpp&#40;const Info& info&#41;
    &#123;
      if&#40;info.colorType == 2&#41; return &#40;3 * info.bitDepth&#41;;
      else if&#40;info.colorType >= 4&#41; return &#40;info.colorType - 2&#41; * info.bitDepth;
      else return info.bitDepth;
    &#125;
    int convert&#40;std&#58;&#58;vector<unsigned char>& out, const unsigned char* in, Info& infoIn, unsigned long w, unsigned long h&#41;
    &#123; //converts from any color type to 32-bit. return value = LodePNG error code
      size_t numpixels = w * h, bp = 0;
      out.resize&#40;numpixels * 4&#41;;
      unsigned char* out_ = out.empty&#40;&#41; ? 0 &#58; &out&#91;0&#93;; //faster if compiled without optimization
      if&#40;infoIn.bitDepth == 8 && infoIn.colorType == 0&#41; //greyscale
      for&#40;size_t i = 0; i < numpixels; i++&#41;
      &#123;
        out_&#91;4 * i + 0&#93; = out_&#91;4 * i + 1&#93; = out_&#91;4 * i + 2&#93; = in&#91;i&#93;;
        out_&#91;4 * i + 3&#93; = &#40;infoIn.key_defined && in&#91;i&#93; == infoIn.key_r&#41; ? 0 &#58; 255;
      &#125;
      else if&#40;infoIn.bitDepth == 8 && infoIn.colorType == 2&#41; //RGB color
      for&#40;size_t i = 0; i < numpixels; i++&#41;
      &#123;
        for&#40;size_t c = 0; c < 3; c++&#41; out_&#91;4 * i + c&#93; = in&#91;3 * i + c&#93;;
        out_&#91;4 * i + 3&#93; = &#40;infoIn.key_defined == 1 && in&#91;3 * i + 0&#93; == infoIn.key_r && in&#91;3 * i + 1&#93; == infoIn.key_g && in&#91;3 * i + 2&#93; == infoIn.key_b&#41; ? 0 &#58; 255;
      &#125;
      else if&#40;infoIn.bitDepth == 8 && infoIn.colorType == 3&#41; //indexed color &#40;palette&#41;
      for&#40;size_t i = 0; i < numpixels; i++&#41;
      &#123;
        if&#40;4U * in&#91;i&#93; >= infoIn.palette.size&#40;&#41;&#41; return 46;
        for&#40;size_t c = 0; c < 4; c++&#41; out_&#91;4 * i + c&#93; = infoIn.palette&#91;4 * in&#91;i&#93; + c&#93;; //get rgb colors from the palette
      &#125;
      else if&#40;infoIn.bitDepth == 8 && infoIn.colorType == 4&#41; //greyscale with alpha
      for&#40;size_t i = 0; i < numpixels; i++&#41;
      &#123;
        out_&#91;4 * i + 0&#93; = out_&#91;4 * i + 1&#93; = out_&#91;4 * i + 2&#93; = in&#91;2 * i + 0&#93;;
        out_&#91;4 * i + 3&#93; = in&#91;2 * i + 1&#93;;
      &#125;
      else if&#40;infoIn.bitDepth == 8 && infoIn.colorType == 6&#41; for&#40;size_t i = 0; i < numpixels; i++&#41; for&#40;size_t c = 0; c < 4; c++&#41; out_&#91;4 * i + c&#93; = in&#91;4 * i + c&#93;; //RGB with alpha
      else if&#40;infoIn.bitDepth == 16 && infoIn.colorType == 0&#41; //greyscale
      for&#40;size_t i = 0; i < numpixels; i++&#41;
      &#123;
        out_&#91;4 * i + 0&#93; = out_&#91;4 * i + 1&#93; = out_&#91;4 * i + 2&#93; = in&#91;2 * i&#93;;
        out_&#91;4 * i + 3&#93; = &#40;infoIn.key_defined && 256U * in&#91;i&#93; + in&#91;i + 1&#93; == infoIn.key_r&#41; ? 0 &#58; 255;
      &#125;
      else if&#40;infoIn.bitDepth == 16 && infoIn.colorType == 2&#41; //RGB color
      for&#40;size_t i = 0; i < numpixels; i++&#41;
      &#123;
        for&#40;size_t c = 0; c < 3; c++&#41; out_&#91;4 * i + c&#93; = in&#91;6 * i + 2 * c&#93;;
        out_&#91;4 * i + 3&#93; = &#40;infoIn.key_defined && 256U*in&#91;6*i+0&#93;+in&#91;6*i+1&#93; == infoIn.key_r && 256U*in&#91;6*i+2&#93;+in&#91;6*i+3&#93; == infoIn.key_g && 256U*in&#91;6*i+4&#93;+in&#91;6*i+5&#93; == infoIn.key_b&#41; ? 0 &#58; 255;
      &#125;
      else if&#40;infoIn.bitDepth == 16 && infoIn.colorType == 4&#41; //greyscale with alpha
      for&#40;size_t i = 0; i < numpixels; i++&#41;
      &#123;
        out_&#91;4 * i + 0&#93; = out_&#91;4 * i + 1&#93; = out_&#91;4 * i + 2&#93; = in&#91;4 * i&#93;; //most significant byte
        out_&#91;4 * i + 3&#93; = in&#91;4 * i + 2&#93;;
      &#125;
      else if&#40;infoIn.bitDepth == 16 && infoIn.colorType == 6&#41; for&#40;size_t i = 0; i < numpixels; i++&#41; for&#40;size_t c = 0; c < 4; c++&#41; out_&#91;4 * i + c&#93; = in&#91;8 * i + 2 * c&#93;; //RGB with alpha
      else if&#40;infoIn.bitDepth < 8 && infoIn.colorType == 0&#41; //greyscale
      for&#40;size_t i = 0; i < numpixels; i++&#41;
      &#123;
        unsigned long value = &#40;readBitsFromReversedStream&#40;bp, in, infoIn.bitDepth&#41; * 255&#41; / &#40;&#40;1 << infoIn.bitDepth&#41; - 1&#41;; //scale value from 0 to 255
        out_&#91;4 * i + 0&#93; = out_&#91;4 * i + 1&#93; = out_&#91;4 * i + 2&#93; = &#40;unsigned char&#41;&#40;value&#41;;
        out_&#91;4 * i + 3&#93; = &#40;infoIn.key_defined && value && &#40;&#40;1U << infoIn.bitDepth&#41; - 1U&#41; == infoIn.key_r && &#40;&#40;1U << infoIn.bitDepth&#41; - 1U&#41;&#41; ? 0 &#58; 255;
      &#125;
      else if&#40;infoIn.bitDepth < 8 && infoIn.colorType == 3&#41; //palette
      for&#40;size_t i = 0; i < numpixels; i++&#41;
      &#123;
        unsigned long value = readBitsFromReversedStream&#40;bp, in, infoIn.bitDepth&#41;;
        if&#40;4 * value >= infoIn.palette.size&#40;&#41;&#41; return 47;
        for&#40;size_t c = 0; c < 4; c++&#41; out_&#91;4 * i + c&#93; = infoIn.palette&#91;4 * value + c&#93;; //get rgb colors from the palette
      &#125;
      return 0;
    &#125;
    long paethPredictor&#40;long a, long b, long c&#41; //Paeth predicter, used by PNG filter type 4
    &#123;
      long p = a + b - c, pa = p > a ? p - a &#58; a - p, pb = p > b ? p - b &#58; b - p, pc = p > c ? p - c &#58; c - p;
      return &#40;pa <= pb && pa <= pc&#41; ? a &#58; pb <= pc ? b &#58; c;
    &#125;
  &#125;;
  PNG decoder; decoder.decode&#40;out_image_32bit, in_png, in_size&#41;;
  image_width = decoder.info.width; image_height = decoder.info.height;
  return decoder.error;
&#125;





//an example using the PNG loading function&#58;

#include <iostream>
#include <fstream>

void loadFile&#40;std&#58;&#58;vector<unsigned char>& buffer, const std&#58;&#58;string& filename&#41; //designed for loading files from hard disk in an std&#58;&#58;vector
&#123;
  std&#58;&#58;ifstream file&#40;filename.c_str&#40;&#41;, std&#58;&#58;ios&#58;&#58;in|std&#58;&#58;ios&#58;&#58;binary|std&#58;&#58;ios&#58;&#58;ate&#41;;

  //get filesize
  std&#58;&#58;streamsize size = 0;
  if&#40;file.seekg&#40;0, std&#58;&#58;ios&#58;&#58;end&#41;.good&#40;&#41;&#41; size = file.tellg&#40;&#41;;
  if&#40;file.seekg&#40;0, std&#58;&#58;ios&#58;&#58;beg&#41;.good&#40;&#41;&#41; size -= file.tellg&#40;&#41;;

  //read contents of the file into the vector
  buffer.resize&#40;size_t&#40;size&#41;&#41;;
  if&#40;size > 0&#41; file.read&#40;&#40;char*&#41;&#40;&buffer&#91;0&#93;&#41;, size&#41;;
&#125;

int main&#40;int argc, char *argv&#91;&#93;&#41;
&#123;
  const char* filename = argc > 1 ? argv&#91;1&#93; &#58; "test.png";
  
  //load and decode
  std&#58;&#58;vector<unsigned char> buffer, image;
  loadFile&#40;buffer, filename&#41;;
  unsigned long w, h;
  int error = decodePNG&#40;image, w, h, buffer.empty&#40;&#41; ? 0 &#58; &buffer&#91;0&#93;, &#40;unsigned long&#41;buffer.size&#40;&#41;&#41;;
  
  //if there's an error, display it
  if&#40;error != 0&#41; std&#58;&#58;cout << "error&#58; " << error << std&#58;&#58;endl;
  
  //the pixels are now in the vector "image", use it as texture, draw it, ...
  
  if&#40;image.size&#40;&#41; > 4&#41; std&#58;&#58;cout << "width&#58; " << w << " height&#58; " << h << " first pixel&#58; " << std&#58;&#58;hex << int&#40;image&#91;0&#93;&#41; << int&#40;image&#91;1&#93;&#41; << int&#40;image&#91;2&#93;&#41; << int&#40;image&#91;3&#93;&#41; << std&#58;&#58;endl;
&#125;

Last edited by KickinAezz on Tue Sep 18, 2007 7:33 am, edited 2 times in total.
saulotmalo2
Posts: 43
Joined: Mon Sep 10, 2007 9:32 am

Post by saulotmalo2 »

<vector> is a container from te STD libray in c++
KickinAezz
Posts: 328
Joined: Sun Jun 03, 2007 10:05 pm

Post by KickinAezz »

Just... saw it in google.
User avatar
dot_blank
Posts: 498
Joined: Wed Sep 28, 2005 8:47 am
Location: Brasil

Post by dot_blank »

please note that all those functions are EXTREMELY
EXPLICIT inline so binary size increases alot :P

but yea all that above works
10011011 00101010 11010111 10001001 10111010
KickinAezz
Posts: 328
Joined: Sun Jun 03, 2007 10:05 pm

Post by KickinAezz »

dot_blank wrote:please note that all those functions are EXTREMELY
EXPLICIT inline so binary size increases alot :P

but yea all that above works
A small example would be nice. using sceGumDrawArray. :]
saulotmalo2
Posts: 43
Joined: Mon Sep 10, 2007 9:32 am

Post by saulotmalo2 »

dot_blank wrote:please note that all those functions are EXTREMELY
EXPLICIT inline so binary size increases alot :P

but yea all that above works
There is a chance of improve the speed by using a lot of inline functions but sometime is a lost because of the cache and memory.
User avatar
dot_blank
Posts: 498
Joined: Wed Sep 28, 2005 8:47 am
Location: Brasil

Post by dot_blank »

saulotmalo2 wrote:
dot_blank wrote:please note that all those functions are EXTREMELY
EXPLICIT inline so binary size increases alot :P

but yea all that above works
There is a chance of improve the speed by using a lot of inline functions but sometime is a lost because of the cache and memory.
yes precisely
10011011 00101010 11010111 10001001 10111010
KickinAezz
Posts: 328
Joined: Sun Jun 03, 2007 10:05 pm

Post by KickinAezz »

KickinAezz wrote:A small example would be nice. using sceGumDrawArray.
Anyone?
Post Reply