1 /* GStreamer JPEG 2000 Sampling
2 * Copyright (C) <2016> Grok Image Compression Inc.
3 * @author Aaron Boxer <boxerab@gmail.com>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21 /**
22 * SECTION:gstjpeg2000sampling
23 * @title: GstJpeg2000Sampling
24 * @short_description: Manage JPEG 2000 sampling and colorspace fields
25 *
26 */
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30
31 #include "gstjpeg2000sampling.h"
32
33 /* string values corresponding to GstJPEG2000Sampling enums */
34 static const gchar *gst_jpeg2000_sampling_strings[] = {
35 "RGB",
36 "BGR",
37 "RGBA",
38 "BGRA",
39 "YCbCr-4:4:4",
40 "YCbCr-4:2:2",
41 "YCbCr-4:2:0",
42 "YCbCr-4:1:0",
43 "GRAYSCALE",
44 "YCbCrA-4:4:4:4",
45 };
46
47 /* convert string to GstJPEG2000Sampling enum */
48 GstJPEG2000Sampling
gst_jpeg2000_sampling_from_string(const gchar * sampling_string)49 gst_jpeg2000_sampling_from_string (const gchar * sampling_string)
50 {
51 GstJPEG2000Sampling i;
52 if (sampling_string == NULL)
53 return GST_JPEG2000_SAMPLING_NONE;
54 for (i = 0; i < G_N_ELEMENTS (gst_jpeg2000_sampling_strings); ++i) {
55 if (!g_strcmp0 (sampling_string, gst_jpeg2000_sampling_strings[i]))
56 return (i + 1);
57 }
58 return GST_JPEG2000_SAMPLING_NONE;
59
60
61 }
62
63 /* convert GstJPEG2000Sampling enum to string */
64 const gchar *
gst_jpeg2000_sampling_to_string(GstJPEG2000Sampling sampling)65 gst_jpeg2000_sampling_to_string (GstJPEG2000Sampling sampling)
66 {
67 g_return_val_if_fail (sampling > 0
68 && sampling <= G_N_ELEMENTS (gst_jpeg2000_sampling_strings), NULL);
69 return gst_jpeg2000_sampling_strings[sampling - 1];
70 }
71
72 /* check if @sampling is in RGB color space */
73 gboolean
gst_jpeg2000_sampling_is_rgb(GstJPEG2000Sampling sampling)74 gst_jpeg2000_sampling_is_rgb (GstJPEG2000Sampling sampling)
75 {
76 return sampling == GST_JPEG2000_SAMPLING_RGB ||
77 sampling == GST_JPEG2000_SAMPLING_RGBA ||
78 sampling == GST_JPEG2000_SAMPLING_BGR
79 || sampling == GST_JPEG2000_SAMPLING_BGRA;
80 }
81
82 /* check if @sampling is in YUV color space */
83 gboolean
gst_jpeg2000_sampling_is_yuv(GstJPEG2000Sampling sampling)84 gst_jpeg2000_sampling_is_yuv (GstJPEG2000Sampling sampling)
85 {
86 return sampling == GST_JPEG2000_SAMPLING_YBRA4444_EXT ||
87 sampling == GST_JPEG2000_SAMPLING_YBR444 ||
88 sampling == GST_JPEG2000_SAMPLING_YBR422 ||
89 sampling == GST_JPEG2000_SAMPLING_YBR420
90 || sampling == GST_JPEG2000_SAMPLING_YBR410;
91 }
92
93 /* check if @sampling is in GRAYSCALE color space */
94 gboolean
gst_jpeg2000_sampling_is_mono(GstJPEG2000Sampling sampling)95 gst_jpeg2000_sampling_is_mono (GstJPEG2000Sampling sampling)
96 {
97 return sampling == GST_JPEG2000_SAMPLING_GRAYSCALE;
98 }
99
100 /* string values corresponding to GstJPEG2000Colorspace enums */
101 static const gchar *gst_jpeg2000_colorspace_strings[] = {
102 "sRGB",
103 "sYUV",
104 "GRAY",
105 };
106
107 /* convert GstJPEG2000Colorspace enum to string */
108 GstJPEG2000Colorspace
gst_jpeg2000_colorspace_from_string(const gchar * colorspace_string)109 gst_jpeg2000_colorspace_from_string (const gchar * colorspace_string)
110 {
111 GstJPEG2000Colorspace i;
112
113 g_return_val_if_fail (colorspace_string != NULL,
114 GST_JPEG2000_COLORSPACE_NONE);
115
116 for (i = 0; i < G_N_ELEMENTS (gst_jpeg2000_colorspace_strings); ++i) {
117 if (!g_strcmp0 (colorspace_string, gst_jpeg2000_colorspace_strings[i]))
118 return (i + 1);
119 }
120 return GST_JPEG2000_COLORSPACE_NONE;
121 }
122
123 /* convert string to GstJPEG2000Colorspace enum */
124 const gchar *
gst_jpeg2000_colorspace_to_string(GstJPEG2000Colorspace colorspace)125 gst_jpeg2000_colorspace_to_string (GstJPEG2000Colorspace colorspace)
126 {
127 g_return_val_if_fail (colorspace > GST_JPEG2000_COLORSPACE_NONE
128 && colorspace <= G_N_ELEMENTS (gst_jpeg2000_colorspace_strings), NULL);
129
130 return gst_jpeg2000_colorspace_strings[colorspace - 1];
131 }
132