Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
F
ffmpeg
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
ffmpeg
Commits
8b72f6d5
Commit
8b72f6d5
authored
Sep 11, 2015
by
Michael Niedermayer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avcodec/ljpegenc: Fix encoding RGBA LJPEG
Signed-off-by:
Michael Niedermayer
<
michael@niedermayer.cc
>
parent
055e56e9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
16 deletions
+35
-16
ljpegenc.c
libavcodec/ljpegenc.c
+12
-9
mjpegenc_common.c
libavcodec/mjpegenc_common.c
+22
-6
mjpegenc_common.h
libavcodec/mjpegenc_common.h
+1
-1
No files found.
libavcodec/ljpegenc.c
View file @
8b72f6d5
...
...
@@ -48,8 +48,8 @@ typedef struct LJpegEncContext {
ScanTable
scantable
;
uint16_t
matrix
[
64
];
int
vsample
[
3
];
int
hsample
[
3
];
int
vsample
[
4
];
int
hsample
[
4
];
uint16_t
huff_code_dc_luminance
[
12
];
uint16_t
huff_code_dc_chrominance
[
12
];
...
...
@@ -68,22 +68,22 @@ static int ljpeg_encode_bgr(AVCodecContext *avctx, PutBitContext *pb,
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
left
[
4
],
top
[
4
],
topleft
[
4
];
int
x
,
y
,
i
;
for
(
i
=
0
;
i
<
3
;
i
++
)
for
(
i
=
0
;
i
<
4
;
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
*
4
)
{
if
(
pb
->
buf_end
-
pb
->
buf
-
(
put_bits_count
(
pb
)
>>
3
)
<
width
*
4
*
4
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"encoded frame too large
\n
"
);
return
-
1
;
}
for
(
i
=
0
;
i
<
3
;
i
++
)
for
(
i
=
0
;
i
<
4
;
i
++
)
top
[
i
]
=
left
[
i
]
=
topleft
[
i
]
=
buffer
[
0
][
i
];
for
(
x
=
0
;
x
<
width
;
x
++
)
{
...
...
@@ -95,9 +95,11 @@ static int ljpeg_encode_bgr(AVCodecContext *avctx, PutBitContext *pb,
buffer
[
x
][
1
]
=
ptr
[
4
*
x
+
0
]
-
ptr
[
4
*
x
+
1
]
+
0x100
;
buffer
[
x
][
2
]
=
ptr
[
4
*
x
+
2
]
-
ptr
[
4
*
x
+
1
]
+
0x100
;
buffer
[
x
][
0
]
=
(
ptr
[
4
*
x
+
0
]
+
2
*
ptr
[
4
*
x
+
1
]
+
ptr
[
4
*
x
+
2
])
>>
2
;
if
(
avctx
->
pix_fmt
==
AV_PIX_FMT_BGRA
)
buffer
[
x
][
3
]
=
ptr
[
4
*
x
+
3
];
}
for
(
i
=
0
;
i
<
3
;
i
++
)
{
for
(
i
=
0
;
i
<
3
+
(
avctx
->
pix_fmt
==
AV_PIX_FMT_BGRA
)
;
i
++
)
{
int
pred
,
diff
;
PREDICT
(
pred
,
topleft
[
i
],
top
[
i
],
left
[
i
],
modified_predictor
);
...
...
@@ -109,7 +111,7 @@ static int ljpeg_encode_bgr(AVCodecContext *avctx, PutBitContext *pb,
diff
=
((
left
[
i
]
-
pred
+
0x100
)
&
0x1FF
)
-
0x100
;
if
(
i
==
0
)
if
(
i
==
0
||
i
==
3
)
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
);
...
...
@@ -221,9 +223,10 @@ static int ljpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
int
ret
,
header_bits
;
if
(
avctx
->
pix_fmt
==
AV_PIX_FMT_BGR0
||
avctx
->
pix_fmt
==
AV_PIX_FMT_BGRA
||
avctx
->
pix_fmt
==
AV_PIX_FMT_BGR24
)
max_pkt_size
+=
width
*
height
*
3
*
4
;
else
if
(
avctx
->
pix_fmt
==
AV_PIX_FMT_BGRA
)
max_pkt_size
+=
width
*
height
*
4
*
4
;
else
{
max_pkt_size
+=
mb_width
*
mb_height
*
3
*
4
*
s
->
hsample
[
0
]
*
s
->
vsample
[
0
];
...
...
libavcodec/mjpegenc_common.c
View file @
8b72f6d5
...
...
@@ -159,7 +159,7 @@ static void jpeg_put_comments(AVCodecContext *avctx, PutBitContext *p)
}
}
void
ff_mjpeg_init_hvsample
(
AVCodecContext
*
avctx
,
int
hsample
[
3
],
int
vsample
[
3
])
void
ff_mjpeg_init_hvsample
(
AVCodecContext
*
avctx
,
int
hsample
[
4
],
int
vsample
[
4
])
{
int
chroma_h_shift
,
chroma_v_shift
;
...
...
@@ -171,7 +171,8 @@ void ff_mjpeg_init_hvsample(AVCodecContext *avctx, int hsample[3], int vsample[3
||
avctx
->
pix_fmt
==
AV_PIX_FMT_BGR24
))
{
vsample
[
0
]
=
hsample
[
0
]
=
vsample
[
1
]
=
hsample
[
1
]
=
vsample
[
2
]
=
hsample
[
2
]
=
1
;
vsample
[
2
]
=
hsample
[
2
]
=
vsample
[
3
]
=
hsample
[
3
]
=
1
;
}
else
if
(
avctx
->
pix_fmt
==
AV_PIX_FMT_YUV444P
||
avctx
->
pix_fmt
==
AV_PIX_FMT_YUVJ444P
)
{
vsample
[
0
]
=
vsample
[
1
]
=
vsample
[
2
]
=
2
;
hsample
[
0
]
=
hsample
[
1
]
=
hsample
[
2
]
=
1
;
...
...
@@ -191,8 +192,9 @@ void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, PutBitContext *pb,
uint16_t
chroma_intra_matrix
[
64
])
{
const
int
lossless
=
avctx
->
codec_id
!=
AV_CODEC_ID_MJPEG
&&
avctx
->
codec_id
!=
AV_CODEC_ID_AMV
;
int
hsample
[
3
],
vsample
[
3
];
int
hsample
[
4
],
vsample
[
4
];
int
i
;
int
components
=
3
+
(
avctx
->
pix_fmt
==
AV_PIX_FMT_BGRA
);
int
chroma_matrix
=
!!
memcmp
(
luma_intra_matrix
,
chroma_intra_matrix
,
sizeof
(
luma_intra_matrix
[
0
])
*
64
);
...
...
@@ -223,7 +225,7 @@ void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, PutBitContext *pb,
put_bits
(
pb
,
8
,
8
);
/* 8 bits/component */
put_bits
(
pb
,
16
,
avctx
->
height
);
put_bits
(
pb
,
16
,
avctx
->
width
);
put_bits
(
pb
,
8
,
3
);
/* 3
components */
put_bits
(
pb
,
8
,
components
);
/* 3 or 4
components */
/* Y component */
put_bits
(
pb
,
8
,
1
);
/* component number */
...
...
@@ -243,10 +245,17 @@ void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, PutBitContext *pb,
put_bits
(
pb
,
4
,
vsample
[
2
]);
/* V factor */
put_bits
(
pb
,
8
,
lossless
?
0
:
chroma_matrix
);
/* select matrix */
if
(
components
==
4
)
{
put_bits
(
pb
,
8
,
4
);
/* component number */
put_bits
(
pb
,
4
,
hsample
[
3
]);
/* H factor */
put_bits
(
pb
,
4
,
vsample
[
3
]);
/* V factor */
put_bits
(
pb
,
8
,
0
);
/* select matrix */
}
/* scan header */
put_marker
(
pb
,
SOS
);
put_bits
(
pb
,
16
,
12
);
/* length */
put_bits
(
pb
,
8
,
3
);
/* 3 components */
put_bits
(
pb
,
16
,
6
+
2
*
components
);
/* length */
put_bits
(
pb
,
8
,
components
);
/* 3 components */
/* Y component */
put_bits
(
pb
,
8
,
1
);
/* index */
...
...
@@ -263,6 +272,13 @@ void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, PutBitContext *pb,
put_bits
(
pb
,
4
,
1
);
/* DC huffman table index */
put_bits
(
pb
,
4
,
lossless
?
0
:
1
);
/* AC huffman table index */
if
(
components
==
4
)
{
/* Alpha component */
put_bits
(
pb
,
8
,
4
);
/* index */
put_bits
(
pb
,
4
,
0
);
/* DC huffman table index */
put_bits
(
pb
,
4
,
0
);
/* AC huffman table index */
}
put_bits
(
pb
,
8
,
lossless
?
avctx
->
prediction_method
+
1
:
0
);
/* Ss (not used) */
switch
(
avctx
->
codec_id
)
{
...
...
libavcodec/mjpegenc_common.h
View file @
8b72f6d5
...
...
@@ -35,7 +35,7 @@ void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, PutBitContext *pb,
void
ff_mjpeg_encode_picture_trailer
(
PutBitContext
*
pb
,
int
header_bits
);
void
ff_mjpeg_escape_FF
(
PutBitContext
*
pb
,
int
start
);
int
ff_mjpeg_encode_stuffing
(
MpegEncContext
*
s
);
void
ff_mjpeg_init_hvsample
(
AVCodecContext
*
avctx
,
int
hsample
[
3
],
int
vsample
[
3
]);
void
ff_mjpeg_init_hvsample
(
AVCodecContext
*
avctx
,
int
hsample
[
4
],
int
vsample
[
4
]);
void
ff_mjpeg_encode_dc
(
PutBitContext
*
pb
,
int
val
,
uint8_t
*
huff_size
,
uint16_t
*
huff_code
);
...
...
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