Gif player
hi i made a gif player which load and play gifs as fast as possible you can create a gif like:
local gif = gifCreate(file_path or gif_buffer) -- "logo.gif" for example
local size = Vector2(dxGetMaterialSize(gif))
addEventHandler("onClientRender",getRootElement(),function()
if isElement(gif) then
dxDrawImage(0,0,size,gif)
end
end)
cuz it is a texture element you can use it, inside shaders or inside all dx related functions
Thanks for the pull request! Cool idea!
I'm wondering if there is an open source Gif loader library out there that we could use instead of implementing the intricacies ourselves, thinking from a future maintainability and security perspective.
Great. But I think you should use the new Lua parser.
Thanks for the pull request! Cool idea!
I'm wondering if there is an open source Gif loader library out there that we could use instead of implementing the intricacies ourselves, thinking from a future maintainability and security perspective.
yeah we can i just used https://github.com/hidefromkgb/gif_load and made it a little better because it needed some changes. you can go and see the real code. it is from @hidefromkgb i thought that we must write code like this this is my first time trying to contribute mta-blue
is there any other problems that i should solve?
In my opinion your solution is over engineered, instead i propose to make "createGif" returns a regular texture ( texture atlas ) + number of frames.
it does. it will return a texture element that is gif and if you want to get frames you can use gifGetFrameCount(element gif)
and also it has a player that you can play or stop or you can set its speed too
for example:
local gif = gifCreate("img.gif")
local width,height = dxGetMaterialSize(gif)
-- you can adjust the delay of each frame
local newDelay = 5 -- ms : 5*(10^-3) s
-- 5 ms can make gif really fast!
local frameCount = gifGetFrameCount(gif)
for frame = 1,frameCount do -- for all frames
gifSetFrameDelay(gif,frame,newDelay)
end
--
gifPlay(gif) -- play the gif
addEventHandler("onClientRender",root,function()
if isElement(gif) then
dxDrwaImage(0,0,width,height,gif)
end
end)
it s really not that hard!
in my opinion these all functions are useless, it is trivial to calculate what frame should be displayed and calculating uv coors is not a rocket science
but i think they can be useful ! for example imagine you are writing a phone script and you have an application like *whatsapp for making that you have 2 ways: 1- using browser -- which is hard to load on weak computers (that in some countries most of the people who are playing MTA have) 2- using dx functions if you choose the dx interface you need some functions that will allow you to control your gifs and many other ideas that scripters can have when they want to use dx functions instead of browser
but your opinion is respected and if you want we can remove them
IMHO, half useless function. There aren't any questions about implementation for this. But, sorry, all world is trying to move out from GIF to APNG, WEBP, and Lottie of course, modern things for today. Even huge GIF hostings are storing GIFs in MP4 format.
Ok
well i removed useless functions. the functions that have been removed are:
gifGetTick(element [gif (dx material)]); -> int, boolean
gifGetFormat(element [gif (dx material)]); -> string, boolean
gifGetFrameDelay(element [gif (dx material)], int [frame index]); -> int, boolean
gifSetFrameDelay(element [gif (dx material)], int [frame index], int [delay]); -> boolean
gifGetShowingFrame(element [gif (dx material)]); -> int
gifGetFrameDefaultDelay(element [gif (dx material)], int [frame index]); -> int
gifGetFrameCount(element [gif (dx material)]); -> int
and the remaining functions are:
gifCreate(string [path or rawdata]); -> gif element (dx material) -- this function creates a gif element
gifPlay(element [gif (dx material)]); -> boolean -- this function plays the gif if it is stopped
gifStop(element [gif (dx material)]); -> boolean -- this function stops the gif if it is playing
gifNavigateToThumbnail(element [gif (dx material)]); -> boolean -- this function shows the first frame
isGifPlaying(element [gif (dx material)]); -> boolean -- this function checks if gif is playing or not
i hope it will be ok this time!
Maybe implementing gifSetShowingFrame instead of gifNavigateToThumbnail will be better. And isGifPlaying should be gifIsPlaying
for gifSetShowingFrame i think gif player needs some functions like gifGetShowingFrame & gifGetFrameCount
but i removed them cuz your friends said it should be simple
i can return them if you want
and isGifPlaying changed to gifIsPlaying!
gifPlay
then, maybe we can specify the first frame in gifPlay or gifStop, in this way gifNavigateToThumbnail can be removed.
then can i return gifGetFrameCount and gifGetShowingFrame?
then can i return
gifGetFrameCountandgifGetShowingFrame?
maybe gifGetDetails, or gifGetProperty/gifSetProperty
ah yeah your right this one is better i will do it now
ah yeah your right this one is better i will do it now
gifGetProperty(gif,"delay") gifSetProperty(gif,"delay",100)
delay works per frame
i mean each frame has a different delay like gifSetFrameDelay(gif, frame, delay)
what should we do for it?
delay works per frame i mean each frame has a different delay like
gifSetFrameDelay(gif, frame, delay)
then, maybe gifSetProperty(gif,frame,"delay",100) for frame property. If frame is not specified, the property will be global
aha ok after 30 minutes i finish them
and i think it is better we set showing frame with gifSetProperty(gif,"showing_frame",frameindex) too
whats your opinion? isn't it better?
and i think it is better we set showing frame with
gifSetProperty(gif,"showing_frame",frameindex)too whats your opinion?
Good idea
In this way, gifCreate, gifPlay, gifStop and gifIsPlaying will be mainly used functions. For rarely used functions, we can just use gifSetProperty/gifGetProperty.
Better to use new lua parser. Refer to #2535
gifGetProperty return types are string or number
how should i return something like that when im using new lua parser?
gifGetPropertyreturn types are string or number how should i return something like that when im using new lua parser?
for example: std::variant<bool, CLuaMultiReturn<char, char>>
and you can even use this for passing arguments: std::variant<bool, float> argumentN