PDA

View Full Version : Newbie: Require assistance - modify existing jpeg image ,save and display on LCD



dbugger
19th March 2008, 07:54
Hi

I have to develop a feature in my application which enables modifying an jpeg image and saving it.

This feature is launched from one of the existing screens in my project

Let me divide this task
1. Open an existing jpeg image. This should be displayed on LCD (640x480)
2. Modify the jpeg image using stylus (Touch Screen is integrated)
3. Save the modified image

What are the steps involved? How should I proceed?

-Thanks in advance:)

wysota
19th March 2008, 09:14
Take a look at QImage.

dbugger
19th March 2008, 09:27
Thanks for your response.

I have tried using the QImage
I open the jpeg file using Qimage. But the image is not visible on the LCD.
What else should I do? I tried using QImageIO to display the image on LCD. But, after opening, the old screen itself is displayed on LCD. How do I make this image to display on the LCD?
This is what I have done:
QImage image;
const char *buffer = "/root/ferrari.jpg";
image.load(buffer);

wysota
19th March 2008, 09:40
You have to display the image somewhere. QImage only holds the data. You can use QLabel to display a QPixmap that you can obtain from QImage or directly load from file.

dbugger
19th March 2008, 14:09
Thanks pal!

This is what I have done. But, I still dont see the image on the LCD. The screen is not refreshing. Have I missed something here?
This is what I have done-

QImage image;
const char *buffer = "/root/ferrai";
image.load(buffer);

QPixmap pix;
pix.fromImage(image, 0);

QLabel labl;
labl.setPixmap(pix);

jacek
19th March 2008, 20:43
QPixmap pix;
pix.fromImage(image, 0);
QPixmap::fromImage() is a static method --- it won't change the "pix" variable, but instead it returns a new QPixmap.

wysota
19th March 2008, 22:44
And the label probably goes out of scope.

dbugger
20th March 2008, 05:00
Thanks for your response

What are you hinting at? Do you mean that that the image I want to display is not available in QLabel? If that is the case how can I achieve it?

I see 2 other classes QImageIO and QIODevice. As, I have to display the image on LCD (touhscreen integrated) which is an IO device, should one of these classses be also used?

jpn
20th March 2008, 06:53
1) QPixmap::fromImage() is a static method --- it won't change the "pix" variable, but instead it returns a new QPixmap.


QPixmap pixmap = QPixmap::fromImage(image);

2) And the label probably goes out of scope.


{
QLabel label;
label.setPixmap(pixmap);
label.show();
} // label is a local variable and goes out of scope, so gets destructed according to normal C++ rules

VS.


{
QLabel* label = new QLabel;
// label->setAttribute(Qt::WA_DeleteOnClose); // hint
label->setPixmap(pixmap);
label->show();
} // the pointer variable goes out of scope but the object itself remains alive

dbugger
20th March 2008, 07:13
Thanks.

I will try and let you know

Cheers :)

dbugger
20th March 2008, 14:11
I tried your suggestion. There is no change in the screen that is displayed on the LCD. But, if I press one of the buttons (which is on the keypad), the current screen vanishes but I still dont see the desired image on LCD. Though on close observation, on the top right corner of the LCD, I see something, but it is not part of the image that I want to display
Where am I going wrong?

Thanks for your patience :)

wysota
20th March 2008, 15:23
Could we see a larger snippet of code?

dbugger
20th March 2008, 19:03
This is what I have done:


QImage image;
const char *buffer = "/root/whitescreen.jpg";
image.load(buffer);
QPixmap pix;
pix.fromImage(image, 0);
QLabel* label = new QLabel;
label->setPixmap(pix);
label->show();

Please excuse me for my mistakes if any

jpn
20th March 2008, 19:05
You are still using QPixmap::fromImage() incorrectly.

wysota
20th March 2008, 20:51
And this snippet is not larger than the previous one. Could we see in what exact context is the code situated? Is it in main() or is it a method of some class and where is it called?

dbugger
20th March 2008, 21:14
This is where the code sits


