1 /*****************************************************************************
2 * jpeg2000.h J2K definitions
3 *****************************************************************************
4 * Copyright (C) 2017 VideoLAN Authors
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
20 #ifndef VLC_JPEG2000_H
21 #define VLC_JPEG2000_H
23 #define J2K_BOX_JP2C VLC_FOURCC('j','p','2','c')
34 static inline bool j2k_is_valid_framerate( unsigned num
, unsigned den
)
40 } numdens
[] = { /* table 2-99 */
50 for( size_t i
=0; i
<ARRAY_SIZE(numdens
); i
++ )
51 if( numdens
[i
].den
== den
&& numdens
[i
].num
== num
)
56 static inline enum j2k_profiles_e
j2k_get_profile( unsigned w
, unsigned h
,
57 unsigned num
, unsigned den
, bool p
)
59 const uint64_t s
= w
*(uint64_t)h
;
60 const uint64_t f
= num
/ den
;
61 if( s
<= 720*576 && f
< 50 )
62 return J2K_PROFILE_SD
; /* VSF_TR-01_2013-04-15 */
63 else if( s
<= 1280*720 && f
< 60 && p
)
64 return J2K_PROFILE_HD
;
65 else if( s
<= 1920*1080 && f
< 60 && !p
)
66 return J2K_PROFILE_HD
;
68 return J2K_PROFILE_3G
;
75 } j2k_profiles_rates
[] = {
76 [J2K_PROFILE_SD
] = { 25, 200 },
77 [J2K_PROFILE_HD
] = { 75, 200 },
78 [J2K_PROFILE_3G
] = { 100, 400 },
79 [J2K_PROFILE_S3D_HD
] = { 150, 200 },
80 [J2K_PROFILE_S3D_3G
] = { 200, 400 },
83 enum j2k_color_specs_e
85 J2K_COLOR_SPEC_UNKNOWN
= 0,
87 J2K_COLOR_SPEC_REC_601
,
88 J2K_COLOR_SPEC_REC_709
,
89 J2K_COLOR_SPEC_CIE_LUV
,
90 J2K_COLOR_SPEC_CIE_XYZ
,
91 J2K_COLOR_SPEC_REC_2020
,
92 J2K_COLOR_SPEC_SMPTE_2084
,
97 video_color_primaries_t primaries
;
98 video_transfer_func_t transfer
;
99 video_color_space_t space
;
100 } j2k_color_specifications
[] = {
101 [J2K_COLOR_SPEC_UNKNOWN
] = { COLOR_PRIMARIES_UNDEF
,
104 [J2K_COLOR_SPEC_SRGB
] = { COLOR_PRIMARIES_SRGB
,
107 [J2K_COLOR_SPEC_REC_601
] = { COLOR_PRIMARIES_BT601_625
,
108 TRANSFER_FUNC_SMPTE_170
,
110 [J2K_COLOR_SPEC_REC_709
] = { COLOR_PRIMARIES_BT709
,
113 [J2K_COLOR_SPEC_CIE_LUV
] = { COLOR_PRIMARIES_UNDEF
,
116 [J2K_COLOR_SPEC_CIE_XYZ
] = { COLOR_PRIMARIES_UNDEF
,
119 [J2K_COLOR_SPEC_REC_2020
] ={ COLOR_PRIMARIES_BT2020
,
120 TRANSFER_FUNC_BT2020
,
121 COLOR_SPACE_BT2020
},
122 [J2K_COLOR_SPEC_SMPTE_2084
]={ COLOR_PRIMARIES_SMTPE_170
,
123 TRANSFER_FUNC_SMPTE_ST2084
,
124 COLOR_SPACE_BT2020
},
127 static inline void j2k_fill_color_profile( enum j2k_color_specs_e e
,
128 video_color_primaries_t
*primaries
,
129 video_transfer_func_t
*transfer
,
130 video_color_space_t
*space
)
132 if( e
> J2K_COLOR_SPEC_UNKNOWN
&& e
<= J2K_COLOR_SPEC_SMPTE_2084
)
134 *primaries
= j2k_color_specifications
[e
].primaries
;
135 *transfer
= j2k_color_specifications
[e
].transfer
;
136 *space
= j2k_color_specifications
[e
].space
;
140 static inline enum j2k_color_specs_e
141 j2k_get_color_spec( video_color_primaries_t primaries
,
142 video_transfer_func_t transfer
,
143 video_color_space_t space
)
145 enum j2k_color_specs_e e
;
146 for( e
= J2K_COLOR_SPEC_UNKNOWN
; e
<= J2K_COLOR_SPEC_SMPTE_2084
; e
++ )
148 if( primaries
== j2k_color_specifications
[e
].primaries
&&
149 transfer
== j2k_color_specifications
[e
].transfer
&&
150 space
== j2k_color_specifications
[e
].space
)
155 return J2K_COLOR_SPEC_UNKNOWN
;