Given a bitmap handle, breaks a bitmap into smaller pieces. Note, this routine isn't terrible fast or efficient, and you must free the bitmaps returned to you in the bm_array
| 1419 | // Note, this routine isn't terrible fast or efficient, and you |
| 1420 | // must free the bitmaps returned to you in the bm_array |
| 1421 | bool bm_CreateChunkedBitmap(int bm_handle, chunked_bitmap *chunk) { |
| 1422 | int i; |
| 1423 | int *bm_array; |
| 1424 | int bw = bm_w(bm_handle, 0); |
| 1425 | int bh = bm_h(bm_handle, 0); |
| 1426 | // determine optimal size of the square bitmaps |
| 1427 | float fopt = 128.0f; |
| 1428 | int iopt; |
| 1429 | // find the smallest dimension and base off that |
| 1430 | int smallest = std::min(bw, bh); |
| 1431 | if (smallest <= 32) |
| 1432 | fopt = 32; |
| 1433 | else if (smallest <= 64) |
| 1434 | fopt = 64; |
| 1435 | else |
| 1436 | fopt = 128; |
| 1437 | iopt = (int)fopt; |
| 1438 | // Get how many pieces we need across and down |
| 1439 | float temp = bw / fopt; |
| 1440 | int how_many_across = temp; |
| 1441 | if ((temp - how_many_across) > 0) |
| 1442 | how_many_across++; |
| 1443 | temp = bh / fopt; |
| 1444 | int how_many_down = temp; |
| 1445 | if ((temp - how_many_down) > 0) |
| 1446 | how_many_down++; |
| 1447 | ASSERT(how_many_across > 0); |
| 1448 | ASSERT(how_many_down > 0); |
| 1449 | // Allocate memory to hold our list of pieces |
| 1450 | bm_array = (int *)mem_malloc(how_many_down * how_many_across * sizeof(int)); |
| 1451 | ASSERT(bm_array); |
| 1452 | for (i = 0; i < how_many_down * how_many_across; i++) { |
| 1453 | bm_array[i] = bm_AllocBitmap(iopt, iopt, 0); |
| 1454 | ASSERT(bm_array[i] > -1); |
| 1455 | // Fill our new pieces with transparency |
| 1456 | bm_ClearBitmap(bm_array[i]); |
| 1457 | } |
| 1458 | // Now go through our big bitmap and partition it into pieces |
| 1459 | uint16_t *src_data = bm_data(bm_handle, 0); |
| 1460 | uint16_t *sdata; |
| 1461 | uint16_t *ddata; |
| 1462 | int shift; |
| 1463 | switch (iopt) { |
| 1464 | case 32: |
| 1465 | shift = 5; |
| 1466 | break; |
| 1467 | case 64: |
| 1468 | shift = 6; |
| 1469 | break; |
| 1470 | case 128: |
| 1471 | shift = 7; |
| 1472 | break; |
| 1473 | default: |
| 1474 | Int3(); // Get Jeff |
| 1475 | break; |
| 1476 | } |
| 1477 | int maxx, maxy; |
| 1478 | int windex, hindex; |
no test coverage detected