r300g: align the height of NPOT textures to POT
[mesa.git] / src / gallium / auxiliary / vl / vl_bitstream_parser.c
index 356faa13481ec340e2766ba65ffaba5c51a20acb..3193ea5f41c9ab07c99101ab03ce18f818f77665 100644 (file)
@@ -1,3 +1,30 @@
+/**************************************************************************
+ * 
+ * Copyright 2009 Younes Manton.
+ * All Rights Reserved.
+ * 
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ * 
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ * 
+ **************************************************************************/
+
 #include "vl_bitstream_parser.h"
 #include <assert.h>
 #include <limits.h>
@@ -23,12 +50,12 @@ show_bits(unsigned cursor, unsigned how_many_bits, const unsigned *bitstream)
        
    assert(bitstream);
        
-   if (cur_bit + how_many_bits > sizeof(unsigned) * CHAR_BIT)
-   {
-      return grab_bits(cur_bit, sizeof(unsigned) * CHAR_BIT - cur_bit,
-                       bitstream[cur_int]) |
-             grab_bits(0, cur_bit + how_many_bits - sizeof(unsigned) * CHAR_BIT,
-                       bitstream[cur_int + 1]) << (sizeof(unsigned) * CHAR_BIT - cur_bit);
+   if (cur_bit + how_many_bits > sizeof(unsigned) * CHAR_BIT) {
+      unsigned lower = grab_bits(cur_bit, sizeof(unsigned) * CHAR_BIT - cur_bit,
+                                 bitstream[cur_int]);
+      unsigned upper = grab_bits(0, cur_bit + how_many_bits - sizeof(unsigned) * CHAR_BIT,
+                                 bitstream[cur_int + 1]);
+      return lower | upper << (sizeof(unsigned) * CHAR_BIT - cur_bit);
    }
    else
       return grab_bits(cur_bit, how_many_bits, bitstream[cur_int]);
@@ -87,16 +114,14 @@ vl_bitstream_parser_show_bits(struct vl_bitstream_parser *parser,
    cursor = parser->cursor;
    cur_bitstream = parser->cur_bitstream;
 
-   while (1)
-   {
+   while (1) {
       unsigned bits_left = parser->sizes[cur_bitstream] * CHAR_BIT - cursor;
       unsigned bits_to_show = how_many_bits > bits_left ? bits_left : how_many_bits;
 
       bits |= show_bits(cursor, bits_to_show,
                         parser->bitstreams[cur_bitstream]) << shift;
                
-      if (how_many_bits > bits_to_show)
-      {
+      if (how_many_bits > bits_to_show) {
          how_many_bits -= bits_to_show;
          cursor = 0;
          ++cur_bitstream;
@@ -117,8 +142,7 @@ void vl_bitstream_parser_forward(struct vl_bitstream_parser *parser,
 
    parser->cursor += how_many_bits;
 
-   while (parser->cursor > parser->sizes[parser->cur_bitstream] * CHAR_BIT)
-   {
+   while (parser->cursor > parser->sizes[parser->cur_bitstream] * CHAR_BIT) {
       parser->cursor -= parser->sizes[parser->cur_bitstream++] * CHAR_BIT;
       assert(parser->cur_bitstream < parser->num_bitstreams);
    }
@@ -134,8 +158,7 @@ void vl_bitstream_parser_rewind(struct vl_bitstream_parser *parser,
        
    c = parser->cursor - how_many_bits;
 
-   while (c < 0)
-   {
+   while (c < 0) {
       c += parser->sizes[parser->cur_bitstream--] * CHAR_BIT;
       assert(parser->cur_bitstream < parser->num_bitstreams);
    }