Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LoadImageFromPNG - how to #13

Open
SummerSeaSun opened this issue Jan 10, 2020 · 5 comments
Open

LoadImageFromPNG - how to #13

SummerSeaSun opened this issue Jan 10, 2020 · 5 comments
Assignees

Comments

@SummerSeaSun
Copy link

This is the prosecution of:
ajstarks#21

I've edited the function like this:

void image_show(int w, int h, char*filename) {
  fprintf(stdout, "inizio\n");

  Start(w, h);
//  VGImage sub_desert = LoadImageFromPNG(const char *filename, VGint *w, VGint
  *h);
  VGImage sub_desert = CreateImageFromPng(const char *filename, VGint *w, VGint
  *h);
  DrawImageAt( 0, 0, sub_desert);
  vgDestroyImage();
}

image_show(1280,800, "/home/pi/img/the");

compilation will result in this error


33:24: warning: implicit declaration of function ‘LoadImageFromPNG’ [-Wimplicit-function-declaration]
   VGImage sub_desert = LoadImageFromPNG(const char *filename, VGint *w, VGint *h);
                        ^~~~~~~~~~~~~~~~
osd_background.c:33:41: error: expected expression before ‘const’
   VGImage sub_desert = LoadImageFromPNG(const char *filename, VGint *w, VGint *h);
                                         ^~~~~


