MCPcopy Create free account
hub / github.com/coreboot/coreboot / truncate_bitmap_buffer

Function truncate_bitmap_buffer

src/lib/vga_gfx.c:158–245  ·  view source on GitHub ↗

* Truncates the content of the bitmap buffer in-place, moving * set pixels to the top-left corner and clearing the rest. * Ensures truncated width and height are multiples of 8. * @param truncated_width Output pointer for the new width. * @param truncated_height Output pointer for the new height. */

Source from the content-addressed store, hash-verified

156 * @param truncated_height Output pointer for the new height.
157 */
158static void truncate_bitmap_buffer(
159 int *truncated_width, int *truncated_height)
160{
161 int min_pixel_x = INT_MAX, max_pixel_x = INT_MIN;
162 int min_pixel_y = INT_MAX, max_pixel_y = INT_MIN;
163 bool found_pixel = false;
164
165 /* Validate input params */
166 if (!truncated_width || !truncated_height)
167 return;
168
169 /* Scan the source buffer to find the actual bounding box of
170 * set pixels
171 */
172 for (int y = 0; y < buffer_height; y++) {
173 for (int x = 0; x < buffer_width; x++) {
174 if (get_raw_pixel(x, y)) {
175 min_pixel_x = MIN(min_pixel_x, x);
176 max_pixel_x = MAX(max_pixel_x, x);
177 min_pixel_y = MIN(min_pixel_y, y);
178 max_pixel_y = MAX(max_pixel_y, y);
179 found_pixel = true;
180 }
181 }
182 }
183
184 if (!found_pixel) {
185 /* No set pixels found, effectively empty. */
186 memset(buffer, 0, buffer_width * buffer_height / BITS_PER_BYTE);
187 *truncated_width = 0;
188 *truncated_height = 0;
189 printk(BIOS_ERR, "BITMAP: Unable to crop. No pixels\n");
190 return;
191 }
192
193 /*
194 * The width of the truncated content in pixels, rounded up to
195 * multiple of FONT_WIDTH.
196 */
197 int min_byte_x = (min_pixel_x / BITS_PER_BYTE);
198 int max_byte_x = (max_pixel_x / BITS_PER_BYTE);
199 int new_content_width = (max_byte_x - min_byte_x + 1) * BITS_PER_BYTE;
200 new_content_width += FONT_WIDTH - 1;
201 new_content_width /= FONT_WIDTH;
202 new_content_width *= FONT_WIDTH;
203 new_content_width = MIN(new_content_width, buffer_width);
204
205 /*
206 * The height of the truncated content in pixels, rounded up to
207 * multiple of FONT_HEIGHT.
208 */
209 int new_content_height = max_pixel_y - min_pixel_y + 1;
210 new_content_height += FONT_HEIGHT - 1;
211 new_content_height /= FONT_HEIGHT;
212 new_content_height *= FONT_HEIGHT;
213 new_content_height = MIN(new_content_height, buffer_height);
214
215 /* Calculate number of bytes per row */

Callers 1

Calls 4

get_raw_pixelFunction · 0.85
memsetFunction · 0.70
memcpyFunction · 0.70
printkFunction · 0.50

Tested by

no test coverage detected