()
| 1203 | } |
| 1204 | |
| 1205 | const renderGIF = async () => { |
| 1206 | let filters = {brightness, contrast, hue, saturation, lightness, blur, sharpen, pixelate} |
| 1207 | if ((abloop || functions.filtersOn(filters) || functions.rateOn({speed, reverse})) && animationData) { |
| 1208 | const adjustedData = functions.animationSpeed(animationData, speed) |
| 1209 | const totalFrames = adjustedData.length |
| 1210 | const duration = getDuration() |
| 1211 | let startIndex = 0 |
| 1212 | let endIndex = totalFrames - 1 |
| 1213 | |
| 1214 | if (abloop) { |
| 1215 | const startTime = (duration / 100) * loopStart |
| 1216 | const endTime = (duration / 100) * loopEnd |
| 1217 | const interval = duration / totalFrames |
| 1218 | |
| 1219 | startIndex = Math.floor(startTime / interval) |
| 1220 | endIndex = Math.floor(endTime / interval) |
| 1221 | startIndex = Math.max(0, startIndex) |
| 1222 | endIndex = Math.min(totalFrames - 1, endIndex) |
| 1223 | } |
| 1224 | |
| 1225 | let sliced = adjustedData.slice(startIndex, endIndex + 1) |
| 1226 | |
| 1227 | if (reverse) sliced = sliced.reverse() |
| 1228 | |
| 1229 | let frames = [] as ArrayBuffer[] |
| 1230 | let delays = [] as number[] |
| 1231 | |
| 1232 | for (let i = 0; i < sliced.length; i++) { |
| 1233 | let clientWidth = animationRef.current?.clientWidth! |
| 1234 | let clientHeight = animationRef.current?.clientHeight! |
| 1235 | |
| 1236 | frames.push(functions.render(sliced[i].frame, filters, {clientWidth, clientHeight})) |
| 1237 | delays.push(sliced[i].delay) |
| 1238 | } |
| 1239 | |
| 1240 | return functions.encodeGIF(frames, delays, |
| 1241 | animationData[0].frame.width, animationData[0].frame.height) |
| 1242 | } else { |
| 1243 | return fetch(originalSrc!).then((r) => r.arrayBuffer()) |
| 1244 | } |
| 1245 | } |
| 1246 | |
| 1247 | const download = useEffectEvent(async () => { |
| 1248 | let defaultPath = originalSrc ?? "" |
no test coverage detected