Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
matrix-media-repo
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
matrix-media-repo
Commits
2d8f5a52
Unverified
Commit
2d8f5a52
authored
4 years ago
by
Sorunome
Browse files
Options
Downloads
Patches
Plain Diff
better handle frames
parent
f8aa489e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
controllers/thumbnail_controller/thumbnail_resource_handler.go
+12
-25
12 additions, 25 deletions
...ollers/thumbnail_controller/thumbnail_resource_handler.go
with
12 additions
and
25 deletions
controllers/thumbnail_controller/thumbnail_resource_handler.go
+
12
−
25
View file @
2d8f5a52
...
@@ -5,7 +5,6 @@ import (
...
@@ -5,7 +5,6 @@ import (
"errors"
"errors"
"fmt"
"fmt"
"image"
"image"
"image/color"
"image/draw"
"image/draw"
"image/gif"
"image/gif"
"io"
"io"
...
@@ -240,23 +239,29 @@ func GenerateThumbnail(media *types.Media, width int, height int, method string,
...
@@ -240,23 +239,29 @@ func GenerateThumbnail(media *types.Media, width int, height int, method string,
// Prepare a blank frame to use as swap space
// Prepare a blank frame to use as swap space
frameImg
:=
image
.
NewRGBA
(
image
.
Rectangle
{
image
.
Point
{
0
,
0
},
image
.
Point
{
g
.
Config
.
Width
,
g
.
Config
.
Height
}})
frameImg
:=
image
.
NewRGBA
(
image
.
Rectangle
{
image
.
Point
{
0
,
0
},
image
.
Point
{
g
.
Config
.
Width
,
g
.
Config
.
Height
}})
// make sure the image is transparent at the start
draw
.
Draw
(
frameImg
,
frameImg
.
Bounds
(),
image
.
Transparent
,
image
.
ZP
,
draw
.
Src
)
for
i
:=
range
g
.
Image
{
for
i
:=
range
g
.
Image
{
img
:=
g
.
Image
[
i
]
img
:=
g
.
Image
[
i
]
var
disposal
byte
var
disposal
byte
if
g
.
Disposal
==
nil
{
if
g
.
Disposal
==
nil
{
// go 1.14
disposal
=
0
disposal
=
0
}
else
{
}
else
{
disposal
=
g
.
Disposal
[
i
]
disposal
=
g
.
Disposal
[
i
]
}
}
var
previousImg
draw
.
Image
// if disposal type is 1 (preserve previous frame) we can get artifacts from re-scaling
// as such, we re-render those frames to disposal type 0 (start with a transparent frame)
// see https://www.w3.org/Graphics/GIF/spec-gif89a.txt
if
disposal
==
1
{
g
.
Disposal
[
i
]
=
0
}
else
{
draw
.
Draw
(
frameImg
,
frameImg
.
Bounds
(),
image
.
Transparent
,
image
.
ZP
,
draw
.
Src
)
}
var
previousFrameImg
draw
.
Image
if
disposal
==
3
{
if
disposal
==
3
{
previousImg
=
image
.
NewRGBA
(
g
.
Image
[
0
]
.
Bounds
())
previous
Frame
Img
=
image
.
NewRGBA
(
frameImg
.
Bounds
())
draw
.
Draw
(
previousImg
,
frameImg
.
Bounds
(),
frameImg
,
image
.
ZP
,
draw
.
Over
)
draw
.
Draw
(
previous
Frame
Img
,
frameImg
.
Bounds
(),
frameImg
,
image
.
ZP
,
draw
.
Over
)
}
}
// Copy the frame to a new image and use that
// Copy the frame to a new image and use that
...
@@ -274,24 +279,6 @@ func GenerateThumbnail(media *types.Media, width int, height int, method string,
...
@@ -274,24 +279,6 @@ func GenerateThumbnail(media *types.Media, width int, height int, method string,
targetImg
:=
image
.
NewPaletted
(
frameThumb
.
Bounds
(),
img
.
Palette
)
targetImg
:=
image
.
NewPaletted
(
frameThumb
.
Bounds
(),
img
.
Palette
)
draw
.
FloydSteinberg
.
Draw
(
targetImg
,
frameThumb
.
Bounds
(),
frameThumb
,
image
.
ZP
)
draw
.
FloydSteinberg
.
Draw
(
targetImg
,
frameThumb
.
Bounds
(),
frameThumb
,
image
.
ZP
)
g
.
Image
[
i
]
=
targetImg
g
.
Image
[
i
]
=
targetImg
// determine how to dispose the frame
// see https://www.w3.org/Graphics/GIF/spec-gif89a.txt
if
disposal
==
0
{
// Clear the transparency of the previous frame
draw
.
Draw
(
frameImg
,
frameImg
.
Bounds
(),
image
.
Transparent
,
image
.
ZP
,
draw
.
Src
)
}
else
if
disposal
==
1
{
// do nothing
}
else
if
disposal
==
2
&&
g
.
Config
.
ColorModel
!=
nil
{
// restore background color
background
:=
g
.
Config
.
ColorModel
.
(
color
.
Palette
)[
g
.
BackgroundIndex
]
if
background
!=
nil
{
draw
.
Draw
(
frameImg
,
frameImg
.
Bounds
(),
image
.
NewUniform
(
background
),
image
.
ZP
,
draw
.
Src
)
}
}
else
if
disposal
==
3
&&
previousImg
!=
nil
{
// restore previous frame
draw
.
Draw
(
frameImg
,
frameImg
.
Bounds
(),
previousImg
,
image
.
ZP
,
draw
.
Over
)
}
}
}
// Set the image size to the first frame's size
// Set the image size to the first frame's size
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment