LibPng Read Into Struct
<p>I cannot seem to get libpng to dump its data into my struct. I can't figure out what I'm doing wrong. I'm trying to flip the bytes because PNG's are stored top->down and I need the data bottom->up.</p>

<p>First my struct looks like:</p>

<pre><code>typedef union RGB
{
    uint32_t Color;
    struct
    {
        unsigned char B, G, R, A;
    } RGBA;
} *PRGB;
</code></pre>

<p>Then I created a vector as such:</p>

<pre><code>png_init_io(PngPointer, hFile);
png_set_sig_bytes(PngPointer, 8);
png_read_info(PngPointer, InfoPointer);

uint32_t width, height;
int bitdepth, colortype, interlacetype, channels;

png_set_strip_16(PngPointer);
channels = png_get_channels(PngPointer, InfoPointer);
png_get_IHDR(PngPointer, InfoPointer, &amp;width, &amp;height, &amp;bitdepth, &amp;colortype, &amp;interlacetype, nullptr, nullptr);


uint32_t RowBytes = png_get_rowbytes(PngPointer, InfoPointer);
unsigned char** RowPointers = png_get_rows(PngPointer, InfoPointer);
std::vector&lt;RGB&gt; Pixels(RowBytes * height);   //Amount of bytes in one row * height of image.

//Crashes in the for loop below :S

for (int I = 0; I &lt; height; I++)
{
    for (int J = 0; J &lt; width; J++)
    {
        Pixels[(height - 1 - I) * width + J].RGBA.B = *(RowPointers[J]++);
        Pixels[(height - 1 - I) * width + J].RGBA.G = *(RowPointers[J]++);
        Pixels[(height - 1 - I) * width + J].RGBA.R = *(RowPointers[J]++);
    }
}

std::fclose(hFile);
png_destroy_read_struct(&amp;PngPointer, &amp;InfoPointer, nullptr);
</code></pre>

<p>What did I do wrong? How can I get the pixels of the PNG and store them upside down? I used the same technique for bitmaps but PNG just isn't working :l</p>
