Builds the bumpmaps for the past in texture
| 737 | |
| 738 | // Builds the bumpmaps for the past in texture |
| 739 | void BuildTextureBumpmaps(int texhandle) { |
| 740 | int i, t; |
| 741 | int8_t *buffer; |
| 742 | |
| 743 | if (GameTextures[texhandle].flags & TF_ANIMATED) |
| 744 | return; // No bumps for animated textures |
| 745 | |
| 746 | mprintf(0, "Calculating bumpmap for texture named %s.\n", GameTextures[texhandle].name); |
| 747 | |
| 748 | // Make sure there is no bump already |
| 749 | ASSERT(GameTextures[texhandle].bumpmap == -1); |
| 750 | |
| 751 | // Get width and height |
| 752 | int w = bm_w(GameTextures[texhandle].bm_handle, 0); |
| 753 | int h = bm_h(GameTextures[texhandle].bm_handle, 0); |
| 754 | |
| 755 | // Allocate a bumpmap |
| 756 | int bump = bump_AllocBumpmap(w, h); |
| 757 | ASSERT(bump != -1); |
| 758 | GameTextures[texhandle].bumpmap = bump; |
| 759 | |
| 760 | // allocate memory for our buffer |
| 761 | buffer = (int8_t *)mem_malloc(w * h); |
| 762 | ASSERT(buffer); |
| 763 | |
| 764 | uint16_t *src_data = (uint16_t *)bm_data(GameTextures[texhandle].bm_handle, 0); |
| 765 | |
| 766 | // create the grayscale |
| 767 | for (i = 0; i < h; i++) { |
| 768 | for (t = 0; t < w; t++) { |
| 769 | uint16_t color = src_data[i * w + t]; |
| 770 | |
| 771 | int red = ((color >> 10) & 0x1f) << 3; |
| 772 | int green = ((color >> 5) & 0x1f) << 3; |
| 773 | int blue = ((color) & 0x1f) << 3; |
| 774 | |
| 775 | buffer[i * w + t] = (int8_t)(0.29 * red + 0.60 * green + 0.11 * blue); |
| 776 | } |
| 777 | } |
| 778 | |
| 779 | uint16_t *dest_data = (uint16_t *)bump_data(bump); |
| 780 | |
| 781 | for (i = 0; i < h; i++) { |
| 782 | int8_t *pDst = (int8_t *)(dest_data + i * w); |
| 783 | for (t = 0; t < w; t++) { |
| 784 | int v00, v01, v10; |
| 785 | |
| 786 | v00 = buffer[(i * w + t)]; // Get current pixel. *3 for 24 bits src |
| 787 | |
| 788 | if (t == w - 1) // Special case for last column |
| 789 | v01 = buffer[(i * w + t)]; // Get pixel to the right |
| 790 | else |
| 791 | v01 = buffer[(i * h + t + 1)]; // Get pixel to the right |
| 792 | |
| 793 | if (i == h - 1) // Special case for last row |
| 794 | v10 = buffer[i * w + t]; // Get pixel one line below |
| 795 | else |
| 796 | v10 = buffer[((i + 1) * w) + t]; // Get pixel one line below |
no test coverage detected