Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
F
ffmpeg.wasm-core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
ffmpeg.wasm-core
Commits
c2eec3df
Commit
c2eec3df
authored
Oct 08, 2012
by
Bobby Bingham
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
targa: support 2-way and 4-way interleaved files
Fixes ticket #701 Signed-off-by:
Bobby Bingham
<
uhmmmm@gmail.com
>
parent
3d9cdfdc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
22 deletions
+48
-22
targa.c
libavcodec/targa.c
+46
-22
targa.h
libavcodec/targa.h
+2
-0
No files found.
libavcodec/targa.c
View file @
c2eec3df
...
...
@@ -33,17 +33,35 @@ typedef struct TargaContext {
int
compression_type
;
}
TargaContext
;
static
uint8_t
*
advance_line
(
uint8_t
*
start
,
uint8_t
*
line
,
int
stride
,
int
*
y
,
int
h
,
int
interleave
)
{
*
y
+=
interleave
;
if
(
*
y
<
h
)
{
return
line
+
interleave
*
stride
;
}
else
{
*
y
=
(
*
y
+
1
)
&
(
interleave
-
1
);
if
(
*
y
)
{
return
start
+
*
y
*
stride
;
}
else
{
return
NULL
;
}
}
}
static
int
targa_decode_rle
(
AVCodecContext
*
avctx
,
TargaContext
*
s
,
uint8_t
*
dst
,
int
w
,
int
h
,
int
stride
,
int
bpp
)
uint8_t
*
start
,
int
w
,
int
h
,
int
stride
,
int
bpp
,
int
interleave
)
{
int
x
,
y
;
int
depth
=
(
bpp
+
1
)
>>
3
;
int
type
,
count
;
int
diff
;
uint8_t
*
line
=
start
;
uint8_t
*
dst
=
line
;
diff
=
stride
-
w
*
depth
;
x
=
y
=
0
;
while
(
y
<
h
)
{
x
=
y
=
count
=
0
;
while
(
dst
)
{
if
(
bytestream2_get_bytes_left
(
&
s
->
gb
)
<=
0
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"Ran ouf of data before end-of-image
\n
"
);
...
...
@@ -52,12 +70,6 @@ static int targa_decode_rle(AVCodecContext *avctx, TargaContext *s,
type
=
bytestream2_get_byteu
(
&
s
->
gb
);
count
=
(
type
&
0x7F
)
+
1
;
type
&=
0x80
;
if
(
x
+
count
>
(
h
-
y
)
*
w
){
av_log
(
avctx
,
AV_LOG_ERROR
,
"Packet went out of bounds: position (%i,%i) size %i
\n
"
,
x
,
y
,
count
);
return
AVERROR_INVALIDDATA
;
}
if
(
!
type
)
{
do
{
int
n
=
FFMIN
(
count
,
w
-
x
);
...
...
@@ -67,10 +79,9 @@ static int targa_decode_rle(AVCodecContext *avctx, TargaContext *s,
x
+=
n
;
if
(
x
==
w
)
{
x
=
0
;
y
++
;
dst
+=
diff
;
dst
=
line
=
advance_line
(
start
,
line
,
stride
,
&
y
,
h
,
interleave
);
}
}
while
(
count
>
0
);
}
while
(
dst
&&
count
>
0
);
}
else
{
uint8_t
tmp
[
4
];
bytestream2_get_buffer
(
&
s
->
gb
,
tmp
,
depth
);
...
...
@@ -84,12 +95,17 @@ static int targa_decode_rle(AVCodecContext *avctx, TargaContext *s,
}
while
(
--
n
);
if
(
x
==
w
)
{
x
=
0
;
y
++
;
dst
+=
diff
;
dst
=
line
=
advance_line
(
start
,
line
,
stride
,
&
y
,
h
,
interleave
);
}
}
while
(
count
>
0
);
}
while
(
dst
&&
count
>
0
);
}
}
if
(
count
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"Packet went out of bounds
\n
"
);
return
AVERROR_INVALIDDATA
;
}
return
0
;
}
...
...
@@ -104,6 +120,7 @@ static int decode_frame(AVCodecContext *avctx,
int
stride
;
int
idlen
,
pal
,
compr
,
y
,
w
,
h
,
bpp
,
flags
;
int
first_clr
,
colors
,
csize
;
int
interleave
;
bytestream2_init
(
&
s
->
gb
,
avpkt
->
data
,
avpkt
->
size
);
...
...
@@ -174,6 +191,9 @@ static int decode_frame(AVCodecContext *avctx,
stride
=
-
p
->
linesize
[
0
];
}
interleave
=
flags
&
TGA_INTERLEAVE2
?
2
:
flags
&
TGA_INTERLEAVE4
?
4
:
1
;
if
(
colors
){
int
pal_size
,
pal_sample_size
;
if
((
colors
+
first_clr
)
>
256
){
...
...
@@ -231,20 +251,24 @@ static int decode_frame(AVCodecContext *avctx,
memset
(
p
->
data
[
0
],
0
,
p
->
linesize
[
0
]
*
h
);
}
else
{
if
(
compr
&
TGA_RLE
){
int
res
=
targa_decode_rle
(
avctx
,
s
,
dst
,
w
,
h
,
stride
,
bpp
);
int
res
=
targa_decode_rle
(
avctx
,
s
,
dst
,
w
,
h
,
stride
,
bpp
,
interleave
);
if
(
res
<
0
)
return
res
;
}
else
{
size_t
img_size
=
w
*
((
bpp
+
1
)
>>
3
);
uint8_t
*
line
;
if
(
bytestream2_get_bytes_left
(
&
s
->
gb
)
<
img_size
*
h
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"Not enough data available for image
\n
"
);
return
AVERROR_INVALIDDATA
;
}
for
(
y
=
0
;
y
<
h
;
y
++
)
{
bytestream2_get_bufferu
(
&
s
->
gb
,
dst
,
img_size
);
dst
+=
stride
;
}
line
=
dst
;
y
=
0
;
do
{
bytestream2_get_bufferu
(
&
s
->
gb
,
line
,
img_size
);
line
=
advance_line
(
dst
,
line
,
stride
,
&
y
,
h
,
interleave
);
}
while
(
line
);
}
}
if
(
flags
&
TGA_RIGHTTOLEFT
)
{
// right-to-left, needs horizontal flip
...
...
libavcodec/targa.h
View file @
c2eec3df
...
...
@@ -41,6 +41,8 @@ enum TargaCompr {
enum
TargaFlags
{
TGA_RIGHTTOLEFT
=
0x10
,
// right-to-left (flipped horizontally)
TGA_TOPTOBOTTOM
=
0x20
,
// top-to-bottom (NOT flipped vertically)
TGA_INTERLEAVE2
=
0x40
,
// 2-way interleave, odd then even lines
TGA_INTERLEAVE4
=
0x80
,
// 4-way interleave
};
#endif
/* AVCODEC_TARGA_H */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment