• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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   "YCbCr-4:1:1",
46 };
47 
48 /* convert string to GstJPEG2000Sampling enum */
49 GstJPEG2000Sampling
gst_jpeg2000_sampling_from_string(const gchar * sampling_string)50 gst_jpeg2000_sampling_from_string (const gchar * sampling_string)
51 {
52   GstJPEG2000Sampling i;
53   if (sampling_string == NULL)
54     return GST_JPEG2000_SAMPLING_NONE;
55   for (i = 0; i < G_N_ELEMENTS (gst_jpeg2000_sampling_strings); ++i) {
56     if (!g_strcmp0 (sampling_string, gst_jpeg2000_sampling_strings[i]))
57       return (i + 1);
58   }
59   return GST_JPEG2000_SAMPLING_NONE;
60 
61 
62 }
63 
64 /* convert GstJPEG2000Sampling enum to string */
65 const gchar *
gst_jpeg2000_sampling_to_string(GstJPEG2000Sampling sampling)66 gst_jpeg2000_sampling_to_string (GstJPEG2000Sampling sampling)
67 {
68   g_return_val_if_fail (sampling > 0
69       && sampling <= G_N_ELEMENTS (gst_jpeg2000_sampling_strings), NULL);
70   return gst_jpeg2000_sampling_strings[sampling - 1];
71 }
72 
73 /* check if @sampling is in RGB color space */
74 gboolean
gst_jpeg2000_sampling_is_rgb(GstJPEG2000Sampling sampling)75 gst_jpeg2000_sampling_is_rgb (GstJPEG2000Sampling sampling)
76 {
77   return sampling == GST_JPEG2000_SAMPLING_RGB ||
78       sampling == GST_JPEG2000_SAMPLING_RGBA ||
79       sampling == GST_JPEG2000_SAMPLING_BGR
80       || sampling == GST_JPEG2000_SAMPLING_BGRA;
81 }
82 
83 /* check if @sampling is in YUV color space */
84 gboolean
gst_jpeg2000_sampling_is_yuv(GstJPEG2000Sampling sampling)85 gst_jpeg2000_sampling_is_yuv (GstJPEG2000Sampling sampling)
86 {
87   return sampling == GST_JPEG2000_SAMPLING_YBRA4444_EXT ||
88       sampling == GST_JPEG2000_SAMPLING_YBR444 ||
89       sampling == GST_JPEG2000_SAMPLING_YBR422 ||
90       sampling == GST_JPEG2000_SAMPLING_YBR420 ||
91       sampling == GST_JPEG2000_SAMPLING_YBR411 ||
92       sampling == GST_JPEG2000_SAMPLING_YBR410;
93 }
94 
95 /* check if @sampling is in GRAYSCALE color space */
96 gboolean
gst_jpeg2000_sampling_is_mono(GstJPEG2000Sampling sampling)97 gst_jpeg2000_sampling_is_mono (GstJPEG2000Sampling sampling)
98 {
99   return sampling == GST_JPEG2000_SAMPLING_GRAYSCALE;
100 }
101 
102 /* string values corresponding to GstJPEG2000Colorspace enums */
103 static const gchar *gst_jpeg2000_colorspace_strings[] = {
104   "sRGB",
105   "sYUV",
106   "GRAY",
107 };
108 
109 /* convert GstJPEG2000Colorspace enum to string */
110 GstJPEG2000Colorspace
gst_jpeg2000_colorspace_from_string(const gchar * colorspace_string)111 gst_jpeg2000_colorspace_from_string (const gchar * colorspace_string)
112 {
113   GstJPEG2000Colorspace i;
114 
115   g_return_val_if_fail (colorspace_string != NULL,
116       GST_JPEG2000_COLORSPACE_NONE);
117 
118   for (i = 0; i < G_N_ELEMENTS (gst_jpeg2000_colorspace_strings); ++i) {
119     if (!g_strcmp0 (colorspace_string, gst_jpeg2000_colorspace_strings[i]))
120       return (i + 1);
121   }
122   return GST_JPEG2000_COLORSPACE_NONE;
123 }
124 
125 /* convert string to GstJPEG2000Colorspace enum */
126 const gchar *
gst_jpeg2000_colorspace_to_string(GstJPEG2000Colorspace colorspace)127 gst_jpeg2000_colorspace_to_string (GstJPEG2000Colorspace colorspace)
128 {
129   g_return_val_if_fail (colorspace > GST_JPEG2000_COLORSPACE_NONE
130       && colorspace <= G_N_ELEMENTS (gst_jpeg2000_colorspace_strings), NULL);
131 
132   return gst_jpeg2000_colorspace_strings[colorspace - 1];
133 }
134