José Fonseca | 15422b2 | 2009-07-26 23:50:00 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | ''' |
| 4 | /************************************************************************** |
| 5 | * |
José Fonseca | 3d30524 | 2009-08-30 12:02:36 +0100 | [diff] [blame] | 6 | * Copyright 2009 VMware, Inc. |
José Fonseca | 15422b2 | 2009-07-26 23:50:00 +0100 | [diff] [blame] | 7 | * All Rights Reserved. |
| 8 | * |
| 9 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 10 | * copy of this software and associated documentation files (the |
| 11 | * "Software"), to deal in the Software without restriction, including |
| 12 | * without limitation the rights to use, copy, modify, merge, publish, |
| 13 | * distribute, sub license, and/or sell copies of the Software, and to |
| 14 | * permit persons to whom the Software is furnished to do so, subject to |
| 15 | * the following conditions: |
| 16 | * |
| 17 | * The above copyright notice and this permission notice (including the |
| 18 | * next paragraph) shall be included in all copies or substantial portions |
| 19 | * of the Software. |
| 20 | * |
| 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 22 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 23 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. |
José Fonseca | 3d30524 | 2009-08-30 12:02:36 +0100 | [diff] [blame] | 24 | * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR |
José Fonseca | 15422b2 | 2009-07-26 23:50:00 +0100 | [diff] [blame] | 25 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 26 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 27 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 28 | * |
| 29 | **************************************************************************/ |
| 30 | ''' |
| 31 | |
| 32 | |
| 33 | import sys |
| 34 | |
José Fonseca | 3d30524 | 2009-08-30 12:02:36 +0100 | [diff] [blame] | 35 | from u_format_parse import * |
José Fonseca | 15422b2 | 2009-07-26 23:50:00 +0100 | [diff] [blame] | 36 | |
| 37 | |
Michal Krol | dfdf83d | 2009-12-09 14:22:30 +0100 | [diff] [blame] | 38 | def layout_map(layout): |
| 39 | return 'UTIL_FORMAT_LAYOUT_' + str(layout).upper() |
José Fonseca | 15422b2 | 2009-07-26 23:50:00 +0100 | [diff] [blame] | 40 | |
| 41 | |
José Fonseca | 42b15b2 | 2009-07-28 08:47:13 +0100 | [diff] [blame] | 42 | def colorspace_map(colorspace): |
| 43 | return 'UTIL_FORMAT_COLORSPACE_' + str(colorspace).upper() |
| 44 | |
| 45 | |
| 46 | colorspace_channels_map = { |
José Fonseca | 7fc75ef | 2009-12-03 18:18:46 +0000 | [diff] [blame] | 47 | 'rgb': ['r', 'g', 'b', 'a'], |
| 48 | 'srgb': ['sr', 'sg', 'sb', 'a'], |
| 49 | 'zs': ['z', 's'], |
| 50 | 'yuv': ['y', 'u', 'v'], |
José Fonseca | 15422b2 | 2009-07-26 23:50:00 +0100 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | |
| 54 | kind_map = { |
José Fonseca | 3d30524 | 2009-08-30 12:02:36 +0100 | [diff] [blame] | 55 | VOID: "UTIL_FORMAT_TYPE_VOID", |
José Fonseca | 15422b2 | 2009-07-26 23:50:00 +0100 | [diff] [blame] | 56 | UNSIGNED: "UTIL_FORMAT_TYPE_UNSIGNED", |
José Fonseca | 3d30524 | 2009-08-30 12:02:36 +0100 | [diff] [blame] | 57 | SIGNED: "UTIL_FORMAT_TYPE_SIGNED", |
| 58 | FIXED: "UTIL_FORMAT_TYPE_FIXED", |
| 59 | FLOAT: "UTIL_FORMAT_TYPE_FLOAT", |
José Fonseca | 15422b2 | 2009-07-26 23:50:00 +0100 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | |
| 63 | def bool_map(value): |
| 64 | if value: |
| 65 | return "TRUE" |
| 66 | else: |
| 67 | return "FALSE" |
| 68 | |
| 69 | |
| 70 | swizzle_map = { |
José Fonseca | 3d30524 | 2009-08-30 12:02:36 +0100 | [diff] [blame] | 71 | SWIZZLE_X: "UTIL_FORMAT_SWIZZLE_X", |
| 72 | SWIZZLE_Y: "UTIL_FORMAT_SWIZZLE_Y", |
| 73 | SWIZZLE_Z: "UTIL_FORMAT_SWIZZLE_Z", |
| 74 | SWIZZLE_W: "UTIL_FORMAT_SWIZZLE_W", |
| 75 | SWIZZLE_0: "UTIL_FORMAT_SWIZZLE_0", |
| 76 | SWIZZLE_1: "UTIL_FORMAT_SWIZZLE_1", |
| 77 | SWIZZLE_NONE: "UTIL_FORMAT_SWIZZLE_NONE", |
José Fonseca | 15422b2 | 2009-07-26 23:50:00 +0100 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | |
| 81 | def write_format_table(formats): |
| 82 | print '/* This file is autogenerated by u_format_table.py from u_format.csv. Do not edit directly. */' |
| 83 | print |
| 84 | # This will print the copyright message on the top of this file |
| 85 | print __doc__.strip() |
| 86 | print |
| 87 | print '#include "u_format.h"' |
| 88 | print |
| 89 | print 'const struct util_format_description' |
| 90 | print 'util_format_description_table[] = ' |
| 91 | print "{" |
Michal Krol | ddbd2d0 | 2009-12-08 15:46:15 +0100 | [diff] [blame] | 92 | print " {" |
| 93 | print " PIPE_FORMAT_NONE," |
| 94 | print " \"PIPE_FORMAT_NONE\"," |
| 95 | print " {0, 0, 0}," |
| 96 | print " 0," |
| 97 | print " {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}," |
| 98 | print " {0, 0, 0, 0}," |
| 99 | print " 0" |
| 100 | print " }," |
José Fonseca | 15422b2 | 2009-07-26 23:50:00 +0100 | [diff] [blame] | 101 | for format in formats: |
| 102 | print " {" |
| 103 | print " %s," % (format.name,) |
| 104 | print " \"%s\"," % (format.name,) |
José Fonseca | 7fc75ef | 2009-12-03 18:18:46 +0000 | [diff] [blame] | 105 | print " {%u, %u, %u},\t/* block */" % (format.block_width, format.block_height, format.block_size()) |
Michal Krol | dfdf83d | 2009-12-09 14:22:30 +0100 | [diff] [blame] | 106 | print " %s," % (layout_map(format.layout),) |
José Fonseca | 15422b2 | 2009-07-26 23:50:00 +0100 | [diff] [blame] | 107 | print " {" |
| 108 | for i in range(4): |
| 109 | type = format.in_types[i] |
| 110 | if i < 3: |
| 111 | sep = "," |
| 112 | else: |
| 113 | sep = "" |
José Fonseca | 7fc75ef | 2009-12-03 18:18:46 +0000 | [diff] [blame] | 114 | print " {%s, %s, %u}%s\t/* %s */" % (kind_map[type.kind], bool_map(type.norm), type.size, sep, "xyzw"[i]) |
José Fonseca | 15422b2 | 2009-07-26 23:50:00 +0100 | [diff] [blame] | 115 | print " }," |
| 116 | print " {" |
| 117 | for i in range(4): |
| 118 | swizzle = format.out_swizzle[i] |
| 119 | if i < 3: |
| 120 | sep = "," |
| 121 | else: |
| 122 | sep = "" |
| 123 | try: |
José Fonseca | 7fc75ef | 2009-12-03 18:18:46 +0000 | [diff] [blame] | 124 | comment = colorspace_channels_map[format.colorspace][i] |
| 125 | except (KeyError, IndexError): |
José Fonseca | 15422b2 | 2009-07-26 23:50:00 +0100 | [diff] [blame] | 126 | comment = 'ignored' |
José Fonseca | 7fc75ef | 2009-12-03 18:18:46 +0000 | [diff] [blame] | 127 | print " %s%s\t/* %s */" % (swizzle_map[swizzle], sep, comment) |
José Fonseca | 15422b2 | 2009-07-26 23:50:00 +0100 | [diff] [blame] | 128 | print " }," |
José Fonseca | 42b15b2 | 2009-07-28 08:47:13 +0100 | [diff] [blame] | 129 | print " %s," % (colorspace_map(format.colorspace),) |
José Fonseca | 15422b2 | 2009-07-26 23:50:00 +0100 | [diff] [blame] | 130 | print " }," |
José Fonseca | 15422b2 | 2009-07-26 23:50:00 +0100 | [diff] [blame] | 131 | print "};" |
| 132 | |
| 133 | |
| 134 | def main(): |
| 135 | |
| 136 | formats = [] |
| 137 | for arg in sys.argv[1:]: |
| 138 | formats.extend(parse(arg)) |
| 139 | write_format_table(formats) |
| 140 | |
| 141 | |
| 142 | if __name__ == '__main__': |
| 143 | main() |