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
fa447681
Commit
fa447681
authored
Dec 02, 2013
by
Anton Khirnov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ljpegenc: split bgr encoding into a separate function
parent
daffed3b
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
45 deletions
+58
-45
ljpegenc.c
libavcodec/ljpegenc.c
+58
-45
No files found.
libavcodec/ljpegenc.c
View file @
fa447681
...
@@ -57,6 +57,61 @@ typedef struct LJpegEncContext {
...
@@ -57,6 +57,61 @@ typedef struct LJpegEncContext {
uint16_t
(
*
scratch
)[
4
];
uint16_t
(
*
scratch
)[
4
];
}
LJpegEncContext
;
}
LJpegEncContext
;
static
int
ljpeg_encode_bgr
(
AVCodecContext
*
avctx
,
PutBitContext
*
pb
,
const
AVFrame
*
frame
)
{
LJpegEncContext
*
s
=
avctx
->
priv_data
;
const
int
width
=
frame
->
width
;
const
int
height
=
frame
->
height
;
const
int
linesize
=
frame
->
linesize
[
0
];
uint16_t
(
*
buffer
)[
4
]
=
s
->
scratch
;
const
int
predictor
=
avctx
->
prediction_method
+
1
;
int
left
[
3
],
top
[
3
],
topleft
[
3
];
int
x
,
y
,
i
;
for
(
i
=
0
;
i
<
3
;
i
++
)
buffer
[
0
][
i
]
=
1
<<
(
9
-
1
);
for
(
y
=
0
;
y
<
height
;
y
++
)
{
const
int
modified_predictor
=
y
?
predictor
:
1
;
uint8_t
*
ptr
=
frame
->
data
[
0
]
+
(
linesize
*
y
);
if
(
pb
->
buf_end
-
pb
->
buf
-
(
put_bits_count
(
pb
)
>>
3
)
<
width
*
3
*
3
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"encoded frame too large
\n
"
);
return
-
1
;
}
for
(
i
=
0
;
i
<
3
;
i
++
)
top
[
i
]
=
left
[
i
]
=
topleft
[
i
]
=
buffer
[
0
][
i
];
for
(
x
=
0
;
x
<
width
;
x
++
)
{
buffer
[
x
][
1
]
=
ptr
[
3
*
x
+
0
]
-
ptr
[
3
*
x
+
1
]
+
0x100
;
buffer
[
x
][
2
]
=
ptr
[
3
*
x
+
2
]
-
ptr
[
3
*
x
+
1
]
+
0x100
;
buffer
[
x
][
0
]
=
(
ptr
[
3
*
x
+
0
]
+
2
*
ptr
[
3
*
x
+
1
]
+
ptr
[
3
*
x
+
2
])
>>
2
;
for
(
i
=
0
;
i
<
3
;
i
++
)
{
int
pred
,
diff
;
PREDICT
(
pred
,
topleft
[
i
],
top
[
i
],
left
[
i
],
modified_predictor
);
topleft
[
i
]
=
top
[
i
];
top
[
i
]
=
buffer
[
x
+
1
][
i
];
left
[
i
]
=
buffer
[
x
][
i
];
diff
=
((
left
[
i
]
-
pred
+
0x100
)
&
0x1FF
)
-
0x100
;
if
(
i
==
0
)
ff_mjpeg_encode_dc
(
pb
,
diff
,
s
->
huff_size_dc_luminance
,
s
->
huff_code_dc_luminance
);
//FIXME ugly
else
ff_mjpeg_encode_dc
(
pb
,
diff
,
s
->
huff_size_dc_chrominance
,
s
->
huff_code_dc_chrominance
);
}
}
}
return
0
;
}
static
int
ljpeg_encode_frame
(
AVCodecContext
*
avctx
,
AVPacket
*
pkt
,
static
int
ljpeg_encode_frame
(
AVCodecContext
*
avctx
,
AVPacket
*
pkt
,
const
AVFrame
*
pict
,
int
*
got_packet
)
const
AVFrame
*
pict
,
int
*
got_packet
)
{
{
...
@@ -89,51 +144,9 @@ static int ljpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
...
@@ -89,51 +144,9 @@ static int ljpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
header_bits
=
put_bits_count
(
&
pb
);
header_bits
=
put_bits_count
(
&
pb
);
if
(
avctx
->
pix_fmt
==
AV_PIX_FMT_BGR24
)
{
if
(
avctx
->
pix_fmt
==
AV_PIX_FMT_BGR24
)
{
int
x
,
y
,
i
;
ret
=
ljpeg_encode_bgr
(
avctx
,
&
pb
,
pict
);
const
int
linesize
=
pict
->
linesize
[
0
];
if
(
ret
<
0
)
uint16_t
(
*
buffer
)[
4
]
=
s
->
scratch
;
return
ret
;
int
left
[
3
],
top
[
3
],
topleft
[
3
];
for
(
i
=
0
;
i
<
3
;
i
++
){
buffer
[
0
][
i
]
=
1
<<
(
9
-
1
);
}
for
(
y
=
0
;
y
<
height
;
y
++
)
{
const
int
modified_predictor
=
y
?
predictor
:
1
;
uint8_t
*
ptr
=
pict
->
data
[
0
]
+
(
linesize
*
y
);
if
(
pb
.
buf_end
-
pb
.
buf
-
(
put_bits_count
(
&
pb
)
>>
3
)
<
width
*
3
*
3
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"encoded frame too large
\n
"
);
return
-
1
;
}
for
(
i
=
0
;
i
<
3
;
i
++
){
top
[
i
]
=
left
[
i
]
=
topleft
[
i
]
=
buffer
[
0
][
i
];
}
for
(
x
=
0
;
x
<
width
;
x
++
)
{
buffer
[
x
][
1
]
=
ptr
[
3
*
x
+
0
]
-
ptr
[
3
*
x
+
1
]
+
0x100
;
buffer
[
x
][
2
]
=
ptr
[
3
*
x
+
2
]
-
ptr
[
3
*
x
+
1
]
+
0x100
;
buffer
[
x
][
0
]
=
(
ptr
[
3
*
x
+
0
]
+
2
*
ptr
[
3
*
x
+
1
]
+
ptr
[
3
*
x
+
2
])
>>
2
;
for
(
i
=
0
;
i
<
3
;
i
++
)
{
int
pred
,
diff
;
PREDICT
(
pred
,
topleft
[
i
],
top
[
i
],
left
[
i
],
modified_predictor
);
topleft
[
i
]
=
top
[
i
];
top
[
i
]
=
buffer
[
x
+
1
][
i
];
left
[
i
]
=
buffer
[
x
][
i
];
diff
=
((
left
[
i
]
-
pred
+
0x100
)
&
0x1FF
)
-
0x100
;
if
(
i
==
0
)
ff_mjpeg_encode_dc
(
&
pb
,
diff
,
s
->
huff_size_dc_luminance
,
s
->
huff_code_dc_luminance
);
//FIXME ugly
else
ff_mjpeg_encode_dc
(
&
pb
,
diff
,
s
->
huff_size_dc_chrominance
,
s
->
huff_code_dc_chrominance
);
}
}
}
}
else
{
}
else
{
int
mb_x
,
mb_y
,
i
;
int
mb_x
,
mb_y
,
i
;
...
...
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