Allegro5 cannot seem to be able to decode png images for my game project. This function:
ALLEGRO_BITMAP* BrushCollection::LoadBitmapFromFile(const char* fileName)
{
ALLEGRO_PATH* path = al_get_standard_path(ALLEGRO_EXENAME_PATH);
al_append_path_component(path, "assets");
al_set_path_filename(path, fileName);
ALLEGRO_BITMAP* bitmap = al_load_bitmap(al_path_cstr(path, '\\'));
allegro_init(bitmap, L"UI Bitmap");
return bitmap;
}
returns NULL. I know image paths are correct because the same code works on Windows.
Related to this question: here
I'm having this same issue in Ubuntu 20.04 with the precompiled allegro 5.2.7 package! I added png as an external library to the project. I do have libpng16-16 and libpng-dev installed in my system, but allegro can't seem to be able to decode png images!
This is the command generated by cmake by the way, which seems to be including libpng in the linking:
/usr/bin/c++ -g CMakeFiles/Planetaire.dir/src/main.cpp.o CMakeFiles/Planetaire.dir/src/Game.cpp.o CMakeFiles/Planetaire.dir/src/brush/BrushCollection.cpp.o CMakeFiles/Planetaire.dir/src/events/EventStack.cpp.o CMakeFiles/Planetaire.dir/src/events/MouseEvents.cpp.o CMakeFiles/Planetaire.dir/src/text/FontCollection.cpp.o CMakeFiles/Planetaire.dir/src/tools/AllegroInit.cpp.o CMakeFiles/Planetaire.dir/src/tools/Debug.cpp.o CMakeFiles/Planetaire.dir/src/ui/actions/ContinueGame.cpp.o CMakeFiles/Planetaire.dir/src/ui/actions/HideInGameMenu.cpp.o CMakeFiles/Planetaire.dir/src/ui/actions/HideMainMenu.cpp.o CMakeFiles/Planetaire.dir/src/ui/actions/QuitGame.cpp.o CMakeFiles/Planetaire.dir/src/ui/actions/QuitToDesktop.cpp.o CMakeFiles/Planetaire.dir/src/ui/actions/ShowInGameMenu.cpp.o CMakeFiles/Planetaire.dir/src/ui/actions/ShowMainMenu.cpp.o CMakeFiles/Planetaire.dir/src/ui/actions/StartNewGame.cpp.o CMakeFiles/Planetaire.dir/src/ui/components/AbstractComponent.cpp.o CMakeFiles/Planetaire.dir/src/ui/components/InGameMenu.cpp.o CMakeFiles/Planetaire.dir/src/ui/components/MainMenu.cpp.o CMakeFiles/Planetaire.dir/src/ui/AbstractUIElement.cpp.o CMakeFiles/Planetaire.dir/src/ui/ButtonElement.cpp.o CMakeFiles/Planetaire.dir/src/ui/ImageElement.cpp.o CMakeFiles/Planetaire.dir/src/ui/MainUIElement.cpp.o CMakeFiles/Planetaire.dir/src/ui/PanelElement.cpp.o CMakeFiles/Planetaire.dir/src/world-generator/Terrain.cpp.o -o Planetaire -lallegro -lallegro_main -lallegro_font -lallegro_ttf -lallegro_image -lallegro_primitives /usr/lib/x86_64-linux-gnu/libpng.so
I wonder what I'm doing wrong here. This works out of the box on windows.
I think I know the answer!
The path is simply wrong, when doing:
ALLEGRO_BITMAP* bitmap = al_load_bitmap(al_path_cstr(path, '\\'));
This is building a backward slash path. Linux/Mac can't find this file. When I corrected this path, the application worked!
Related
I'm trying to learn how to use allegro5 so I installed it from source on their github and it was going fine until I tried to load an image. Here is my code that wasn't working.
#include<allegro5/allegro.h>
#include<allegro5/allegro_image.h>
#include<stdio.h>
int main(int argc, char **argv){
al_init();
al_init_image_addon();
al_create_display(640,560);
ALLEGRO_BITMAP * image = al_load_bitmap("pi.png");
while(true){
al_clear_to_color(al_map_rgb(100,0,0));
if(image == NULL){
printf("Image didn't load properly\n");
return -1;
}
al_draw_bitmap(image, 0, 0, 0);
al_flip_display();
}
}
But after making a pi.bmp in the same directory and then changing the
ALLEGRO_BITMAP * image = al_load_bitmap("pi.png");
to
ALLEGRO_BITMAP * image = al_load_bitmap("pi.bmp");
It works as expected. I already have libpng16-16 and libpng-dev installed. I am compiling the file (main.cpp) with this command:
g++ main.cpp -I/usr/local/include/allegro5 -L/usr/local/lib -lallegro -lallegro_image -lpng
Does anyone know what I am doing wrong?
EDIT: By not working I do mean that image == NULL is true. Also I just tried to do it on my laptop. I believe the problem must be somewhere with my installation. My desktop (the one that doesn't work) is running Ubuntu 18.10 (cosmic) and my laptop is running 18.04 (bionic) and works fine after adding the ppa and updating. It seems they only have pre-compiled binaries for bionic, which is what forced me to compile from source.
EDIT2: #rcorre's answer worked for me! Hopefully this will help someone else out in the future. When building you need to use the command cmake -D WANT_IMAGE_PNG=1 .. from the build directory.
I have already raised the inquiry to Tesseract Forum, but whether I can have a clue for the error, I raise the issue at this forum again. As this is my favorite forum in solving the problems.
I have a problem somehow related to the tesseract lib.
The problem is at libtiff one of the components used in leptonica library.
I followed exactly what is described here
in building libtiff for my 64bit windows.
C:\LIBTIFF\LIBTIFF> nmake /f makefile.vc
C:\LIBTIFF\LIBTIFF> cd ..\tools
C:\LIBTIFF\TOOLS> nmake /f makefile.vc
Build is ok.
Using tiff lib and I built leptonica lib and tessearact lib for 64bit windows.
Once I run my application using tesseract lib, I got error at tiff lib and the error is
"Unhandled exception at 0x00007FFA966FDD27 (msvcr120.dll) in TessarActOCR_test.exe: An invalid parameter was passed to a function that considers invalid parameters fatal."
The error is happening at lseek in the following function. The function is located in tiffio.c
static TIFF *
fopenTiff(FILE *fp,tif_win32.c
const char *modestring)
{
l_int32 fd;
PROCNAME("fopenTiff");
if (!fp)
return (TIFF *)ERROR_PTR("stream not opened", procName, NULL);
if (!modestring)
return (TIFF *)ERROR_PTR("modestring not defined", procName, NULL);
if ((fd = fileno(fp)) < 0)
return (TIFF *)ERROR_PTR("invalid file descriptor", procName, NULL);
lseek(fd, 0, SEEK_SET);
return TIFFFdOpen(fd, "TIFFstream", modestring);
}
What could be wrong with this error?
Now I solved all problems and tesseract lib is working at my 64bit pc and project. The solution for me is step by step following the discussions in this link during preparing the dependencies. Then leptonica lib is built and then link to tesseract to build tesseract lib. Now all are working well.
I'm trying to use LibVLC in a Qt 5 program to open a VLC instance and play a video.
The following code comes from https://wiki.videolan.org/LibVLC_Tutorial/
I'm using Linux.
.pro :
TEMPLATE = app
TARGET = projectLoic
INCLUDEPATH += . vlc
QT += widgets
# Input
HEADERS +=
SOURCES += main.cpp
LIBS +=-lvlc
main :
#include <vlc/vlc.h>
#include <QApplication>
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
libvlc_instance_t * inst;
libvlc_media_player_t *mp;
libvlc_media_t *m;
// Load the VLC engine
inst = libvlc_new(0, NULL);
// Create a new item
m = libvlc_media_new_path (inst, "/home/........mp3");
// Create a media player playing environement
mp = libvlc_media_player_new_from_media (m);
// play the media_player
libvlc_media_player_play (mp);
return app.exec();
}
The compilation is fine. But the program immediatly crashes when I build it (with Qt Creator). Any idea?
Many thanks
Many things could cause this crash. The best is to get VLC source code to trace back the issue. Passing the option '--verbose=2' when initializing libVLC can help as well.
In my case the cause of the crash was due to this bug in the ubuntu package of vlc:
https://bugs.launchpad.net/ubuntu/+source/vlc/+bug/1328466
When calling libvlc_new() vlc modules and their dependent libraries are loaded into memory. The qt module of LibVLC was searching for Qt4 shared objects instead of Qt5 (manually installed).
The solution was to rebuild the module cache which was outdated an pointing to Qt4 binaries. You can reset it on the command line:
sudo /usr/lib/vlc/vlc-cache-gen -f /usr/lib/vlc/plugins/
Or pass to vlc the option:
--reset-plugins-cache
I have never used this library, but Are you using exactly this code?
m = libvlc_media_new_path (inst, "/home/........mp3");
This path may be the problem.
What distribution of Linux are you using?
I ran into this same problem with Qt5 and LibVLC, and the primary cause (Ubuntu 12.04 LTS and 14.04 LTS), was that LibVLC was loading the qt4 interface plugin, which conflicted with Qt5. If you check your call stack, you'll most likely see that at a Qt4 library was being loaded, causing the crash.
If this is the problem, there are only 3 options (tested with LibVLC 2.2 and Qt5 on Ubuntu 12.04 and 14.04 LTS 64 bit).
The first (worst) is to delete the qt4 user interface plugin. You can test this is the problem by moving and running and then setting it back. Deleting will break your regular VLC player most likely.
Second option is to create a copy of the plugins directory and set that in your runtime path using VLC_PLUGIN_PATH, environment variable. but I've had trouble getting that to work without changing the original plugin path folder also (which will break your VLC player unless you modify your shortcuts, etc. to also set VLC_PLUGIN_PATH.
The third option, and what I ended up doing, was to custom build my own static LibVLC binary with a few edits to the source code so that it will not load the qt4 interface plugin installed with VLC. You can follow these steps to do this.
1) Download VLC Source Code for your platforms distribution.
http://download.videolan.org/pub/videolan/vlc/
Make sure you download the version matching your distribution. For
example, match the VLC version to what is installed with Ubuntu.
2) Extract source code to folder
3) Install dependencies for the OS distribution
sudo apt-get build-dep vlc
4) Modify src/modules/bank.c
Edit the module_InitDynamic function
Add the following code at the top of the function:
// HACK TO DISABLE QT4 PLUGIN
if(strstr(path, "qt4") != NULL)
return NULL;
// END HACK
3) From terminal
./bootstrap
./configure --disable-qt --disable-skins2 --enable-xcb --prefix=/home/$USER/vlc-custom_build_output_folder_name
./make
./make install
4) Copy/Save the resulting files in the install folder.
Then just link against this library instead.
I have this code to create and write an image in opencv:
char * outImage="C:/tmp/000014/outimage.jpg";
Mat gray_image(imageWidth,imageHeight, CV_8UC1, Scalar(255));
imwrite( outImage, gray_image );
but when I am running thid code, I am getting error that file extension is not known and hence iwrite can not write image.
What is wrong with this code?
edit1
I changed the code to see there is a problem with code or installation.
so I have this code now
Mat x=imread("C:/tmp/a.jpg");
imshow("Image", x);
waitKey(0);
I am sure that the file c:/tmp/a.jpg exist.
When I run the application, I am getting this error:
OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in unknown function, file C:\slave\builds\WinInstallerMegaPack\src\opencv\modules\core\src\array.cpp, line 2482
C:\slave\builds\WinInstallerMegaPack\src\opencv\modules\core\src\array.cpp:2482: error: (-206) Unrecognized or unsupported array type
I followed this answer in so to install OpenCV o my system (I use vc11, insteade of vc10 during installation) Installing OpenCV 2.4.3 in Visual C++ 2010 Express
edit 2
The problem was that I mixed the debug and release libraries,
For release use release libraries which don't have d at the end (for example opencv_calib3d243.lib
instead od opencv_calib3d243d.lib)
for debug use debug libraries which has d at the end for example opencv_calib3d243d.lib
Make sure that you are using the correct lib name based on the opencv version that you have for example opencv_calib3d245d.lib for opencv 2.4.5.
Make sure you have not mixed up release and debug DLL's of OpenCV. Plus check whether x86 or x64 DLL's would work. Sometimes x64 DLL's do mess up on x64 machines. Dont know why but I had to switch to x86 version.
Try this:
void write(){
char * outImage="C:/tmp/000014/outimage.jpg";
Mat img = Mat(Size(imageWidth,imageHeight), CV_8UC1, Scalar(255));
imwrite(out, img);
}
Please be sure of your output path, imageWidth,imageHeight.
MoreOver check your dependance (you need libjpeg8 under Linux):
For Linux
sudo apt-get install libpng12-0 libpng12-dev libpng++-dev libpng3 libpnglite-dev libpngwriter0-dev libpngwriter0c2 zlib1g-dbg zlib1g zlib1g-dev pngtools libjasper-dev libjasper-runtime libjasper1 libjpeg8 libjpeg8-dbg libjpeg62 libjpeg62-dev libjpeg-progs libtiff4-dev libtiff4 libtiffxx0c2 libtiff-tools ffmpeg libavcodec-dev libavcodec52 libavformat52 libavformat-dev libswscale0 libswscale-dev openexr libopenexr6 libopenexr-dev
For Windows follow that guide:
http://docs.opencv.org/doc/tutorials/introduction/windows_install/windows_install.html
Could it be that there is a bug in OpenCV2.4 highgui for capturing frames from video in windows?
I installed both the precompiled libraries, the ones compiled by me, I can compile everything perfectly and I can run my programs if
they are image based. The problem is only for videos. OpenCV crashes in this function always:
virtual IplImage* retrieveFrame(int)
{
unsigned char* data = 0;
int step=0, width=0, height=0, cn=0;
if(!ffmpegCapture ||
!icvRetrieveFrame_FFMPEG_p(ffmpegCapture,&data,&step,&width,&height,&cn)) <-------CRASHES HERE
return 0;
cvInitImageHeader(&frame, cvSize(width, height), 8, cn);
cvSetData(&frame, data, step);
return &frame;
}
This is inside the class cap_ffmpeg.cpp and is called by VideoCapture.
I tried versions 2.4.2 and 2.4.9. My programes were working finde with opencv2
More information
Windows 7
Build the projects with cmake (important as it could be that cmake is not building/finding the right codecs)
VisualStudio 9 2008
OpenCV 2.4.2
EDIT
It looks like it is actually a bug, so, how can I solve this problem and change my code to be able to read avi files?
As a temporary solution I decided to re-encode the videos so OpenCV doesn't use the ffmpeg. I used VirtualDub with the microsoft video 1 compression, which uses "msvidc32.dll" driver.
It works with all my videos so it is enough by now as I can keep working with OpenCV in windows.
I had similar problem. I downloaded VirtualDub, but it did not open one of my avi video because of its FMP4 encode. So in the end, the solution that solved the problem was to install ffdshow, a decoder for windows. See this link: http://www.moviecodec.com/video-codecs/fmp4-codec-with-virtualdub-45814/
Then I do not need to use VirtualDub anymore to re-encode my video anymore!
if your using x64. Please use opencv_ffmpeg245_64.dll this solves may solve the problem. Or rename opencv_ffmpeg245_64.dll to opencv_ffmpeg245.dll may solve the problem.