Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
沉迷打码的小凳子
glide
提交
8f80ee83
G
glide
项目概览
沉迷打码的小凳子
/
glide
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
glide
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8f80ee83
编写于
10月 12, 2014
作者:
S
Sam Judd
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Skip AnimatedGifEncoder for original GIFs.
Fixes #184.
上级
3c1ebe27
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
40 addition
and
1 deletion
+40
-1
library/src/androidTest/java/com/bumptech/glide/load/resource/gif/GifResourceEncoderTest.java
...ptech/glide/load/resource/gif/GifResourceEncoderTest.java
+20
-0
library/src/main/java/com/bumptech/glide/load/resource/gif/GifResourceEncoder.java
.../bumptech/glide/load/resource/gif/GifResourceEncoder.java
+20
-1
未找到文件。
library/src/androidTest/java/com/bumptech/glide/load/resource/gif/GifResourceEncoderTest.java
浏览文件 @
8f80ee83
...
...
@@ -8,12 +8,14 @@ import com.bumptech.glide.gifencoder.AnimatedGifEncoder;
import
com.bumptech.glide.load.Transformation
;
import
com.bumptech.glide.load.engine.Resource
;
import
com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool
;
import
com.bumptech.glide.load.resource.UnitTransformation
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.InOrder
;
import
org.robolectric.RobolectricTestRunner
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
...
...
@@ -24,6 +26,7 @@ import static org.mockito.Matchers.anyInt;
import
static
org
.
mockito
.
Matchers
.
eq
;
import
static
org
.
mockito
.
Mockito
.
inOrder
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
never
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
...
...
@@ -236,6 +239,23 @@ public class GifResourceEncoderTest {
order
.
verify
(
frameResource
).
recycle
();
}
@Test
public
void
testWritesBytesDirectlyToDiskIfTransformationIsUnitTransformation
()
throws
IOException
{
when
(
gifDrawable
.
getFrameTransformation
()).
thenReturn
(
UnitTransformation
.<
Bitmap
>
get
());
byte
[]
expected
=
"expected"
.
getBytes
();
when
(
gifDrawable
.
getData
()).
thenReturn
(
expected
);
OutputStream
os
=
mock
(
OutputStream
.
class
);
encoder
.
encode
(
resource
,
os
);
verify
(
os
).
write
(
eq
(
expected
));
verify
(
gifEncoder
,
never
()).
start
(
any
(
OutputStream
.
class
));
verify
(
parser
,
never
()).
setData
(
any
(
byte
[].
class
));
verify
(
parser
,
never
()).
parseHeader
();
}
@Test
public
void
testHasValidId
()
{
assertEquals
(
""
,
encoder
.
getId
());
...
...
library/src/main/java/com/bumptech/glide/load/resource/gif/GifResourceEncoder.java
浏览文件 @
8f80ee83
...
...
@@ -10,9 +10,11 @@ import com.bumptech.glide.load.ResourceEncoder;
import
com.bumptech.glide.load.Transformation
;
import
com.bumptech.glide.load.engine.Resource
;
import
com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool
;
import
com.bumptech.glide.load.resource.UnitTransformation
;
import
com.bumptech.glide.load.resource.bitmap.BitmapResource
;
import
com.bumptech.glide.util.LogTime
;
import
java.io.IOException
;
import
java.io.OutputStream
;
/**
...
...
@@ -42,6 +44,11 @@ public class GifResourceEncoder implements ResourceEncoder<GifDrawable> {
long
startTime
=
LogTime
.
getLogTime
();
GifDrawable
drawable
=
resource
.
get
();
Transformation
<
Bitmap
>
transformation
=
drawable
.
getFrameTransformation
();
if
(
transformation
instanceof
UnitTransformation
)
{
return
writeDataDirect
(
drawable
.
getData
(),
os
);
}
GifDecoder
decoder
=
decodeHeaders
(
drawable
.
getData
());
AnimatedGifEncoder
encoder
=
factory
.
buildEncoder
();
...
...
@@ -49,7 +56,6 @@ public class GifResourceEncoder implements ResourceEncoder<GifDrawable> {
return
false
;
}
Transformation
<
Bitmap
>
transformation
=
drawable
.
getFrameTransformation
();
for
(
int
i
=
0
;
i
<
decoder
.
getFrameCount
();
i
++)
{
Bitmap
currentFrame
=
decoder
.
getNextFrame
();
Resource
<
Bitmap
>
transformedResource
=
getTransformedFrame
(
currentFrame
,
transformation
,
drawable
);
...
...
@@ -77,6 +83,19 @@ public class GifResourceEncoder implements ResourceEncoder<GifDrawable> {
return
result
;
}
private
boolean
writeDataDirect
(
byte
[]
data
,
OutputStream
os
)
{
boolean
success
=
true
;
try
{
os
.
write
(
data
);
}
catch
(
IOException
e
)
{
if
(
Log
.
isLoggable
(
TAG
,
Log
.
DEBUG
))
{
Log
.
d
(
TAG
,
"Failed to write data to output stream in GifResourceEncoder"
,
e
);
}
success
=
false
;
}
return
success
;
}
private
GifDecoder
decodeHeaders
(
byte
[]
data
)
{
GifHeaderParser
parser
=
factory
.
buildParser
();
parser
.
setData
(
data
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录