Blender  V2.93
bitmap.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2012 by Nicholas Bishop
17  * All rights reserved.
18  */
19 
26 #include <limits.h>
27 #include <string.h>
28 
29 #include "BLI_bitmap.h"
30 #include "BLI_utildefines.h"
31 
33 void BLI_bitmap_set_all(BLI_bitmap *bitmap, bool set, size_t bits)
34 {
35  memset(bitmap, set ? UCHAR_MAX : 0, BLI_BITMAP_SIZE(bits));
36 }
37 
39 void BLI_bitmap_flip_all(BLI_bitmap *bitmap, size_t bits)
40 {
41  size_t num_blocks = _BITMAP_NUM_BLOCKS(bits);
42  for (size_t i = 0; i < num_blocks; i++) {
43  bitmap[i] ^= ~(BLI_bitmap)0;
44  }
45 }
46 
48 void BLI_bitmap_copy_all(BLI_bitmap *dst, const BLI_bitmap *src, size_t bits)
49 {
50  memcpy(dst, src, BLI_BITMAP_SIZE(bits));
51 }
52 
54 void BLI_bitmap_and_all(BLI_bitmap *dst, const BLI_bitmap *src, size_t bits)
55 {
56  size_t num_blocks = _BITMAP_NUM_BLOCKS(bits);
57  for (size_t i = 0; i < num_blocks; i++) {
58  dst[i] &= src[i];
59  }
60 }
61 
63 void BLI_bitmap_or_all(BLI_bitmap *dst, const BLI_bitmap *src, size_t bits)
64 {
65  size_t num_blocks = _BITMAP_NUM_BLOCKS(bits);
66  for (size_t i = 0; i < num_blocks; i++) {
67  dst[i] |= src[i];
68  }
69 }
#define _BITMAP_NUM_BLOCKS(_tot)
Definition: BLI_bitmap.h:44
#define BLI_BITMAP_SIZE(_tot)
Definition: BLI_bitmap.h:47
unsigned int BLI_bitmap
Definition: BLI_bitmap.h:32
void BLI_bitmap_or_all(BLI_bitmap *dst, const BLI_bitmap *src, size_t bits)
Definition: bitmap.c:63
void BLI_bitmap_and_all(BLI_bitmap *dst, const BLI_bitmap *src, size_t bits)
Definition: bitmap.c:54
void BLI_bitmap_copy_all(BLI_bitmap *dst, const BLI_bitmap *src, size_t bits)
Definition: bitmap.c:48
void BLI_bitmap_set_all(BLI_bitmap *bitmap, bool set, size_t bits)
Definition: bitmap.c:33
void BLI_bitmap_flip_all(BLI_bitmap *bitmap, size_t bits)
Definition: bitmap.c:39