/src/gstreamer/subprojects/gst-plugins-base/gst-libs/gst/video/gstvideoutilsprivate.h
Line | Count | Source |
1 | | /* GStreamer |
2 | | * Copyright (C) 2008 David Schleef <ds@schleef.org> |
3 | | * Copyright (C) 2012 Collabora Ltd. |
4 | | * Author : Edward Hervey <edward@collabora.com> |
5 | | * |
6 | | * This library is free software; you can redistribute it and/or |
7 | | * modify it under the terms of the GNU Library General Public |
8 | | * License as published by the Free Software Foundation; either |
9 | | * version 2 of the License, or (at your option) any later version. |
10 | | * |
11 | | * This library 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 GNU |
14 | | * Library General Public License for more details. |
15 | | * |
16 | | * You should have received a copy of the GNU Library General Public |
17 | | * License along with this library; if not, write to the |
18 | | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, |
19 | | * Boston, MA 02110-1301, USA. |
20 | | */ |
21 | | |
22 | | #ifndef __GST_VIDEO_H__ |
23 | | #include <gst/video/video.h> |
24 | | #endif |
25 | | |
26 | | #ifndef _GST_VIDEO_UTILS_PRIVATE_H_ |
27 | | #define _GST_VIDEO_UTILS_PRIVATE_H_ |
28 | | |
29 | | #include <gst/gst.h> |
30 | | |
31 | | G_BEGIN_DECLS |
32 | | |
33 | | /* IEEE half-float (binary16) <-> float conversion, shared by the RGBA_F16 |
34 | | * (un)pack in video-format.c and the RGBA_F16 <-> RGBA_F32 converter fast |
35 | | * path in video-converter.c. */ |
36 | | static inline gfloat |
37 | | gst_half_to_float (guint16 h) |
38 | 0 | { |
39 | 0 | union |
40 | 0 | { |
41 | 0 | guint32 i; |
42 | 0 | gfloat f; |
43 | 0 | } u; |
44 | 0 | guint32 sign = ((guint32) h & 0x8000) << 16; |
45 | 0 | guint32 exponent = (h >> 10) & 0x1f; |
46 | 0 | guint32 mantissa = h & 0x3ff; |
47 | |
|
48 | 0 | if (exponent == 0) { |
49 | 0 | if (mantissa == 0) { |
50 | 0 | u.i = sign; |
51 | 0 | return u.f; |
52 | 0 | } |
53 | | /* subnormal half: renormalize */ |
54 | 0 | exponent = 127 - 15 + 1; |
55 | 0 | while ((mantissa & 0x400) == 0) { |
56 | 0 | mantissa <<= 1; |
57 | 0 | exponent--; |
58 | 0 | } |
59 | 0 | mantissa &= 0x3ff; |
60 | 0 | u.i = sign | (exponent << 23) | (mantissa << 13); |
61 | 0 | } else if (exponent == 31) { |
62 | 0 | u.i = sign | 0x7f800000 | (mantissa << 13); |
63 | 0 | } else { |
64 | 0 | u.i = sign | ((exponent - 15 + 127) << 23) | (mantissa << 13); |
65 | 0 | } |
66 | 0 | return u.f; |
67 | 0 | } Unexecuted instantiation: gstvideodecoder.c:gst_half_to_float Unexecuted instantiation: gstvideoencoder.c:gst_half_to_float Unexecuted instantiation: gstvideoutilsprivate.c:gst_half_to_float Unexecuted instantiation: video-converter.c:gst_half_to_float Unexecuted instantiation: video-format.c:gst_half_to_float |
68 | | |
69 | | static inline guint16 |
70 | | gst_float_to_half (gfloat f) |
71 | 0 | { |
72 | 0 | union |
73 | 0 | { |
74 | 0 | gfloat f; |
75 | 0 | guint32 i; |
76 | 0 | } u; |
77 | 0 | guint32 sign, mantissa, shift, rest, halfway; |
78 | 0 | gint32 exponent; |
79 | 0 | guint16 h; |
80 | |
|
81 | 0 | u.f = f; |
82 | 0 | sign = (u.i >> 16) & 0x8000; |
83 | 0 | exponent = (gint32) ((u.i >> 23) & 0xff) - 127 + 15; |
84 | 0 | mantissa = u.i & 0x7fffff; |
85 | | |
86 | | /* infinity / NaN: NaN keeps the top payload bits, with the (mantissa == 0) |
87 | | * term ensuring a NaN whose payload is truncated away stays a NaN */ |
88 | 0 | if (((u.i >> 23) & 0xff) == 0xff) { |
89 | 0 | if (mantissa == 0) |
90 | 0 | return sign | 0x7c00; |
91 | 0 | mantissa >>= 13; |
92 | 0 | return sign | 0x7c00 | mantissa | (mantissa == 0); |
93 | 0 | } |
94 | | |
95 | | /* overflow: round to infinity */ |
96 | 0 | if (exponent >= 31) |
97 | 0 | return sign | 0x7c00; |
98 | | |
99 | | /* subnormal half or underflow to zero, round to nearest even */ |
100 | 0 | if (exponent <= 0) { |
101 | 0 | if (exponent < -10) |
102 | 0 | return sign; |
103 | 0 | mantissa |= 0x800000; |
104 | 0 | shift = 14 - exponent; |
105 | 0 | h = mantissa >> shift; |
106 | 0 | rest = mantissa & ((1u << shift) - 1); |
107 | 0 | halfway = 1u << (shift - 1); |
108 | 0 | if (rest > halfway || (rest == halfway && (h & 1))) |
109 | 0 | h++; |
110 | 0 | return sign | h; |
111 | 0 | } |
112 | | |
113 | | /* round to nearest even, a carry into the exponent rounds up to infinity */ |
114 | 0 | h = (exponent << 10) | (mantissa >> 13); |
115 | 0 | rest = mantissa & 0x1fff; |
116 | 0 | if (rest > 0x1000 || (rest == 0x1000 && (h & 1))) |
117 | 0 | h++; |
118 | 0 | return sign | h; |
119 | 0 | } Unexecuted instantiation: gstvideodecoder.c:gst_float_to_half Unexecuted instantiation: gstvideoencoder.c:gst_float_to_half Unexecuted instantiation: gstvideoutilsprivate.c:gst_float_to_half Unexecuted instantiation: video-converter.c:gst_float_to_half Unexecuted instantiation: video-format.c:gst_float_to_half |
120 | | |
121 | | /* Element utility functions */ |
122 | | G_GNUC_INTERNAL |
123 | | GstCaps *__gst_video_element_proxy_getcaps (GstElement * element, GstPad * sinkpad, |
124 | | GstPad * srcpad, GstCaps * initial_caps, |
125 | | GstCaps * filter); |
126 | | |
127 | | G_GNUC_INTERNAL |
128 | | gboolean __gst_video_encoded_video_convert (gint64 bytes, gint64 time, |
129 | | GstFormat src_format, gint64 src_value, |
130 | | GstFormat * dest_format, gint64 * dest_value); |
131 | | |
132 | | G_GNUC_INTERNAL |
133 | | gboolean __gst_video_rawvideo_convert (GstVideoCodecState * state, GstFormat src_format, |
134 | | gint64 src_value, GstFormat * dest_format, |
135 | | gint64 * dest_value); |
136 | | |
137 | | G_END_DECLS |
138 | | |
139 | | #endif |