-
Mar 7th, 2018, 01:31 PM
#1
vbRichClient Animated GIF
hi
Is it possible to play an animated GIF using vbRichClient (RC5) ?
-
Mar 8th, 2018, 05:39 AM
#2
Re: vbRichClient Animated GIF
I don't know if RC5 can play GIF, but in the following thread posted by Olaf, the 9th tutorial "usage of vbIPictureDisp" shows an example of playing a GIF:
http://www.vbforums.com/showthread.p...BaseInterfaces
Last edited by dreammanor; Mar 8th, 2018 at 08:48 AM.
-
Mar 10th, 2018, 05:39 AM
#3
Re: vbRichClient Animated GIF
Originally Posted by dreammanor
Yep, the one under the link you've posted is using GDI+ to decode the Gif-Frames from an animated Gif.
@reexre
One can decode GIF-Frames from an animated GIF with relative ease, using:
- "any single-frame-GIF-decoder, which can load from ByteArrays"
- by detecting (parsing) all the Frame-Header-Offsets (of the frames which follow the "BaseFrame") within the ByteContent
- and then simply "shifting" the follow-up-frames into the position of the first frame (in a copy of the Gif-ByteArray), via memcopy
- then performing the normal "single-gif-decoding - and simply repeating that for any further "follow-up-frames"
So, with the above described approach you can avoid, having to write "the complete GIF-decoder yourself"
(it still involves a bit of parsing though - but comparably much less code is needed).
Below comes an example, which is using the approach in a small cGifFrames.cls, which is able to read out any Frame in a Gif as a cCairoImageSurface:
Here is the Demo-Zip (updated):
GifFrames.zip
The above is also using a fast caching-mechanism, to reduce CPU-load (and mem-consumption) with larger GIFs like these:
http://vbRichClient.com/Downloads/MoebiusAnim.gif
http://vbRichClient.com/Downloads/SpiralAnim.gif
(the two larger Gifs above are not included in the Zips \Res\-subfolder, but copying them into it is recommended,
to see the quite large influence of the built-in JPG-cache "in action").
Edit: Had to update the Zip, due to a length-calculation-error for the target ByteArray, which is now fixed.
Olaf
Last edited by Schmidt; Mar 10th, 2018 at 06:39 AM.
-
Mar 10th, 2018, 12:47 PM
#4
Re: vbRichClient Animated GIF
Thank you very much!!!
BTW on Vista there some little background problem:
later I will look deeper at the code.
-
Mar 11th, 2018, 03:03 AM
#5
Re: vbRichClient Animated GIF
I tested Olaf's code and it works very well on both Win10 and XP.
-
Mar 11th, 2018, 07:24 AM
#6
New Member
Re: vbRichClient Animated GIF
hi,
I am just a beginner in Cairo programming, so I would like to make the background of my UserControl transparent. The BackStyle is set to 0 - so the UserControl is transparent but if I paint a Cairo.CreateSurface Content into it then the source color is used to fill the background.
I would like to make the background transparent, do you have any idea how I can make it?
-
Mar 11th, 2018, 09:14 AM
#7
Re: vbRichClient Animated GIF
Originally Posted by PaulF
hi,
I am just a beginner in Cairo programming, so I would like to make the background of my UserControl transparent. The BackStyle is set to 0 - so the UserControl is transparent but if I paint a Cairo.CreateSurface Content into it then the source color is used to fill the background.
I would like to make the background transparent, do you have any idea how I can make it?
Here is an example, which is using the normal VB6-UserControl-Engine in conjunction with Cairo-drawing-calls.
The "trick" is basically, to (finally) use the GDI-AlphaBlend-call, to get the (premultiplied) alpha-content of Cairo-Surfaces
onto the UserControl.hDC (in a "non-destructive" way with regards to the Alpha-channel).
http://www.vbforums.com/showthread.p...iro-Rendering)
Though whilst that does work, the old VB6-UserControl-engine is (IMO) a pain to work with
(not only with regards to "how it handles alpha and transparencies")...
There is also a lot of Event-Support missing (as e.g. MouseEnter/MouseLeave, MouseWheel, etc.).
And the matter of "siting" (instancing) a Control on other containers is also quite clumsily solved,
when you work in the IDE...
All that (quite unnecessary) closing/reopening of VB6-UCs can be avoided, when you host your
Controls in normal VB6-Classes... I'd suggest to take a good look at the Cairo-Widget-Tutorials:
http://vbrichclient.com/#/en/Demos/GUI/
An RC5 cwWidget-Class does offer everything (Event-wise), which a VB6-UserControl offers (and more)
and is quite compatible (MoseMove, KeyDown, Paint, Resize, etc.) - and it can interact directly
with a Cairo-Drawing-Context in its Paint-Event (including full support for nested Alpha-Renderings).
Not sure, what type of Control (or Widget) you plan to implement - though I'd suggest that you use
the RC5-WidgetEngine for that - and then aksing more specific questions in their own thread.
Happy cairo-coding...
Olaf
-
Mar 11th, 2018, 09:45 AM
#8
Re: vbRichClient Animated GIF
Originally Posted by reexre
BTW on Vista there some little background problem...
A Gif-Image which is loaded into a Cairo-Surface:
1) is using the VB6-Runtime-LoadPicture (OleAut-LoadPicture) in a first step for decoding
2) the resulting StdPicture is then rendered onto a "temporary hDC" (which was priorily filled with magenta)
3) the Pixels of that temporary hDC/DIB-combination are then "transferred" into a Cairo-Surface in a loop
4) all magenta-colored Pixels being replaced with proper "Alpha=0" Bytes
5) once the GIF was transferred into such a "normal" Cairo-Image-Surface, you can save it from there e.g. as a PNG or as an "Alpha-JPG" (with the appropriate methods)
What I suspect (from your ScreenShot) is, that Vista "messes up" in steps 2->3 above.
(the interaction of the Vista-Glass-DX-surfaces with GDI-Blit-calls is - in my understanding -
quite different to what MS later has significantly improved in the Win7-rendering-engine).
Not sure, whether "trying to find or solve that directly in the RC5" is worthwhile (I have no Vista-VM here to go directly at it) -
when perhaps even a Vista- or DirectX-Upgrade or -ServicePack might solve the problem for you.
I've tested it now on two different XP-VMs as well (in two modes, with 16bit-Color-resolution, as well as in 32Bit) -
and no problems there... (with the above described "magenta-based blitting-workaround").
Also not sure, what you want to do in the end (with those GIFs) or what your scenario is...
If it's only for "shipping your own animated resources", then why not simply use the code as shown,
to decode all the GIF-animation-frames into a sequence of "Image-ByteArray-Blobs",
which you then could save (in either PNG- or Alpha-JPG-format) within e.g. a "single SQLite-DB-Table" (of -File).
The size of such a single-file-SQLite-DB could very well end up being (much) smaller than the original GIF.
E.g. when I save all the frames of the "CatAnim.gif" as JPG-Blobs within such an SQLite-DB-File, it is only half as large as the GIF -
also the loading and rendering of these JPG-Blobs would be much faster (due to libJPG-Turbo-support in the RC5) -
and also no problems would happen on Vista, when you render from such a format...
Food for thought, I guess...
Olaf
-
Mar 11th, 2018, 10:23 AM
#9
New Member
Re: vbRichClient Animated GIF
Thank you very much, Olaf.
Ich will try it and I will get a look on the Cairo-Widget functionality.
Paul
-
Mar 11th, 2018, 01:36 PM
#10
New Member
Re: vbRichClient Animated GIF
Olaf,
I have implemented it to show SVG files in the UserControl:
Private Sub UserControl_Resize()
On Error Resume Next
If Not Ambient.UserMode Then Exit Sub
Set BBuf = Cairo.CreateWin32Surface(UserControl.ScaleWidth, UserControl.ScaleHeight)
BBufHDC = BBuf.GetDC
SVG.RenderFromDOM BBuf.CreateContext, 0, 0, UserControl.ScaleWidth, UserControl.ScaleHeight, 0
End Sub
Private Sub UserControl_Paint()
GdiAlphaBlend hDC, 0, 0, UserControl.ScaleWidth, UserControl.ScaleHeight, BBufHDC, 0, 0, UserControl.ScaleWidth, UserControl.ScaleHeight, 2 ^ 24 + &HFF0000 * 1#
End Sub
This is working well but a little bit slowly..
BTW: can insert any standard (UserControls, tables ...) components on a Cairo-Widget form? Or is it possible to insert cairo widget on standard form?
Paul
-
Mar 11th, 2018, 03:04 PM
#11
Re: vbRichClient Animated GIF
Originally Posted by PaulF
I have implemented it to show SVG files in the UserControl:
Yep, code looks good to me...
Originally Posted by PaulF
This is working well but a little bit slowly..
The UserControl_Paint Handler-code can't be optimized anymore performancewise...
So I guess your performance-problems "kreep in", when you re-render a given SVG in the UserControl_Resize-Handler...
SVG-renderings can be time-consuming (>10msec), in case their contentsize is >10-20KB or so
(usually the case, when they contain somewhat more complex things than "simple shape-outlines").
You could avoid this, when you render the SVG only *once* into an (factor 2-3) oversized Cairo-Surface (e.g. named SvgBufSrf).
Then in the UserControl_Resize-Handler you 'd use only a (much faster) downscaling of SvgBufSrf onto the BBuf-Surface you already have...
Code:
BBuf.CreateContext.RenderSurfaceContent SvgBufSrf, 0, 0, BBuf.Width, BBuf.Height
Originally Posted by PaulF
BTW: can insert any standard (UserControls, tables ...) components on a Cairo-Widget form?
Or is it possible to insert cairo widget on standard form?
As for WidgetHosting... the cWidgetForm-Classes are thought for "Widgets-Only-Mode".
The recommended way to integrate "a group of one or more Widgets into a normal VB-Form"
is based on a little (generic) Helper-Control (usually named ucPanel.ctl)...
I've recently described this here: http://www.vbforums.com/showthread.p...=1#post5268145
(posts, from #14 onwards...)
HTH
Olaf
-
Mar 11th, 2018, 03:20 PM
#12
New Member
Re: vbRichClient Animated GIF
Thanks a lot again, I would like to explain my task:
I have to provide solution to render up to 1000 svg control elements on one visualization page (vb form). The problem is that such surfaces need a lot of memory : my test vb application has used up 1 GByte memory for 500 svg controls...
The second problem is that the antialiasing fonts have a black border due the GdiAlphaBlend rendering method.
AA Font:
-
Mar 11th, 2018, 03:26 PM
#13
New Member
Re: vbRichClient Animated GIF
I have found solution for the AA Font problem:
Cairo.FontOptions = CAIRO_ANTIALIAS_GRAY
that seems to be good enought
-
Mar 11th, 2018, 04:35 PM
#14
Re: vbRichClient Animated GIF
Originally Posted by PaulF
I have to provide solution to render up to 1000 svg control elements on one visualization page (vb form).
The problem is that such surfaces need a lot of memory : my test vb application has used up 1 GByte memory for 500 svg controls...
If we assume, that a VB-Form covers a Screen-Pixel-area of "Full-HD" (1920x1080 Pixels) -
and further assume, that its whole area is covered with your UserControls, then the allocated
Memory from *all* the UserControls internal BBuf-Surfaces should not consume (in Sum) more
than those 1920x1020 Pixels...
(which is roughly 2MegaPixels and multiplied by "4Bytes per Pixel" would consume ~ 8MB total).
If you come up into regions of 1GB or more, then I assume that you've forgot to set the UC to:
UserControl.ScaleMode = vbPixels (in e.g. UserControl_Initialize)
If you don't have such a line in your Control, then you will resize (and then later scale and SVG-render)
everything to vbTwips, which would mean a mem-consumption which is 15^2 = 225 times larger than needed.
As for your ScreenShots (and my recommendation, to "pre-render" the SVGs).
If you have indeed such a huge amount of Controls, then the pre-rendering of those SVGs should happen
already in Form_Load (or Sub Main) - once, at App-Startup.
You would then create these "slightly oversized" SVG-Surface-Buffers once for each differing SVG-BackGround and -Scale.
Also the Text-Rendering (for the given different Scales) could happen in this "pre-creation-stage" at App-Startup.
These auto-generated "somewhat oversized Surface-Buffers" could be stored e.g. in the Cairo.ImageList under approriate StringKeys -
other prebuffered Surfaces you store there, could be the different "Arrow-Types", which you could pre-render as well.
Your UserControls would then only expose two differents "Public String-Properties":
- InstrumentBackGroundKey
- InstrumentArrowKey
Inside the Controls you would then only need to render directly from these pre-stored Image-Keys:
Code:
BBuf.CreateContext.RenderSurfaceContent Me.InstrumentBackGroundKey, 0, 0, BBuf.Width, BBuf.Height
BBuf.CreateContext.RenderSurfaceContent Me.InstrumentArrowKey, ...
HTH
Olaf
-
Mar 12th, 2018, 03:23 AM
#15
New Member
Re: vbRichClient Animated GIF
If we assume, that a VB-Form covers a Screen-Pixel-area of "Full-HD" (1920x1080 Pixels) -
and further assume, that its whole area is covered with your UserControls, then the allocated
Memory from *all* the UserControls internal BBuf-Surfaces should not consume (in Sum) more
than those 1920x1020 Pixels...
(which is roughly 2MegaPixels and multiplied by "4Bytes per Pixel" would consume ~ 8MB total).
If you come up into regions of 1GB or more, then I assume that you've forgot to set the UC to:
UserControl.ScaleMode = vbPixels (in e.g. UserControl_Initialize)
you right, I put the
UserControl.ScaleMode = vbPixels
in the UserControl_Initialize already.
Yes, the control consume about 1 MB in normal zoom but if I zoom in the form (up to 10000 x 5000 pixels) then all controls (i.e. 500 of them) consume much more memory.
I will optimalize the rendering of controls outside of the visible area to reduce the resources consumption.
I will try today your "prerendering" solution.
Thanks.
br
Paul
-
Mar 12th, 2018, 06:34 AM
#16
Re: vbRichClient Animated GIF
@Olaf
About vbMagenta Issue:
If it can be usefuel; Magenta background (on Vista) do not happens in first Frame. (Correct black background)
(it do not happens on CatAnim,gif and SpiralAnim.gif)
Anyway I'll follow your previous suggestions
-
Mar 13th, 2018, 02:48 PM
#17
Re: vbRichClient Animated GIF
@Olaf
Tested on Windows 7 (32bit)
Magenta issue here too !
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|