It is currently Fri Jun 22, 2018 12:58 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: GIF frame issue
PostPosted: Sun May 07, 2017 1:22 pm 
Offline
Addict
Addict

Joined: Sat Mar 02, 2013 9:17 am
Posts: 931
I will output a GIF frame with invisible color, i must set #PB_2DDrawing_AlphaBlend, this is clear
Set i this not, i get ever a black background
On the first 560 betas i have get back and visible the real used invisible color from each frame
I think only this is correct
For pre processing GIF frames same sprites it is more as helpfull i can get (and see) the used invisible color from each frame
With a black replaced invisible color i can do absolutely nothing, other GIF colors can also be black
So, i self will say, this is a bug

Code:
UseGIFImageDecoder()

EnableExplicit

Define path$=OpenFileRequester("Select a GIF", "", "", 0)

Define gif_ID=LoadImage(#PB_Any, path$)

Define frame_ID=CreateImage(#PB_Any, ImageWidth(gif_ID), ImageHeight(gif_ID), 32, $FF)

SetImageFrame(gif_ID, 0)
StartDrawing(ImageOutput(frame_ID))
; DrawingMode(#PB_2DDrawing_AlphaBlend) ; Activate this line
DrawImage(ImageID(gif_ID), 0, 0)
StopDrawing()

OpenWindow(#PB_Any, #PB_Ignore, #PB_Ignore, ImageWidth(gif_ID), ImageHeight(gif_ID), "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

ImageGadget(1, 0 , 0, ImageWidth(gif_ID), ImageHeight(gif_ID), ImageID(frame_ID))

Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow

_________________
http://www.nachtoptik.de


Last edited by walbus on Wed Nov 01, 2017 11:51 am, edited 4 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: GIF frame issue
PostPosted: Tue Jul 11, 2017 3:51 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 13304
Location: France
You need to use DrawAlphaImage() if you want transparency


Top
 Profile  
Reply with quote  
 Post subject: Re: GIF frame issue
PostPosted: Tue Jul 11, 2017 4:50 pm 
Offline
Addict
Addict

Joined: Sat Mar 02, 2013 9:17 am
Posts: 931
Yep,
thanks for your answer
But this i mean not, i mean, i will see the original colors from the Gif
I need see or get the as invisible declared color for further processing

_________________
http://www.nachtoptik.de


Top
 Profile  
Reply with quote  
 Post subject: Re: GIF frame issue
PostPosted: Tue Jul 11, 2017 5:09 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 13304
Location: France
I can't follow you here. Could you post a GIF and tell me what you expect ?


Top
 Profile  
Reply with quote  
 Post subject: Re: GIF frame issue
PostPosted: Tue Jul 11, 2017 5:24 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3142
Location: Netherlands
I think what he means is that if the transparent index is set to 12 and the RGB palette entry for that index is $123456, the decoded RGBA color for a transparent pixel would be $00123456 (the original palette entry RGB color with alpha set to 0) instead of $00000000 (both alpha and RGB set to 0) .

_________________
MacOS 10.13 High Sierra, PB 5.60 x64


Top
 Profile  
Reply with quote  
 Post subject: Re: GIF frame issue
PostPosted: Tue Jul 11, 2017 5:45 pm 
Offline
Addict
Addict

Joined: Sat Mar 02, 2013 9:17 am
Posts: 931
Many thanks Wilbert
For my this is a (little) problem for post processing Gif with BF
Posting a Gif sample is so not good available, i can not make it visible

As sample, i load a Gif, then i make from the Gif frames automatically masked sprites (shapes)

On BF i use Gif frames equal masked sprites, so i want the mask color (the as invisible declared color) from each frame

Or i make a CSS sheet from the Gif, for the sheet, its nice, i can get the invisible color for each tile
Can i this not, i must self looking for a unused color, for making the sheet

Can i simple get the original used invisible color from this Gif for each frame, i can set this color as mask color for my new created shapes or sheets

Can i not get the invisible color, i must looking for a not used color on this frame (or the complete Gif) or i become "Holes" in my sprites

BF make mostly Gif outputs not directly as alpha image, only for simple and fast outputs, mostly BF use the frames equal a masked sprite
Can i not get the mask color, i can not good handle the Gif frame as sprite

On PB560 B1 with the little code above, the frames was without using as alpha image complete visible, with the as invisible declared mask color

Have i created a sheet with 560B1, with the code above, each tile was visible with the as invisible declared color
On PB560 final, i see not a way for making visible the as invisible declared color

Can i this again, i can improve simple many things with Gif very nice on BF

I will not use a self maked code for grabbing the invisible color from the frames
I need a full PB compatible solution for getting the invisible color from the frames, i think...

_________________
http://www.nachtoptik.de


Top
 Profile  
Reply with quote  
 Post subject: Re: GIF frame issue
PostPosted: Thu Jul 13, 2017 4:31 pm 
Offline
PureBasic Bullfrog
PureBasic Bullfrog
User avatar

Joined: Wed Jul 06, 2005 5:42 am
Posts: 7971
Location: Kelowna, BC, Canada
Could you please post a sample containing at least one gif with undesirable results along with a description of the expected result? You're skilled in this subject but the language barrier is preventing you from being fully understood here. (by me at least)

_________________
Veni, vidi, vici.


Top
 Profile  
Reply with quote  
 Post subject: Re: GIF frame issue
PostPosted: Thu Jul 13, 2017 5:51 pm 
Offline
Addict
Addict

Joined: Sat Mar 02, 2013 9:17 am
Posts: 931
@netmaestro
Thanks for your post, please looking

Image

I use on BucketFill advanced Gif primary as sprites
So i must have the invisible color from each frame
Get i the Gif frames on PB560b1 without using DrawAlpha, i get the invisible color, this i correct

Get i on PB560 final the frames without alpha, i get ever a black background

So, on PB 560 final it's not available getting the invisible color from Gif frames

The Hound here has black points on his skin
Grabb i now the mask color from Pos x=0, y=0 (This is standard for sprites and CSS sheets and works with the mostly Gif at the same),
the points on the skin from the dog are "Holes" - The points are black and the mask is black

( Can i get on a other way the used invisible colors from the Gif frames, i can set self the background )

Is the mask color (invisible color) unknown, i must looking self for a alterable uasble color

A other, can i obtain a state from each frame and see, it's a Gif without a invisible color, this is also important for
a Gif output as sprite
-------------------------------------------
Please looking here this demo video
http://www.quick-aes-256.de/Video/Sprite_and_GIF_1.mp4

The gear Gif on this demo has original a black background, it have not a invisible color !
I get simple the background color from the gear Gif, Point(0,0), and define this color as invisible color
This is cool, i ehance now the mask and can so also rotate the Gif over a textured background, with invisible color
And many more is available

I have uploaded a new BF to day, a last part, i will add more cool Gif Gimmicks
To time i make this with workarounds, this is OK, but i can make many more when i can get more info from a used Gif

Unfortunately, its a great leak for perfect and fast Gif handling

Looking, this little code make a sheet from any Gif
It is ok you should see ever the real background color on each frame
It is not ok, you see ever a black background all over

Code:
; - Demo - Create a CSS sprite sheet from a GIF image PB 5.60 => needed
; This code generate a complete sheet from a GIF and also a separately info file
; Primary created for using with Bucketfill advanced

UseGIFImageDecoder()
UsePNGImageEncoder()

EnableExplicit

Define gif_ID, sheet_ID, i, ii, iii, iiii, file, image_frame_delay
Define gif_width, gif_height, sheet_width, sheet_height, frames, frames_x, frames_y
Define path$

path$=OpenFileRequester("Select a GIF picture", "", "", 0)
If path$="" Or UCase(GetExtensionPart(path$))<>"GIF": End : EndIf

gif_ID=LoadImage(#PB_Any, path$) ; Sprite mode

gif_width=ImageWidth(gif_ID)
gif_height=ImageHeight(gif_ID)
frames=ImageFrameCount(gif_ID)
If gif_height>gif_width And frames>1
  frames_x=Sqr(frames)+1
Else
  frames_x=Sqr(frames)
EndIf
frames_y=frames/frames_x+1
sheet_width=frames_x*gif_width
sheet_height=frames_y*gif_height

For i=0 To frames-1
  iiii=iii : ii+gif_width
  If ii=>sheet_width
    ii=0 : iii+gif_height
  EndIf   
Next i
ii=0 : iii=0

sheet_height=iiii+gif_height

sheet_ID=CreateImage(#PB_Any, sheet_width, sheet_height)

For i=0 To frames-1
  SetImageFrame(gif_ID, i)
  StartDrawing(ImageOutput(sheet_ID))
  DrawImage(ImageID(gif_ID), ii, iii)
  StopDrawing()
  ii+gif_width
  If ii=>sheet_width
    ii=0 : iii+gif_height
  EndIf   
Next i
ii=0 : iii=0

FreeImage(sheet_ID)

sheet_ID=CreateImage(#PB_Any, sheet_width, sheet_height)

ii=0 : iii=0
For i=0 To frames-1
  SetImageFrame(gif_ID, i)
  image_frame_delay=GetImageFrameDelay(gif_ID)
  If Not image_frame_delay : image_frame_delay=100 ; Delay 0 works not, so as a standard, delay 0 = delay 100
                                                   ; ElseIf image_frame_delay<30 : image_frame_delay=30 ; Browsers can or will mostly not handle a delay <30ms
  EndIf
  StartDrawing(ImageOutput(sheet_ID))
  ; DrawAlphaImage(ImageID(gif_ID), ii, iii)
  DrawImage(ImageID(gif_ID), ii, iii) ; Now you should see the realy background colors from any frames ###################################
  StopDrawing()
  ii+gif_width
  If ii=>sheet_width
    ii=0 : iii+gif_height
  EndIf   
Next i

SaveImage(sheet_ID, GetPathPart(path$)+GetFilePart(path$, #PB_FileSystem_NoExtension)+".png", #PB_ImagePlugin_PNG, 10, 24)

_________________
http://www.nachtoptik.de


Last edited by walbus on Wed Nov 01, 2017 11:53 am, edited 7 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: GIF frame issue
PostPosted: Thu Jul 13, 2017 7:11 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Oct 09, 2010 3:47 am
Posts: 1443
Hi walbus,

The process should be relatively easy using script from either netmaestro's GIF Workshop or my GIF Toolkit (GIFs by ORBO).
- get the transparent index for each frame
- decode the LZW data for each frame
- get the transparent color at the index from the decoded data for each frame

I am sure netmaestro will provide a more detailed answer, but I thought this could get you started.

_________________
ImageMy PureBasic Stuff - Unfinished


Top
 Profile  
Reply with quote  
 Post subject: Re: GIF frame issue
PostPosted: Thu Jul 13, 2017 7:43 pm 
Offline
Addict
Addict

Joined: Sat Mar 02, 2013 9:17 am
Posts: 931
Hi JHPJHP
Many thanks for your answer
Yep, thanks, primary, this is the solution
Gif is Devils Work, I was concerned about possible incompatibility with LibGif Fred has used

For an easy-to-use and well-functioning solution, I'm grateful, quite honestly, I'm missing the moment the motivation me to explain the internal gif structureur

_________________
http://www.nachtoptik.de


Top
 Profile  
Reply with quote  
 Post subject: Re: GIF frame issue
PostPosted: Thu Jul 13, 2017 10:11 pm 
Offline
PureBasic Bullfrog
PureBasic Bullfrog
User avatar

Joined: Wed Jul 06, 2005 5:42 am
Posts: 7971
Location: Kelowna, BC, Canada
I don't think it's practical to try a workaround here, it's best to just report a bug to Fred on this.

Why? because the transparent color is stored and used not as a colorref but as an index. To handle it properly you must have access to:

1. The transparent color index for the frame
2. The size of the colortable used by the frame (1-256). This is found in the Logical Screen Descriptor for global colortables, or the Graphics Control Extension for local.
3. The colortable used by the frame. This could be either local (frame-based) or global.
4. The array of colortable indexes in the body of the image

Fred can't just provide a command like ImageFrameTransparentColor(<frame ID>) and leave it at that, it would be too unreliable. This is because all too often, gif authors will repeat the transparent color in another index. When this happens and you draw transparency by color alone, garbled images are the result. Everything must be drawn by index so that transparency is only applied where the transparent color index is found in the array of indexes representing the body of the image. And so all that stuff must be available.

You can readily see that in order to have access to all this data, you're pretty much writing your own gif decoder from scratch. Best to let Fred sort this out on his end with the gif lib he's using.

_________________
Veni, vidi, vici.


Top
 Profile  
Reply with quote  
 Post subject: Re: GIF frame issue
PostPosted: Fri Jul 14, 2017 5:41 am 
Offline
Addict
Addict
User avatar

Joined: Sat Oct 09, 2010 3:47 am
Posts: 1443
Hi walbus,

Everything netmaestro previously said is correct; it would need to be expanded to a complete decoder like the example gif_decode.pb found in my GIF Toolkit, but then the Function UseGIFImageDecoder becomes redundant.

_________________
ImageMy PureBasic Stuff - Unfinished


Last edited by JHPJHP on Tue Feb 27, 2018 5:25 am, edited 6 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: GIF frame issue
PostPosted: Fri Jul 14, 2017 7:51 am 
Offline
Addict
Addict

Joined: Sat Mar 02, 2013 9:17 am
Posts: 931
Hi netmaestro and JHPJHP

Many thanks for your very helpfull answers

Yep, Gif is Devils Work LOL

Its a very complicated thing and many Gif internal strange

I hope Fred make a fix, this is the best way, i make now a official bug report

Handling Gif as sprites or shapes has a lot advantages, it open a great door

Best regards Werner

_________________
http://www.nachtoptik.de


Top
 Profile  
Reply with quote  
 Post subject: Re: GIF frame issue
PostPosted: Tue Jan 23, 2018 11:12 pm 
Offline
PureBasic Team
PureBasic Team
User avatar

Joined: Fri Apr 25, 2003 6:14 pm
Posts: 1559
Location: Germany (Saxony, Deutscheinsiedel)
Moved to Bug-Reports for further investigations.
See the comments of netmaestro and JHPJHP, which seems to proof that there is a problem...

I'm trying a translation of a short german description which should contain a "summary" according to this "bug":
- PB handles GIF frames like PNG pictures with alpha-channel
- every GIF frame can have an invisible color, just like sprites
- the programmer must output the GIF always with alpha-channel to have a transparent background
- if he doesn't output the GIF frame as alpha image, the transparent background will always be replaced with the color black (<= this is the bug!)
- the background color exists, so replacing it with black isn't the right way...
- if a GIF has the black color as visible part of the image, you will get holes in the GIF when using it as Sprite
- one example is the "Hound_1.gif" included in the BucketFill package - if you want to output this as Sprite, then the hound is full of holes

- the "bug" seems to be in the PB5.60 final, but was not in the PB5.60 beta1

Hope this helps! 8)

_________________
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye