Bug Summary

File:home/HaikuArchives/ArtPaint/artpaint/Utilities/BitmapUtilities.cpp
Warning:line 197, column 9
Value stored to 'cur_color' during its initialization is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-haiku -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name BitmapUtilities.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model static -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /boot/system/lib/clang/12.0.1 -iquote ./ -iquote artpaint/ -iquote artpaint/Utilities/ -iquote artpaint/application/ -iquote artpaint/controls/ -iquote artpaint/layers/ -iquote artpaint/paintwindow/ -iquote artpaint/tools/ -iquote artpaint/viewmanipulators/ -iquote artpaint/windows/ -iquote objects_artpaint/ -isystem /boot/system/develop/headers/private/interface -internal-isystem /system/develop/headers/c++ -internal-isystem /system/develop/headers/c++/x86_64-unknown-haiku -internal-isystem /system/develop/headers/c++/backward -O3 -fdeprecated-macro -fdebug-compilation-dir /boot/home/HaikuArchives/ArtPaint -ferror-limit 19 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -o /tmp/scan-build-2022-06-19-103017-1294-1 -x c++ artpaint/Utilities/BitmapUtilities.cpp
1/*
2 * Copyright 2003, Heikki Suhonen
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 * Heikki Suhonen <heikki.suhonen@gmail.com>
7 * Dale Cieslak <dcieslak@yahoo.com>
8 *
9 */
10#include "BitmapUtilities.h"
11
12
13#include "PixelOperations.h"
14
15
16#include <Screen.h>
17
18
19status_t
20BitmapUtilities::FixMissingAlpha(BBitmap *bitmap)
21{
22 uint32 *bits = (uint32*)bitmap->Bits();
23 int32 bits_length = bitmap->BitsLength()/4;
24
25 if (bitmap->ColorSpace() != B_RGB32)
26 return B_BAD_TYPE((-2147483647 -1) + 4);
27
28
29 union {
30 uint8 bytes[4];
31 uint32 word;
32 } c;
33
34 for (int32 i=0;i<bits_length;i++) {
35 c.word = *bits++;
36 if (c.bytes[3] != 0) {
37 return B_OK((int)0);
38 }
39 }
40
41 bits = (uint32*)bitmap->Bits();
42 c.word = 0x00000000;
43 c.bytes[3] = 255;
44 for (int32 i=0;i<bits_length;i++) {
45 *bits = *bits | c.word;
46 bits++;
47 }
48
49 return B_OK((int)0);
50}
51
52
53
54BBitmap*
55BitmapUtilities::ConvertColorSpace(BBitmap *inBitmap, color_space wantSpace)
56{
57 if (inBitmap->ColorSpace() == wantSpace) {
58 return inBitmap;
59 }
60 else if (wantSpace == B_RGBA32) {
61 switch (inBitmap->ColorSpace()) {
62 case B_RGB32:
63 return inBitmap;
64
65 case B_CMAP8:
66 {
67 BBitmap *out_map = new BBitmap(inBitmap->Bounds(),wantSpace);
68 uint32 *out_bits = (uint32*)out_map->Bits();
69 int32 out_bpr = out_map->BytesPerRow()/4;
70
71 uint8 *in_bits = (uint8*)inBitmap->Bits();
72 int32 in_bpr = inBitmap->BytesPerRow();
73
74 union {
75 uint8 bytes[4];
76 uint32 word;
77 } c;
78
79 c.bytes[3] = 0xff;
80
81 BScreen screen;
82 const rgb_color *color_list = screen.ColorMap()->color_list;
83
84 for (int32 y=0;y<out_map->Bounds().IntegerHeight();y++) {
85 for (int32 x=0;x<out_map->Bounds().IntegerWidth();x++) {
86 rgb_color color = color_list[*(in_bits + x + y*in_bpr)];
87 c.bytes[0] = color.blue;
88 c.bytes[1] = color.green;
89 c.bytes[2] = color.red;
90
91 *(out_bits + x + y*out_bpr) = c.word;
92 }
93 }
94
95 delete inBitmap;
96
97 return out_map;
98 }
99
100 default:
101 return NULL__null;
102 }
103 }
104 else {
105 return NULL__null;
106 }
107}
108
109
110void
111BitmapUtilities::CompositeBitmapOnSource(BBitmap* toBuffer, BBitmap* srcBuffer, BBitmap* fromBuffer,
112 BRect updated_rect)
113{
114 updated_rect = updated_rect & toBuffer->Bounds();
115
116 int32 bpr = toBuffer->BytesPerRow() / 4;
117 int32 width = updated_rect.IntegerWidth()+1;
118 int32 height = updated_rect.IntegerHeight()+1;
119
120 int32 start_x, start_y;
121 start_x = (int32)updated_rect.left;
122 start_y = (int32)updated_rect.top;
123
124 uint32* bits = (uint32*)toBuffer->Bits();
125 bits += bpr*start_y + start_x;
126
127 uint32* src_bits = (uint32*)srcBuffer->Bits();
128 uint32* from_bits = (uint32*)fromBuffer->Bits();
129 src_bits += bpr*start_y + start_x;
130 from_bits += bpr*start_y + start_x;
131
132 for (int y=0;y<height;y++) {
133 int32 ypos = y*bpr;
134 for (int x=0;x<width;x++) {
135 *bits++ = src_over_fixed(*(src_bits + x + ypos),
136 *(from_bits + x + ypos));
137 }
138 bits += bpr - width;
139 }
140}
141
142
143void
144BitmapUtilities::ClearBitmap(BBitmap* bitmap, uint32 color, BRect* area)
145{
146 uint32 width = bitmap->Bounds().IntegerWidth()+1;
147 uint32 height = bitmap->Bounds().IntegerHeight()+1;
148 uint32 bpr = bitmap->BytesPerRow() / 4;
149
150 int32 start_x = 0;
151 int32 start_y = 0;
152
153 if (area) {
154 width = area->IntegerWidth()+1;
155 height = area->IntegerHeight()+1;
156 start_x = (int32)area->left;
157 start_y = (int32)area->top;
158 }
159
160 uint32* bits = (uint32*)bitmap->Bits();
161 bits += start_x + bpr * start_y;
162
163 for (int y = 0;y < height;++y) {
164 for (int x = 0;x < width;++x) {
165 *bits++ = color;
166 }
167 bits += bpr - width;
168 }
169}
170
171
172void
173BitmapUtilities::CheckerBitmap(BBitmap* bitmap,
174 uint32 color1, uint32 color2, uint32 grid_size,
175 BRect* area)
176{
177 uint32 width = bitmap->Bounds().IntegerWidth()+1;
178 uint32 height = bitmap->Bounds().IntegerHeight()+1;
179 uint32 bpr = bitmap->BytesPerRow() / 4;
180
181 int32 start_x = 0;
182 int32 start_y = 0;
183
184 if (area) {
185 *area = *area & bitmap->Bounds();
186 width = area->IntegerWidth()+1;
187 height = area->IntegerHeight()+1;
188 if (width > bitmap->Bounds().IntegerWidth()+1)
189 return;
190 if (height > bitmap->Bounds().IntegerHeight()+1)
191 return;
192 start_x = (int32)area->left;
193 start_y = (int32)area->top;
194 }
195
196 uint32 grid_color[2] = { color1, color2 };
197 uint32 cur_color = grid_color[0];
Value stored to 'cur_color' during its initialization is never read
198
199 uint32* bits = (uint32*)bitmap->Bits();
200 bits += start_x + bpr * start_y;
201 uint32 row_size = bpr - width;
202
203 for (int y = start_y;y < height+start_y;++y) {
204 int rowMod2 = (y / grid_size) % 2;
205 for (int x = start_x;x < width+start_x;++x) {
206 int col = x / grid_size;
207 if (rowMod2 == col % 2)
208 cur_color = grid_color[1];
209 else
210 cur_color = grid_color[0];
211
212 *bits++ = cur_color;
213 }
214 bits += row_size;
215 }
216}