Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(527)

Side by Side Diff: third_party/libwebp/utils/bit_writer_utils.c

Issue 2651883004: libwebp-0.6.0-rc1 (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/libwebp/utils/bit_writer_utils.h ('k') | third_party/libwebp/utils/color_cache.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 Google Inc. All Rights Reserved. 1 // Copyright 2011 Google Inc. All Rights Reserved.
2 // 2 //
3 // Use of this source code is governed by a BSD-style license 3 // Use of this source code is governed by a BSD-style license
4 // that can be found in the COPYING file in the root of the source 4 // that can be found in the COPYING file in the root of the source
5 // tree. An additional intellectual property rights grant can be found 5 // tree. An additional intellectual property rights grant can be found
6 // in the file PATENTS. All contributing project authors may 6 // in the file PATENTS. All contributing project authors may
7 // be found in the AUTHORS file in the root of the source tree. 7 // be found in the AUTHORS file in the root of the source tree.
8 // ----------------------------------------------------------------------------- 8 // -----------------------------------------------------------------------------
9 // 9 //
10 // Bit writing and boolean coder 10 // Bit writing and boolean coder
11 // 11 //
12 // Author: Skal (pascal.massimino@gmail.com) 12 // Author: Skal (pascal.massimino@gmail.com)
13 // Vikas Arora (vikaas.arora@gmail.com) 13 // Vikas Arora (vikaas.arora@gmail.com)
14 14
15 #include <assert.h> 15 #include <assert.h>
16 #include <string.h> // for memcpy() 16 #include <string.h> // for memcpy()
17 #include <stdlib.h> 17 #include <stdlib.h>
18 18
19 #include "./bit_writer.h" 19 #include "./bit_writer_utils.h"
20 #include "./endian_inl.h" 20 #include "./endian_inl_utils.h"
21 #include "./utils.h" 21 #include "./utils.h"
22 22
23 //------------------------------------------------------------------------------ 23 //------------------------------------------------------------------------------
24 // VP8BitWriter 24 // VP8BitWriter
25 25
26 static int BitWriterResize(VP8BitWriter* const bw, size_t extra_size) { 26 static int BitWriterResize(VP8BitWriter* const bw, size_t extra_size) {
27 uint8_t* new_buf; 27 uint8_t* new_buf;
28 size_t new_size; 28 size_t new_size;
29 const uint64_t needed_size_64b = (uint64_t)bw->pos_ + extra_size; 29 const uint64_t needed_size_64b = (uint64_t)bw->pos_ + extra_size;
30 const size_t needed_size = (size_t)needed_size_64b; 30 const size_t needed_size = (size_t)needed_size_64b;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 bw->value_ <<= 1; 136 bw->value_ <<= 1;
137 bw->nb_bits_ += 1; 137 bw->nb_bits_ += 1;
138 if (bw->nb_bits_ > 0) Flush(bw); 138 if (bw->nb_bits_ > 0) Flush(bw);
139 } 139 }
140 return bit; 140 return bit;
141 } 141 }
142 142
143 void VP8PutBits(VP8BitWriter* const bw, uint32_t value, int nb_bits) { 143 void VP8PutBits(VP8BitWriter* const bw, uint32_t value, int nb_bits) {
144 uint32_t mask; 144 uint32_t mask;
145 assert(nb_bits > 0 && nb_bits < 32); 145 assert(nb_bits > 0 && nb_bits < 32);
146 for (mask = 1u << (nb_bits - 1); mask; mask >>= 1) 146 for (mask = 1u << (nb_bits - 1); mask; mask >>= 1) {
147 VP8PutBitUniform(bw, value & mask); 147 VP8PutBitUniform(bw, value & mask);
148 }
148 } 149 }
149 150
150 void VP8PutSignedBits(VP8BitWriter* const bw, int value, int nb_bits) { 151 void VP8PutSignedBits(VP8BitWriter* const bw, int value, int nb_bits) {
151 if (!VP8PutBitUniform(bw, value != 0)) 152 if (!VP8PutBitUniform(bw, value != 0)) return;
152 return;
153 if (value < 0) { 153 if (value < 0) {
154 VP8PutBits(bw, ((-value) << 1) | 1, nb_bits + 1); 154 VP8PutBits(bw, ((-value) << 1) | 1, nb_bits + 1);
155 } else { 155 } else {
156 VP8PutBits(bw, value << 1, nb_bits + 1); 156 VP8PutBits(bw, value << 1, nb_bits + 1);
157 } 157 }
158 } 158 }
159 159
160 //------------------------------------------------------------------------------ 160 //------------------------------------------------------------------------------
161 161
162 int VP8BitWriterInit(VP8BitWriter* const bw, size_t expected_size) { 162 int VP8BitWriterInit(VP8BitWriter* const bw, size_t expected_size) {
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 *bw->cur_++ = (uint8_t)bw->bits_; 310 *bw->cur_++ = (uint8_t)bw->bits_;
311 bw->bits_ >>= 8; 311 bw->bits_ >>= 8;
312 bw->used_ -= 8; 312 bw->used_ -= 8;
313 } 313 }
314 bw->used_ = 0; 314 bw->used_ = 0;
315 } 315 }
316 return bw->buf_; 316 return bw->buf_;
317 } 317 }
318 318
319 //------------------------------------------------------------------------------ 319 //------------------------------------------------------------------------------
OLDNEW
« no previous file with comments | « third_party/libwebp/utils/bit_writer_utils.h ('k') | third_party/libwebp/utils/color_cache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698