Finished PNG loading, but totally untested

Originally committed to SVN as r274.
This commit is contained in:
Rodrigo Braz Monteiro 2006-04-01 11:00:55 +00:00
parent 121c81a157
commit 065056157c
3 changed files with 55 additions and 14 deletions

View file

@ -38,6 +38,7 @@
// Headers // Headers
#include <png.h> #include <png.h>
#include "png_wrap.h" #include "png_wrap.h"
#include "prs_video_frame.h"
/////////////// ///////////////
@ -57,18 +58,9 @@ PNGWrapper::~PNGWrapper() {
////////////// //////////////
// Read image // Read image
void PNGWrapper::Read(void *dst) { void PNGWrapper::Read(PRSVideoFrame *frame) {
// Check initialization // Begin
if (!initialized) Begin(); Begin();
}
//////////////
// Initialize
void PNGWrapper::Begin() {
// Check initialization
if (initialized) End();
initialized = true;
// Initialize libpng structures // Initialize libpng structures
png_structp png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); png_structp png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
@ -90,6 +82,29 @@ void PNGWrapper::Begin() {
throw 1; throw 1;
} }
// Set data reading
png_set_read_fn(png_ptr,this,memory_read_data);
// Set row pointers
png_bytepp row_pointers = (png_bytep *) png_malloc(png_ptr, frame->h*sizeof(png_bytep));
for (int i=0; i<frame->h; i++) row_pointers[i] = (png_bytep) (frame->data[0] + frame->w*i);
png_set_rows(png_ptr, info_ptr, row_pointers);
// Read data
png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);
// Clean up
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
End();
}
//////////////
// Initialize
void PNGWrapper::Begin() {
// Check initialization
if (initialized) End();
initialized = true;
} }
@ -100,3 +115,16 @@ void PNGWrapper::End() {
if (!initialized) return; if (!initialized) return;
initialized = false; initialized = false;
} }
/////////////
// Read data
void PNGWrapper::memory_read_data(png_structp png_ptr, png_bytep dstData, png_size_t length) {
PNGWrapper *wrapper = (PNGWrapper*) png_get_io_ptr(png_ptr);
wrapper->ReadData(dstData,length);
}
void PNGWrapper::ReadData(png_bytep dstData, png_size_t length) {
memcpy(dstData,((char*)data)+pos,length);
pos++;
}

View file

@ -34,6 +34,16 @@
// //
///////////
// Headers
#include <png.h>
//////////////
// Prototypes
class PRSVideoFrame;
///////////////////// /////////////////////
// PNG Wrapper class // PNG Wrapper class
class PNGWrapper { class PNGWrapper {
@ -45,6 +55,9 @@ private:
void Begin(); void Begin();
void End(); void End();
static void memory_read_data(png_structp png_ptr, png_bytep data, png_size_t length);
void ReadData(png_bytep data, png_size_t length);
public: public:
PNGWrapper(); PNGWrapper();
~PNGWrapper(); ~PNGWrapper();
@ -52,5 +65,5 @@ public:
void SetData(void *ptr) { data = ptr; pos = 0; } void SetData(void *ptr) { data = ptr; pos = 0; }
void *GetData() { return data; } void *GetData() { return data; }
void Read(void *dst); void Read(PRSVideoFrame *dst);
}; };

View file

@ -139,7 +139,7 @@ PRSVideoFrame *PRSImage::GetDecodedFrame() {
try { try {
PNGWrapper png; PNGWrapper png;
png.SetData(data); png.SetData(data);
png.Read(frame->data[0]); png.Read(frame);
} }
// Handle errors // Handle errors