Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
沉迷打码的小凳子
glide
提交
990a0d3e
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,发现更多精彩内容 >>
提交
990a0d3e
编写于
10月 18, 2014
作者:
S
Sam Judd
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add tests for local color tables in gif parser.
上级
67e5f1d5
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
181 addition
and
9 deletion
+181
-9
third_party/gif_decoder/src/androidTest/java/com/bumptech/glide/gifdecoder/GifHeaderParserTest.java
...va/com/bumptech/glide/gifdecoder/GifHeaderParserTest.java
+78
-3
third_party/gif_decoder/src/androidTest/java/com/bumptech/glide/gifdecoder/test/GifBytesTestUtil.java
.../com/bumptech/glide/gifdecoder/test/GifBytesTestUtil.java
+36
-3
third_party/gif_decoder/src/androidTest/java/com/bumptech/glide/gifdecoder/test/GifBytesTestUtilTest.java
.../bumptech/glide/gifdecoder/test/GifBytesTestUtilTest.java
+67
-3
未找到文件。
third_party/gif_decoder/src/androidTest/java/com/bumptech/glide/gifdecoder/GifHeaderParserTest.java
浏览文件 @
990a0d3e
...
...
@@ -13,6 +13,7 @@ import java.nio.ByteOrder;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertNull
;
/**
* Tests for {@link com.bumptech.glide.gifdecoder.GifHeaderParser}.
...
...
@@ -62,10 +63,58 @@ public class GifHeaderParserTest {
@Test
public
void
testCanReadImageDescriptorWithoutGraphicalExtension
()
{
ByteBuffer
buffer
=
ByteBuffer
.
allocate
(
GifBytesTestUtil
.
HEADER_LENGTH
+
GifBytesTestUtil
.
IMAGE_DESCRIPTOR_LENGTH
+
4
).
order
(
ByteOrder
.
LITTLE_ENDIAN
);
final
int
lzwMinCodeSize
=
2
;
ByteBuffer
buffer
=
ByteBuffer
.
allocate
(
GifBytesTestUtil
.
HEADER_LENGTH
+
GifBytesTestUtil
.
IMAGE_DESCRIPTOR_LENGTH
+
GifBytesTestUtil
.
getImageDataSize
(
lzwMinCodeSize
)
).
order
(
ByteOrder
.
LITTLE_ENDIAN
);
GifBytesTestUtil
.
writeHeaderAndLsd
(
buffer
,
1
,
1
,
false
,
0
);
GifBytesTestUtil
.
writeImageDescriptor
(
buffer
,
0
,
0
,
1
,
1
);
GifBytesTestUtil
.
writeImageDescriptor
(
buffer
,
0
,
0
,
1
,
1
,
false
/*hasLct*/
,
0
);
GifBytesTestUtil
.
writeFakeImageData
(
buffer
,
lzwMinCodeSize
);
parser
.
setData
(
buffer
.
array
());
GifHeader
header
=
parser
.
parseHeader
();
assertEquals
(
1
,
header
.
width
);
assertEquals
(
1
,
header
.
height
);
assertEquals
(
1
,
header
.
frameCount
);
assertNotNull
(
header
.
frames
.
get
(
0
));
}
@Test
public
void
testSetsFrameLocalColorTableToNullIfNoColorTable
()
{
final
int
lzwMinCodeSize
=
2
;
ByteBuffer
buffer
=
ByteBuffer
.
allocate
(
GifBytesTestUtil
.
HEADER_LENGTH
+
GifBytesTestUtil
.
IMAGE_DESCRIPTOR_LENGTH
+
GifBytesTestUtil
.
getImageDataSize
(
lzwMinCodeSize
)
).
order
(
ByteOrder
.
LITTLE_ENDIAN
);
GifBytesTestUtil
.
writeHeaderAndLsd
(
buffer
,
1
,
1
,
false
,
0
);
GifBytesTestUtil
.
writeImageDescriptor
(
buffer
,
0
,
0
,
1
,
1
,
false
/*hasLct*/
,
0
);
GifBytesTestUtil
.
writeFakeImageData
(
buffer
,
lzwMinCodeSize
);
parser
.
setData
(
buffer
.
array
());
GifHeader
header
=
parser
.
parseHeader
();
assertEquals
(
1
,
header
.
width
);
assertEquals
(
1
,
header
.
height
);
assertEquals
(
1
,
header
.
frameCount
);
assertNotNull
(
header
.
frames
.
get
(
0
));
assertNull
(
header
.
frames
.
get
(
0
).
lct
);
}
@Test
public
void
testSetsFrameLocalColorTableIfHasColorTable
()
{
final
int
lzwMinCodeSize
=
2
;
final
int
numColors
=
4
;
ByteBuffer
buffer
=
ByteBuffer
.
allocate
(
GifBytesTestUtil
.
HEADER_LENGTH
+
GifBytesTestUtil
.
IMAGE_DESCRIPTOR_LENGTH
+
GifBytesTestUtil
.
getImageDataSize
(
lzwMinCodeSize
)
+
GifBytesTestUtil
.
getColorTableLength
(
numColors
)
).
order
(
ByteOrder
.
LITTLE_ENDIAN
);
GifBytesTestUtil
.
writeHeaderAndLsd
(
buffer
,
1
,
1
,
false
,
0
);
GifBytesTestUtil
.
writeImageDescriptor
(
buffer
,
0
,
0
,
1
,
1
,
true
/*hasLct*/
,
numColors
);
GifBytesTestUtil
.
writeColorTable
(
buffer
,
numColors
);
GifBytesTestUtil
.
writeFakeImageData
(
buffer
,
2
);
parser
.
setData
(
buffer
.
array
());
...
...
@@ -74,6 +123,32 @@ public class GifHeaderParserTest {
assertEquals
(
1
,
header
.
height
);
assertEquals
(
1
,
header
.
frameCount
);
assertNotNull
(
header
.
frames
.
get
(
0
));
GifFrame
frame
=
header
.
frames
.
get
(
0
);
assertNotNull
(
frame
.
lct
);
}
@Test
public
void
testCanParseMultipleFrames
()
{
final
int
lzwMinCodeSize
=
2
;
final
int
expectedFrames
=
3
;
final
int
frameSize
=
GifBytesTestUtil
.
IMAGE_DESCRIPTOR_LENGTH
+
GifBytesTestUtil
.
getImageDataSize
(
lzwMinCodeSize
);
ByteBuffer
buffer
=
ByteBuffer
.
allocate
(
GifBytesTestUtil
.
HEADER_LENGTH
+
expectedFrames
*
frameSize
).
order
(
ByteOrder
.
LITTLE_ENDIAN
);
GifBytesTestUtil
.
writeHeaderAndLsd
(
buffer
,
1
,
1
,
false
,
0
);
for
(
int
i
=
0
;
i
<
expectedFrames
;
i
++)
{
GifBytesTestUtil
.
writeImageDescriptor
(
buffer
,
0
,
0
,
1
,
1
,
false
/*hasLct*/
,
0
/*numColors*/
);
GifBytesTestUtil
.
writeFakeImageData
(
buffer
,
2
);
}
parser
.
setData
(
buffer
.
array
());
GifHeader
header
=
parser
.
parseHeader
();
assertEquals
(
expectedFrames
,
header
.
frameCount
);
assertEquals
(
expectedFrames
,
header
.
frames
.
size
());
}
private
InputStream
openResource
(
String
imageName
)
throws
IOException
{
...
...
third_party/gif_decoder/src/androidTest/java/com/bumptech/glide/gifdecoder/test/GifBytesTestUtil.java
浏览文件 @
990a0d3e
...
...
@@ -11,6 +11,15 @@ public class GifBytesTestUtil {
// Length in bytes.
public
static
final
int
IMAGE_DESCRIPTOR_LENGTH
=
10
;
public
static
int
getColorTableLength
(
int
numColors
)
{
return
3
*
numColors
;
}
public
static
int
getImageDataSize
(
int
lzwMinCodeSize
)
{
// TODO: fill this out.
return
4
;
}
public
static
void
writeFakeImageData
(
ByteBuffer
out
,
int
lzwMinCodeSize
)
{
// 1 for lzwMinCodeSize, 1 for length, 1 for min content, 1 for block terminator.
verifyRemaining
(
out
,
4
);
...
...
@@ -25,16 +34,40 @@ public class GifBytesTestUtil {
out
.
put
((
byte
)
0x00
);
}
public
static
void
writeColorTable
(
ByteBuffer
out
,
int
numColors
)
{
verifyRemaining
(
out
,
getColorTableLength
(
numColors
));
for
(
int
i
=
0
;
i
<
numColors
;
i
++)
{
out
.
put
((
byte
)
(
0xFF0000
&
i
));
out
.
put
((
byte
)
(
0x00FF00
&
i
));
out
.
put
((
byte
)
(
0x0000FF
&
i
));
}
}
public
static
void
writeImageDescriptor
(
ByteBuffer
out
,
int
imageLeft
,
int
imageTop
,
int
imageWidth
,
int
imageHeight
)
{
int
imageHeight
,
boolean
hasLct
,
int
numColors
)
{
verifyRemaining
(
out
,
IMAGE_DESCRIPTOR_LENGTH
);
verifyShortValues
(
imageLeft
,
imageTop
,
imageWidth
,
imageHeight
);
final
byte
packed
;
if
(
hasLct
)
{
int
size
=
log2
(
numColors
)
-
1
;
packed
=
(
byte
)
(
0x80
|
size
);
}
else
{
packed
=
0x00
;
}
// Image separator
out
.
put
((
byte
)
0x2C
);
out
.
putShort
((
short
)
imageLeft
)
.
putShort
((
short
)
imageTop
)
.
putShort
((
short
)
imageWidth
)
.
putShort
((
short
)
imageHeight
)
.
put
(
packed
);
}
out
.
putShort
((
short
)
imageLeft
).
putShort
((
short
)
imageTop
).
putShort
((
short
)
imageWidth
)
.
putShort
((
short
)
imageHeight
);
private
static
int
log2
(
int
num
)
{
return
(
int
)
Math
.
round
(
Math
.
log
(
num
)
/
Math
.
log
(
2
)
);
}
public
static
void
writeHeaderAndLsd
(
ByteBuffer
out
,
int
width
,
int
height
,
boolean
hasGct
,
int
gctSize
)
{
...
...
third_party/gif_decoder/src/androidTest/java/com/bumptech/glide/gifdecoder/test/GifBytesTestUtilTest.java
浏览文件 @
990a0d3e
...
...
@@ -3,6 +3,7 @@ package com.bumptech.glide.gifdecoder.test;
import
org.junit.Test
;
import
java.nio.ByteBuffer
;
import
java.util.Arrays
;
import
static
org
.
junit
.
Assert
.
assertArrayEquals
;
...
...
@@ -33,15 +34,78 @@ public class GifBytesTestUtilTest {
}
@Test
public
void
testWriteImageDescriptor
()
{
public
void
testWriteImageDescriptor
WithoutColorTable
()
{
ByteBuffer
buffer
=
ByteBuffer
.
allocate
(
GifBytesTestUtil
.
IMAGE_DESCRIPTOR_LENGTH
);
GifBytesTestUtil
.
writeImageDescriptor
(
buffer
,
10
,
9
,
8
,
7
);
GifBytesTestUtil
.
writeImageDescriptor
(
buffer
,
10
,
9
,
8
,
7
,
false
,
0
);
byte
[]
expected
=
new
byte
[]
{
// Image separator.
0x2C
,
// Image left.
0x00
,
0x0A
,
// Image right.
0x00
,
0X09
,
// Image width.
0x00
,
0x08
,
// Image height.
0x00
,
0x07
,
// Packed field.
0x00
};
byte
[]
expected
=
new
byte
[]
{
0x2C
,
0x00
,
0x0A
,
0x00
,
0X09
,
0x00
,
0x08
,
0x000
,
0x07
,
0x00
};
assertArrayEquals
(
expected
,
buffer
.
array
());
}
@Test
public
void
testWriteImageDescriptorWithColorTable
()
{
ByteBuffer
buffer
=
ByteBuffer
.
allocate
(
GifBytesTestUtil
.
IMAGE_DESCRIPTOR_LENGTH
);
GifBytesTestUtil
.
writeImageDescriptor
(
buffer
,
10
,
9
,
8
,
7
,
true
,
4
);
byte
packedField
=
// Set LCT flag
(
byte
)
0x80
// Size of color table (2^(N + 1) == 4)
|
0x01
;
byte
[]
expected
=
new
byte
[]
{
// Image separator.
0x2C
,
// Image left.
0x00
,
0x0A
,
// Image right.
0x00
,
0X09
,
// Image width.
0x00
,
0x08
,
// Image height.
0x00
,
0x07
,
packedField
};
assertArrayEquals
(
expected
,
buffer
.
array
());
}
@Test
public
void
testWriteColorTable
()
{
final
int
numColors
=
4
;
ByteBuffer
buffer
=
ByteBuffer
.
allocate
(
GifBytesTestUtil
.
getColorTableLength
(
numColors
));
GifBytesTestUtil
.
writeColorTable
(
buffer
,
numColors
);
byte
[]
expected
=
new
byte
[]
{
// First color.
0x00
,
0x00
,
0x00
,
// Second color.
0x00
,
0x00
,
0x01
,
// Third color.
0x00
,
0x00
,
0x02
,
// Fourth color.
0x00
,
0x00
,
0x03
,
};
assertArrayEquals
(
"expected="
+
Arrays
.
toString
(
expected
)
+
" received="
+
Arrays
.
toString
(
buffer
.
array
()),
expected
,
buffer
.
array
());
}
@Test
public
void
testWriteFakeImageData
()
{
ByteBuffer
buffer
=
ByteBuffer
.
allocate
(
4
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录