Image formats like JPEG and PNG do
not store "raw" pixel data. In order to get the amount of data down to a "manageable" size, they use
compression. Video formats are even more complex, because they use similar techniques as JPEG or PNG for
intra-frame (within a frame) compression, but additionally use
inter-frame (in-between subsequent frames) compression techniques!
So, if your
char*
array contains JPEG or PNG data (or some sort of video data), then that is
not "raw" pixel data, but a
compressed bit-stream! This must be
decompressed first, using the matching
decoder, in order to restore the original "image pixels" (or video frames).
In order to get an idea of how image compression works, have look at the JPEG encoding here:
https://en.wikipedia.org/wiki/JPEG#Encoding
Because image formats like JPEG and PNG are very complex (and video formats even more so!), you certainly do
not want to implement the required decoder (de-compressor) in your own code, but rather use one of the existing and well-tested libraries...
http://libjpeg.sourceforge.net/
http://www.libpng.org/pub/png/libpng.html
http://ffmpeg.org/libavcodec.html