Comments (11)
Image scaling is not supported at this time. If it were what API would you propose?
from openvg.
Well, with the current API design where everything returns void, I guess I would just expect the Scale() function to up-scale whatever's on the canvas at the time. Going forward, I think that returning some sort of context structure back to the user would make things like this easier -- e.g., Image() and makeimage() would return a context back to the caller, then the caller can call Scale(), Rotate(), etc. on those "objects".
from openvg.
Here's an idea -- instead of directly adding support for scaling images, what about giving users a canvas-like object (opaque pointer) that they can then scale, rotate, translate, etc. and then place within other canvases? I think this is how other 2D toolkits like MagickWand and GD do it. In fact, even without scaling, the ability to compose canvases within canvases would be very useful on its own.
from openvg.
You can scale images in OpenVG, OpenVG just uses different matrices to store the transformation of paths and images. For example that code would do it and then reset the matrix you're currently modifying to the one applied to paths.
vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
Scale(scale, scale);
vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
from openvg.
After playing some hours with openvg I found the following solution. A change in libshapes.c.
void Image(VGfloat x, VGfloat y, int w, int h, char *filename) {
VGImage img = createImageFromJpeg(filename);
#if 0 //vgSetPixels paints directly without scale and transform
vgSetPixels(x, y, img, 0, 0, w, h);
#else //vgDrawImage is better
vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
vgTranslate(x, y);
vgDrawImage(img);
vgTranslate(-x, -y);
vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
#endif
vgDestroyImage(img);
}
It does break older code, because this way translate and scale do work on images too.
Hope it helps someone...
Greetings Klaus
from openvg.
Hi klkl140 I have the same problem with scaling images, I modified libshape.c with your code but the image is not scaled :( Any suggestions?
Thanks!!
EDIT: Solve :)
from openvg.
HI @LucaSoldi and @klkl140 ,
I am looking for a solution to scale the image from res 1920x1080 to 320x240.
@LucaSoldi you did commented above that the in first try it didn't worked for you but later you solved it.
Can you guys provide some insight, perhaps some code sharing on how this is done.
Regards,
Gurtaj
from openvg.
from openvg.
Hi @klkl140 ,
I was going through openvg bug list and found you comments.
https://github.com/ajstarks/openvg/issues/3
When I do the change in libshapes.c.
void Image(VGfloat x, VGfloat y, int w, int h, char *filename) {
VGImage img = createImageFromJpeg(filename);
#if 0 //vgSetPixels paints directly without scale and transform
vgSetPixels(x, y, img, 0, 0, w, h);
#else //vgDrawImage is better
vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
vgTranslate(x, y);
vgDrawImage(img);
vgTranslate(-x, -y);
vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
#endif
vgDestroyImage(img);
}
I always see full size Image.
Thanks,
Gurtaj
from openvg.
Are you scaling the VG_MATRIX_IMAGE_USER_TO_SURFACE matrix? If not then drawn images won't get scaled (see jamazerto's post above). By default the matrix to be altered is VG_MATRIX_PATH_USER_TO_SURFACE which only affects how paths are transformed.
OpenVG uses 5 separate matrices, VG_MATRIX_PATH_USER_TO_SURFACE to transform paths (which are used to draw the various shapes) and VG_MATRIX_IMAGE_USER_TO_SURFACE to transform images (the others transform the fill and stroke paints and text glyphs).
from openvg.
HI @paeryn
As mentioned in the code snippet above I am using exact these changes in libshape.c
void Image(VGfloat x, VGfloat y, int w, int h, char *filename) {
VGImage img = createImageFromJpeg(filename);
#if 0 //vgSetPixels paints directly without scale and transform
vgSetPixels(x, y, img, 0, 0, w, h);
#else //vgDrawImage is better
vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
vgTranslate(x, y);
vgDrawImage(img);
vgTranslate(-x, -y);
vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
#endif
vgDestroyImage(img);
}
Remember I want to scale down the image from resolution 1920x1080 to 320x240.
from openvg.
Related Issues (20)
- Performance optimizations HOT 1
- Move scaling origin point ? HOT 1
- followed the instructions for shapedemo
- How do I print a text in front of a video that is played in omxplayer? HOT 2
- Golang make failed HOT 3
- * Failed to add service - already in use? When openGL driver is enabled. HOT 2
- Degree sign doesn't get rendered HOT 6
- Segfault error when drawing emoji HOT 1
- [Suggestion] Changing CGO flags on Raspbian Stretch HOT 1
- OpenVG Crash with recent firmwares... HOT 7
- PI4 support HOT 9
- Inconsistency on Circle/CircleOutline third parameter HOT 1
- Python version?
- Multiple instances one over other
- Screen recording?
- How to rotate an image, with specific rotation
- End() fails after a finish() and a init(). I'm trying to go back and forth from and to the raw terminal
- Animation HOT 1
- How to paint a circle HOT 10
- ttf-dejavu-core No more for RPi.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from openvg.