void class_name::function()
{
#if PRINT_DEBUG
qDebug("%s : xxxxxxxxx yyyyyyy Pressed",pname);
#endif

#if 1
printf("\nentering open image\n");
openimage();//ING_IND
printf("\nexited open image\n");
#endif
}


void class_name::openimage()
{
closecurrentscreen();
/*open jpeg image*/
QImage image;
const char *buffer = "/root/whitescreen.jpg";
QPixmap pix;
pix.load(buffer);
QLabel* label = new QLabel;
label->setPixmap(pix);
label->show();
/*modify image*/
/*need to code*/
/*save image*/
/*need to code*/
}

This is exactly what I intend to do. Before opening the image,
- close the current screen
- open the image
- modify
- save

But even the current screen itself is not getting closed.

Thanks pal for everything!!

dbugger
20th March 2008, 21:19
I would like to show some more of the code but it is confidential :(

dbugger
20th March 2008, 21:21
but I can give you the scenario if you want to know. but that I cannot write in the forum, I can write you a private message, if that is fine with you!!

Thanks!!

wysota
20th March 2008, 21:31
You will surely have to redesign your code. Qt is event driven. That means that the code is not structured as a single scenario flow, but instead it's a state machine that reacts on events received. Your method will have to display the image and do nothing more with it. Other methods will perform actions associated with editing the image and finally yet another one will save it back.

My guess is that your slot is not called at all, so verify that first by inserting some debug statements in it.

dbugger
20th March 2008, 21:52
Do you mean to say that the control isn't entering the "openimage" function? If that is the case, I can see the debug messages, which means that my SLOT is fine. But I am not sure as to how to make my current application which has many screens to go inactive/ionvisible and display the jpeg image on LCD.
Should/Can we modify the frame buffer?

wysota
20th March 2008, 22:10
It is very hard to say what is wrong with your code without knowing more. I suggest you use a debugger and step through the code to make sure everything is executed correctly. You will probably encounter some oddities which will tell you where to look for errors.

jacek
20th March 2008, 22:48
const char *buffer = "/root/whitescreen.jpg";
QPixmap pix;
pix.load(buffer);
Does pix.load(buffer) return true? Did you compile Qt with JPEG support?

dbugger
22nd March 2008, 11:03
Thanks for your inputs

1. Does pix.load(buffer) return true?
I checked the return value. It is zero. Does this mean the jpg format is not supported?

2. Did you compile Qt with JPEG support?
I did'nt compile Qt with jpg support
I see the following libraries in the target though- libqjpeg.so and libqjpeg.a
But any attempts to run the examples like -
/usr/local/qtopia-core/examples/itemviews/puzzle/./puzzle or any other example throws the following error: "error while loading shared libraries: libQtGui.so.4: cannot open shared object file: No such file or directory"

Does this mean that because I have built Qt with static option, I cannot link librraries dynamically.
Earlier I did try removing the static option but my application was crashing at startup giving some similar error message as the one above. So I rebuilt Qt with static option

Now, what do you suggest to rectify this. Should I try building QT without static option and with jpeg support or anything on these lines?

wysota
22nd March 2008, 11:19
If you link against static Qt, you can't use regular plugins. Read about static plugins (http://doc.trolltech.com/4.3/plugins-howto.html#static-plugins).

dbugger
23rd March 2008, 13:40
Hi again :),

To statically link plugins, the doc says to do the following
- import the plugin
- make changes to the *.pro file
Having done this, I faced a compilation error of my application for which I doubted the static option. I rebuilt Qt without static opiton and with jpeg support. But, even now I get the same errors. The error is related to the jpeg library with some undefined references and also some warnings which again indicate towards static and dynamic linking

Any clues pal?? :confused:

jacek
23rd March 2008, 16:06
Any clues pal?? :confused:
First you have to provide us some clues. Please post the exact error message you get. Most likely you were trying to use dynamic plugins with static Qt.

dbugger
24th March 2008, 07:20
Okay, so this is what I did.

My final setup will be Qt4.3.4 with static option, OS FC5

Current setup is Qt 4.3.0 without static option and with jpeg support, OS is FC5
In main.cpp file, I included the following
#include <QtPlugin>
Q_IMPORT_PLUGIN(qjpeg)
And in .pro file ,
QTPLUGIN += qjpeg

Now doing a make gives me the following errors (it is long list)

.
/home/pjain/thirdparty/qtopia/qtopia-core-commercial-src/../stage/qtopia-core/lib/libQtCore.a(qlibrary_unix.o): In function `QLibraryPrivate::load_sys()':
qlibrary_unix.cpp:[.text+0x93c]: warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/home/pjain/thirdparty/qtopia/qtopia-core-commercial-src/../stage/qtopia-core/lib/libQtCore.a[qfsfileengine_unix.o]: In function `QFSFileEngine::owner(QAbstractFileEngine::FileOwn er) const':
qfsfileengine_unix.cpp:[.text+0x2de0]: warning: Using 'getgrgid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
qfsfileengine_unix.cpp:[.text+0x2e7c]: warning: Using 'getpwuid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/home/pjain/thirdparty/qtopia/qtopia-core-commercial-src/../stage/qtopia-core/lib/libQtNetwork.a(qhostinfo_unix.o): In function `QHostInfoAgent::fromName(QString const&)':
qhostinfo_unix.cpp:[.text+0x2c0]: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/home/pjain/ingenient-bsp/../ingenient-app/imedia/net/snmp/bin/libisnmp.a(snmpc.o): In function `isnmp_clientInit':
/home/pjain/ingenient-app/imedia/net/snmp/src/snmpc.c:221: warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/home/pjain/thirdparty/qtopia/qtopia-core-commercial-src/../stage/qtopia-core/plugins/imageformats//libqjpeg.a(qjpeghandler.o): In function `read_jpeg_image(QIODevice*, QImage*, QByteArray const&, QSize, int)':
qjpeghandler.cpp:[.text+0x156c]: undefined reference to `jpeg_CreateDecompress'
qjpeghandler.cpp:[.text+0x1580]: undefined reference to `jpeg_std_error'
qjpeghandler.cpp:[.text+0x15b8]: undefined reference to `jpeg_read_header'
qjpeghandler.cpp:[.text+0x15c0]: undefined reference to `jpeg_start_decompress'
qjpeghandler.cpp:[.text+0x1838]: undefined reference to `jpeg_destroy_decompress'
qjpeghandler.cpp:[.text+0x21c8]: undefined reference to `jpeg_read_scanlines'
qjpeghandler.cpp:[.text+0x2278]: undefined reference to `jpeg_finish_decompress'
qjpeghandler.cpp:[.text+0x22f8]: undefined reference to `jpeg_read_scanlines'
qjpeghandler.cpp:[.text+0x24b8]: undefined reference to `jpeg_resync_to_restart'
qjpeghandler.cpp:[.text+0x2510]: undefined reference to `jpeg_finish_decompress'
/home/pjain/thirdparty/qtopia/qtopia-core-commercial-src/../stage/qtopia-core/plugins/imageformats//libqjpeg.a(qjpeghandler.o): In function `write_jpeg_image(QImage const&, QIODevice*, int)':
qjpeghandler.cpp:[.text+0x2d58]: undefined reference to `jpeg_std_error'
qjpeghandler.cpp:[.text+0x2d88]: undefined reference to `jpeg_CreateCompress'
qjpeghandler.cpp:[.text+0x2e3c]: undefined reference to `jpeg_destroy_compress'
qjpeghandler.cpp:[.text+0x2ee0]: undefined reference to `jpeg_set_defaults'
qjpeghandler.cpp:[.text+0x3174]: undefined reference to `jpeg_set_quality'
qjpeghandler.cpp:[.text+0x3180]: undefined reference to `jpeg_start_compress'
qjpeghandler.cpp:[.text+0x31c8]: undefined reference to `jpeg_write_scanlines'
qjpeghandler.cpp:[.text+0x3390]: undefined reference to `jpeg_write_scanlines'
qjpeghandler.cpp:[.text+0x33ac]: undefined reference to `jpeg_finish_compress'
qjpeghandler.cpp:[.text+0x33b4]: undefined reference to `jpeg_destroy_compress'
/home/pjain/thirdparty/qtopia/qtopia-core-commercial-src/../stage/qtopia-core/plugins/imageformats//libqjpeg.a(qjpeghandler.o): In function `jpegSmoothScaler::scanLine(int, QImage const*)':
qjpeghandler.cpp:(.gnu.linkonce.t._ZN16jpegSmoothS caler8scanLineEiPK6QImage+0x28): undefined reference to `jpeg_read_scanlines'


Now commenting the Q_IMPORT_PLUGIN(qjpeg), solves the compilation problem. But, then the return value for pix.load is still zero

Now, the errors are the same incase of QT built with static option

So, I am not sure what is the problem here!!
Is there any other information that you require?

Thanks for your support

dbugger
24th March 2008, 07:22
plz ignore the emoticons....got generated!!

jacek
25th March 2008, 19:16
Current setup is Qt 4.3.0 without static option and with jpeg support, OS is FC5
You can't use static plugins (i.e. Q_IMPORT_PLUGIN(xxx) and QTPLUGIN += xxx) with non-static Qt.



qjpeghandler.cpp:[.text+0x156c]: undefined reference to `jpeg_CreateDecompress'
This means that linker has problems in finding jpeg library. What commands did you exactly issue?

dbugger
26th March 2008, 07:32
Let me clear the confusion

"You can't use static plugins (i.e. Q_IMPORT_PLUGIN(xxx) and QTPLUGIN += xxx) with non-static Qt."
Dbugger: Precisely, initially my Qt was with static support. When I imported the plugins, I got meassages that I posted in the earlier reply. This made me doubt that importing of plugins may not always work when Qt is built statically. So, I reconfigured Qt without static support and with jpeg support. When I tested the code, the return value (pix.load) was zero. So I tried importing the plugin, just to check if there is any change, but the error messages were the same. So, I am not sure what needs to be done

"What commands did you exactly issue?"
Dbugger: I think you mean here the import plugin commands
In my main.cpp file, I did the following
#include <QtPlugin>
Q_IMPORT_PLUGIN(qjpeg)
And in .pro file ,
QTPLUGIN += qjpeg-
The above two are the only changes that I did

As mentioned, even building Qt with jpeg support and without static option, still I am not able to succeed :(

jacek
28th March 2008, 01:02
"What commands did you exactly issue?"
Dbugger: I think you mean here the import plugin commands
I meant the commands you have entered on the console to get that error messages. Where do you run make exactly? What parameters did you pass to configure?

dbugger
30th March 2008, 20:50
"I meant the commands you have entered on the console to get that error messages. Where do you run make exactly? What parameters did you pass to configure?"
Dbugger: This image code is part of another screen in which I have a button, which when clicked is supposed to show the image that I want to see on the LCD.
My application is cross compiled.
So, by doing a make of my application, I get the binary of the entire application on the target

I hope I am clear!!

dbugger
30th March 2008, 21:00
Sorry, I missed the configure options. The following are my configuration options
./configure -v \
-prefix "${STAGE_DIR}" \
-prefix-install \
-no-rpath \
-embedded arm \
-little-endian \
-release \
-no-mouse-pc \
-no-kbd-tty \
-no-kbd-usb \
-no-kbd-sl5000 \
-no-kbd-yopy \
-no-kbd-vr41xx \
-no-kbd-qvfb \
-no-mouse-bus \
-no-mouse-linuxtp \
-no-mouse-yopy \
-no-mouse-vr41xx \
-no-mouse-tslib \
-no-mouse-qvfb \
-no-accessibility \
-no-largefile \
-no-stl \
-no-nis \
-no-cups \
-no-iconv \
-no-qt3support \
-no-freetype \
-qt-libjpeg \ ...
the above is the current config options. earlier ther was "-static" and no support for jpeg

Thanks!! :)