or  with CreateImageFromPng
:33:43: error: expected expression before ‘const’
   VGImage sub_desert = CreateImageFromPng(const char *filename, VGint *w, VGint

@paeryn
Copy link
Owner

paeryn commented Jan 11, 2020

Why have you put the types of the parameters in the function calls? That's not valid C so there's no wonder the compiler is throwing errors. Just put the variables or values, the compiler uses the type information provided in the function declarations to make sure the values you pass are of the correct typesq.

VGImage sub_desert = CreateImageFromPng(filename);

It's perfectly fine to pass a char * as a filename, the const in CreateImageFromPng's declaration just says that CreateImageFromPng won't modify the string you pass it.

CreateImageFromPng() only has one parameter, the filename. LoadImageFromPNG() used to have two additional pointers which would be the addresses where it would store the image's dimensions (so your attempt to pass w and h would be invalid).

If you want to query a loaded image's dimensions you can with

VGint imageWidth = vgGetParameteri(sub_desert, VG_IMAGE_WIDTH);
VGint imageHeight = vgGetParameteri(sub_desert, VG_IMAGE_HEIGHT);

@paeryn paeryn self-assigned this Jan 11, 2020
@SummerSeaSun
Copy link
Author

Surely I'm missing something:
With this I've replaced OpenHD version with yours:

cd /home/pi
mv openvg openvg_orig
git clone https://github.com/paeryn/openvg.git

cd openvg
sudo make clean
sudo make library
sudo make install

Then I've created the c script:


// show static background images


#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "VG/openvg.h"
#include "VG/vgu.h"
#include "fontinfo.h"
#include "shapes.h"



void image_show(int x, int y, int w, int h, char*filename) {



	  Start(w, h);
	//  VGImage sub_desert = LoadImageFromPNG(const char *filename, VGint *w, VGint	  *h);

		VGImage sub_desert = CreateImageFromPng(filename);
           //		Image(x, y, w, h, filename);
	  DrawImageAt( 0, 0, sub_desert);
	//  vgDestroyImage();

	//Image(x, y, w, h, filename);

  End();

}


int main(int argc, char *argv[]) {
fprintf(stdout, "inizio\n" );

    int width, height;
    init(&width, &height);
    Start(width, height);

		image_show(0,0, 1280,800, "/home/pi/img/test.png");

sleep(36500000 );
    End();
    finish();
    exit(0);
}

Then compile fail:

make: Warning: File 'osd_background.c' has modification time 689 s in the future
gcc -c -o osd_background.o osd_background.c -I/opt/vc/include/ -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux
osd_background.c: In function ‘image_show’:
osd_background.c:22:24: warning: implicit declaration of function ‘CreateImageFromPng’ [-Wimplicit-function-declaration]
   VGImage sub_desert = CreateImageFromPng(filename);
                        ^~~~~~~~~~~~~~~~~~
osd_background.c:23:4: warning: implicit declaration of function ‘DrawImageAt’ [-Wimplicit-function-declaration]
    DrawImageAt( 0, 0, sub_desert);
    ^~~~~~~~~~~
gcc -o osd_background osd_background.o -lfreetype -lz -L/opt/vc/lib/ -lbrcmGLESv2 -lbrcmEGL -lopenmaxil -lbcm_host -lvcos -lvchiq_arm -lpthread -lrt -lm -lshapes
osd_background.o: In function `image_show':
osd_background.c:(.text+0x2c): undefined reference to `CreateImageFromPng'
osd_background.c:(.text+0x44): undefined reference to `DrawImageAt'
collect2: error: ld returned 1 exit status
Makefile:15: recipe for target 'osd_background' failed
make: *** [osd_background] Error 1

@paeryn
Copy link
Owner

paeryn commented Jan 13, 2020

You need to switch to a recent branch (screenshot is the latest) which has the functions. I've got it set up so that the main branch is from when I forked ajstarks' code and the other branches are named from when certain key features were implemented. I realise this isn't the normal way for git but I'm used to constantly incrementing branches.

You need to do a

git checkout screenshot

and build it from there. Oh, and you shouldn't use sudo until the final make install, building the library doesn't require root privileges, only the installing to system directories requires it. Using sudo to build the library will mean you end up with a load of files owned by root in your directory.

git clone https://github.com/paeryn/openvg.git
cd openvg
git checkout screenshot
make clean
make library
sudo make install

@SummerSeaSun
Copy link
Author

SummerSeaSun commented Jan 13, 2020

Thanks for patience, but no luck, seems there is an error with that "font2openvg":

Cloning into 'openvg'...

pi@wbc(rw):~$ git clone https://github.com/paeryn/openvg.git
remote: Enumerating objects: 1525, done.
remote: Total 1525 (delta 0), reused 0 (delta 0), pack-reused 1525
Receiving objects: 100% (1525/1525), 6.54 MiB | 4.73 MiB/s, done.
Resolving deltas: 100% (937/937), done.
pi@wbc(rw):~$ cd openvg
pi@wbc(rw):~/openvg$ git checkout screenshot
Branch screenshot set up to track remote branch screenshot from origin.
Switched to a new branch 'screenshot'
pi@wbc(rw):~/openvg$ make clean
rm -f *.o *.inc *.so font2openvg *.c~ *.h~
indent -linux -c 60 -brf -l 132  libshapes.c oglinit.c fontsystem.c shapes.h fontinfo.h
pi@wbc(rw):~/openvg$ make library
make: *** No rule to make target 'library'.  Stop.
pi@wbc(rw):~/openvg$ sudo make install
install -m 755 -p font2openvg /usr/bin/
install: cannot stat 'font2openvg': No such file or directory
Makefile:57: recipe for target 'install' failed
make: *** [install] Error 1

instead with ajstarks version it compile:

@wbc(rw):~$ sudo rm -r openvg
pi@wbc(rw):~$ sudo git clone --verbose https://github.com/ajstarks/openvg.git
Cloning into 'openvg'...
POST git-upload-pack (165 bytes)
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 1151 (delta 0), reused 1 (delta 0), pack-reused 1147
Receiving objects: 100% (1151/1151), 6.17 MiB | 1.36 MiB/s, done.
Resolving deltas: 100% (637/637), done.
pi@wbc(rw):~$ cd openvg
pi@wbc(rw):~/openvg$ sudo make clean
rm -f *.o *.inc *.so font2openvg *.c~ *.h~
indent -linux -c 60 -brf -l 132  libshapes.c oglinit.c shapes.h fontinfo.h
pi@wbc(rw):~/openvg$ sudo make library
gcc -O2 -Wall -I/opt/vc/include -I/opt/vc/include/interface/vmcs_host/linux -I/opt/vc/include/interface/vcos/pthreads -fPIC -c oglinit.c
g++ -I/usr/include/freetype2 fontutil/font2openvg.cpp -o font2openvg -lfreetype
./font2openvg /usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf DejaVuSans.inc DejaVuSans
468 glyphs written
./font2openvg /usr/share/fonts/truetype/ttf-dejavu/DejaVuSansMono.ttf DejaVuSansMono.inc DejaVuSansMono
468 glyphs written
./font2openvg /usr/share/fonts/truetype/ttf-dejavu/DejaVuSerif.ttf DejaVuSerif.inc DejaVuSerif
468 glyphs written
gcc -O2 -Wall -I/opt/vc/include -I/opt/vc/include/interface/vmcs_host/linux -I/opt/vc/include/interface/vcos/pthreads -fPIC -c libshapes.c
gcc -L/opt/vc/lib -lbrcmEGL -lbrcmGLESv2 -ljpeg -shared -o libshapes.so oglinit.o libshapes.o
pi@wbc(rw):~/openvg$ sudo make install
install -m 755 -p font2openvg /usr/bin/
install -m 755 -p libshapes.so /usr/lib/libshapes.so.1.0.0
strip --strip-unneeded /usr/lib/libshapes.so.1.0.0
ln -f -s /usr/lib/libshapes.so.1.0.0 /usr/lib/libshapes.so
ln -f -s /usr/lib/libshapes.so.1.0.0 /usr/lib/libshapes.so.1
ln -f -s /usr/lib/libshapes.so.1.0.0 /usr/lib/libshapes.so.1.0
install -m 644 -p shapes.h /usr/include/
install -m 644 -p fontinfo.h /usr/include/

@paeryn
Copy link
Owner

paeryn commented Jan 13, 2020

Ah, I must've removed the library target at some point. Instead of make library just do make, that should build both font2openvg and the library. Then (unless errors occured) do the sudo make install

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants