I read compressed image from libpng .. my EncoderWriteCallback write is ok and running
but the read (EncoderReadCallback) is not ok why?
is the same 1:1 QByteArray wo libpng has writteln ... why now it can not read?
the QByteArray is not from qpixmap or qimage.
on debug qbuffer is readable and having size ..
I start the callback so...
png_ptr_read = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if(png_ptr_read == NULL) {
qWarning("unable to create read struct");
return;
}
info_ptr_read = png_create_info_struct(png_ptr_read);
if(info_ptr_read == NULL) {
qWarning("unable to create info struct");
return;
}
png_set_sig_bytes(png_ptr_read, 8);
APNGImageStream myqtchunk(0,frame.stream()); /* stream() = QByteArray */
png_set_read_fn(png_ptr_read,&myqtchunk,EncoderReadCallback);
png_ptr_read = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if(png_ptr_read == NULL) {
qWarning("unable to create read struct");
return;
}
info_ptr_read = png_create_info_struct(png_ptr_read);
if(info_ptr_read == NULL) {
qWarning("unable to create info struct");
return;
}
png_set_sig_bytes(png_ptr_read, 8);
APNGImageStream myqtchunk(0,frame.stream()); /* stream() = QByteArray */
png_set_read_fn(png_ptr_read,&myqtchunk,EncoderReadCallback);
To copy to clipboard, switch view to plain text mode
and this is reader and writer
#define PNG_USER_MEM_SUPPORTED
#define PNG_WRITE_bKGD_SUPPORTED
////base ref http://www.littlesvr.ca/apng/tutorial/x148.html
/* png lib from firefox 3 is patch to APNG format! */
#include "../moz_png/png.h"
/* device to write or read image frames */
class APNGImageStream {
public:
{
dev->setBuffer(&bytes);
if (mode == 1) {
} else {
}
}
~APNGImageStream()
{
dev->close();
}
bool isValid() { return img.loadFromData(dev->data()); }
};
// Called by libpng to flush its internal buffer to ours.
static void EncoderWriteCallback(png_structp png, png_bytep data,
png_size_t size) {
APNGImageStream *state = static_cast<APNGImageStream*>(png_get_io_ptr(png));
Q_ASSERT(state->device());
state->device()->write((char*)data,size);
}
// Called by libpng to read original QByteArray that has self created .
static void EncoderReadCallback(png_structp png, png_bytep data,
png_size_t sizer) {
APNGImageStream *state = static_cast<APNGImageStream*>(png_get_io_ptr(png));
Q_ASSERT(state->device());
qDebug() << "### size to read 1/0 " << state->stream().size() << "," << state->device()->isReadable();
state->device()->read((char*)data,sizer);
qDebug() << "### read callback length " << sizer;
}
#define PNG_USER_MEM_SUPPORTED
#define PNG_WRITE_bKGD_SUPPORTED
////base ref http://www.littlesvr.ca/apng/tutorial/x148.html
/* png lib from firefox 3 is patch to APNG format! */
#include "../moz_png/png.h"
/* device to write or read image frames */
class APNGImageStream {
public:
APNGImageStream( const int mode , QByteArray in = QByteArray() )
:dev(new QBuffer()),bytes(in)
{
dev->setBuffer(&bytes);
if (mode == 1) {
dev->open(QIODevice::WriteOnly);
} else {
dev->open(QIODevice::ReadOnly);
}
}
~APNGImageStream()
{
dev->close();
}
QBuffer *device() { return dev; }
bool isValid() { return img.loadFromData(dev->data()); }
QByteArray stream() { return dev->data(); }
QImage img;
QBuffer *dev;
QByteArray bytes;
};
// Called by libpng to flush its internal buffer to ours.
static void EncoderWriteCallback(png_structp png, png_bytep data,
png_size_t size) {
APNGImageStream *state = static_cast<APNGImageStream*>(png_get_io_ptr(png));
Q_ASSERT(state->device());
state->device()->write((char*)data,size);
}
// Called by libpng to read original QByteArray that has self created .
static void EncoderReadCallback(png_structp png, png_bytep data,
png_size_t sizer) {
APNGImageStream *state = static_cast<APNGImageStream*>(png_get_io_ptr(png));
Q_ASSERT(state->device());
qDebug() << "### size to read 1/0 " << state->stream().size() << "," << state->device()->isReadable();
state->device()->read((char*)data,sizer);
qDebug() << "### read callback length " << sizer;
}
To copy to clipboard, switch view to plain text mode
Bookmarks