PDA

View Full Version : Frame sequence



bmn
21st May 2008, 12:30
Hi all
I am trying to load a sequence of images having .png extension similar to playing a video. I have described a text file which contains the absolute path of the images. Now I was able to open the text file and read line by line data using readLine function but when I try to display it in a loop using setPixmap function, only the path of the last line in the text is being displayed.Can anyone help me.

patrik08
21st May 2008, 12:43
How do you swap frame next() pixmap you set a timer event? on frame total
can you post this piece of code?

louis_xx
21st May 2008, 13:08
Its a long time since ive done things like this, but you may need to tell whatever it is to redraw itself. update() ?

bmn
21st May 2008, 13:13
There are two files
window.h

#ifndef UI_WINDOW_H
#define UI_WINDOW_H

#include <QtGui>

class QPushButton;
class QSplitter;
class QGridLayout;

class Custom_window : public QWidget
{
Q_OBJECT

public:
Custom_window();

private slots:
void new_dialog();
private:
QPushButton *createButton(const QString &text,QWidget *receiver,
const char *member);
void Button_Layout();

QLabel *old_window;
QPushButton *start;
QPushButton *stop;
QVBoxLayout *mainLayout;
QHBoxLayout *box;
QGridLayout *buttonsLayout;
QLabel *address;
QLineEdit *url;
QSpacerItem *spacerItem;
QTextEdit *message;
QFile *file;
QPixmap *p;
};
#endif

window.cpp

#include<QtGui>
#include<stdio.h>

#include "window.h"

Custom_window::Custom_window()
{
old_window = new QLabel;
old_window->setSizePolicy(QSizePolicy::Expanding,QSizePolicy:: Expanding);
old_window->setAlignment(Qt::AlignCenter);
old_window->setText("Press Start");
address = new QLabel;
address->setText("Server I.P");
QFont font;
font.setPointSize(11);
address->setFont(font);
url = new QLineEdit;
url->setObjectName(QString::fromUtf8("url"));
message = new QTextEdit;
message->setSizePolicy(QSizePolicy::Preferred,QSizePolicy:: Preferred);
Button_Layout();

mainLayout = new QVBoxLayout;
mainLayout->addWidget(old_window);
mainLayout->addLayout(buttonsLayout);
mainLayout->addWidget(message);
setLayout(mainLayout);
setWindowTitle(tr("Client GUI"));
resize(640,800);
}

QPushButton *Custom_window::createButton(const QString &text,QWidget *receiver,
const char *member)
{
QPushButton *button = new QPushButton(text);
button->connect(button,SIGNAL(clicked()),receiver,member);
return button;
}

void Custom_window::Button_Layout()
{
start = createButton(tr("Start"), this, SLOT(new_dialog()));
stop = createButton(tr("Stop"), this, SLOT(close()));
buttonsLayout = new QGridLayout;
buttonsLayout->addWidget(address,0,0,1,1);
buttonsLayout->addWidget(url,0,1,1,1);
buttonsLayout->addWidget(start,0,2,1,1);
buttonsLayout->addWidget(stop,0,3,1,1);

}

void Custom_window::new_dialog()
{
QFile file("in.txt");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text ))
return;
QTextStream in(&file);
while (!in.atEnd()) {
QString line = in.readLine();
url->setText(line);
QPixmap p(line);
p=p.scaled ( old_window->width(),old_window->height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
old_window->resize(500,480);
old_window->setPixmap(p);
message->append("The path of the file is");
message->append(line);
}
}

patrik08
21st May 2008, 14:43
And how you define time to display one pixmap?
If you open 100 file by setpixmap you can see only the last!

You must create a data struct from image



struct frame
{
QByteArray extension; /* png jpg ...*/
QByteArray data; /* pixmap data */
int timetolive; /* time to show */
QRect display; /* 100x100 */
int age;
};



or better make a struct like MNG image format and you can display on QMovie

or have a look on
http://wiki.qtcentre.org/index.php?title=Using_custom_data_types_with_Qt
or other image class to serialize image:
http://www.qtforum.de/forum/viewtopic.php?t=6600

After create a QDataStream wo contain all your single frame the virtual AVI file
and at end play its... from a timer event

if your choise the MNG format all needed info is inside:
QDIR\4.4.0_src\src\3rdparty\libmng

bmn
22nd May 2008, 06:51
Can u be more specific i.e where can I place the data struct. Plz post the code also

patrik08
22nd May 2008, 10:13
Here is a good structure to compose image frame:

qt-x11-opensource-4.0.0-b2/tools/qvfb/qanimationwriter.cpp
It is as target only linux but i rewrite it to win32

http://fop-miniscribus.googlecode.com/svn/trunk/demo_write_mng/

Compose image sequence




void Gui_Main::setCaptureEnabled(bool enable)
{
/* start stop QBasicTimer FrameTimeLine; */
RRunning = enable;
if (enable && framerate > 32) {
FrameTimeLine.start(framerate,this);
} else {
FrameTimeLine.stop();
}
}
QImage Gui_Main::CatScreen()
{
QDesktopWidget *desk = qApp->desktop();
QPixmap desktopscreen = QPixmap::grabWindow(desk->screen()->winId());
QPixmap small = desktopscreen.scaledToWidth(100);
devimg->paint( small );
scrollArea->setWidget(devimg);
delete &desktopscreen;
return small.toImage();
}

void Gui_Main::StartRead()
{
if (RRunning) {
StopRead();
return;
}
QString filename = QFileDialog::getSaveFileName(this, "Save animation", "animation.mng", "*.mng");
if (filename.size() > 0) {
animation = new AnimationWriter(filename,"MNG");
animation->setFrameRate(framerate);
animation->appendFrame(CatScreen());
setCaptureEnabled(true);
}
}
void Gui_Main::timerEvent(QTimerEvent *event)
{
if (event->timerId() == FrameTimeLine.timerId()) {
timeline++;
qDebug() << "### timeline " << timeline;
animation->appendFrame(CatScreen());
}
}
void Gui_Main::StopRead()
{
setCaptureEnabled(false);
delete animation;
animation = 0;
}




try it
1# svn co http://fop-miniscribus.googlecode.com/svn/trunk/demo_write_mng/ movietest
2#
copy path from QTDIR /src/3rdparty/zlib & libpng to movietest dir

INCLUDEPATH += ui libpng zlib

and build it...

it write file .... but QMovie on read say:
MNG error 4097: Image is larger than defined maximum; chunk MHDR; subcode 0:0
MNG error 1028: Chunk-length is invalid; chunk MOVE; subcode 0:0

MHDR is a chunk format to learn and after you can register your image to a simple movie like gif animated ...

to look original search qanimationwriter.cpp on http://www.google.com/codesearch

patrik08
22nd May 2008, 22:57
Can u be more specific i.e where can I place the data struct. Plz post the code also


QT 4.4 can write APNG image format!
http://en.wikipedia.org/wiki/Animated_Portable_Network_Graphics


I have it :) ready as console assembler now you can bundle all your image and display on firefox ...
and later write a QLabel to display al single frame png....




apng img1.png img2.png img3.png [enter]



result here...
http://ppk.ciz.ch/qt_c++/apng_format/written-apng.png
Install Firefox 3 or GrandParadiso , Opera 9.5 if the image here is not animated and you see only the first frame....

svn co http://fop-miniscribus.googlecode.com/svn/trunk/APNG_assembler/ APNG_assembler