1 /* This file is part of the Pangolin Project.
2  * http://github.com/stevenlovegrove/Pangolin
3  *
4  * Copyright (c) 2011 Steven Lovegrove
5  *
6  * Permission is hereby granted, free of charge, to any person
7  * obtaining a copy of this software and associated documentation
8  * files (the "Software"), to deal in the Software without
9  * restriction, including without limitation the rights to use,
10  * copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the
12  * Software is furnished to do so, subject to the following
13  * conditions:
14  *
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25  * OTHER DEALINGS IN THE SOFTWARE.
26  */
27 
28 #include <pangolin/image/pixel_format.h>
29 
30 #include <stdexcept>
31 #include <vector>
32 
33 namespace pangolin
34 {
35 
36 // Not to exceed 8 byte Format code.
37 const PixelFormat SupportedPixelFormats[] =
38 {
39     {"GRAY8", 1, {8}, 8, 8, false},
40     {"GRAY10", 1, {10}, 10, 10, false},
41     {"GRAY12", 1, {12}, 12, 12, false},
42     {"GRAY16LE", 1, {16}, 16, 16, false},
43     {"GRAY32", 1, {32}, 32, 32, false},
44     {"Y400A", 2, {8,8}, 16, 8, false},
45     {"RGB24", 3, {8,8,8}, 24, 8, false},
46     {"BGR24", 3, {8,8,8}, 24, 8, false},
47     {"RGB48", 3, {16,16,16}, 48, 16, false},
48     {"BGR48", 3, {16,16,16}, 48, 16, false},
49     {"YUYV422", 3, {4,2,2}, 16, 8, false},
50     {"UYVY422", 3, {4,2,2}, 16, 8, false},
51     {"RGBA32",  4, {8,8,8,8}, 32, 8, false},
52     {"BGRA32",  4, {8,8,8,8}, 32, 8, false},
53     {"RGBA64",  4, {16,16,16,16}, 64, 16, false},
54     {"BGRA64",  4, {16,16,16,16}, 64, 16, false},
55     {"GRAY32F", 1, {32}, 32, 32, false},
56     {"GRAY64F", 1, {64}, 64, 64, false},
57     {"RGB96F",  3, {32,32,32}, 96, 32, false},
58     {"RGBA128F",  4, {32,32,32,32}, 128, 32, false},
59     {"",0,{0,0,0,0},0,0,0}
60 };
61 
PixelFormatFromString(const std::string & format)62 PixelFormat PixelFormatFromString(const std::string& format)
63 {
64     for(int i=0; !SupportedPixelFormats[i].format.empty(); ++i)
65         if(!format.compare(SupportedPixelFormats[i].format))
66             return SupportedPixelFormats[i];
67     throw std::runtime_error( std::string("Unknown Format: ") + format);
68 }
69 
70 }
71