| 1 | /* |
| 2 | * Descent 3 |
| 3 | * Copyright (C) 2024 Parallax Software |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | // Lightmap info |
| 20 | #include "pstypes.h"cxx . . $ `<file>/lib/pstypes.h`/ |
| 21 | |
| 22 | #include "lightmap_info.h"cxx . . $ `<file>/Descent3/lightmap_info.h`/ |
| 23 | #include "lightmap.h"cxx . . $ `<file>/lib/lightmap.h`/ |
| 24 | #include "mono.h"cxx . . $ `<file>/ddebug/mono.h`/ |
| 25 | #include "Ddgr.h"cxx . . $ `<file>/lib/Ddgr.h`/ |
| 26 | #include "grdefs.h"cxx . . $ `<file>/lib/grdefs.h`/ |
| 27 | #include "renderer.h"cxx . . $ `<file>/lib/renderer.h`/ |
| 28 | #include <stdlib.h> |
| 29 | #include <string.h> |
| 30 | #include "mem.h"cxx . . $ `<file>/mem/mem.h`/ |
| 31 | #include "dedicated_server.h"cxx . . $ `<file>/lib/dedicated_server.h`/ |
| 32 | |
| 33 | int Num_of_lightmap_infocxx . . $ Num_of_lightmap_info. = 0; |
| 34 | lightmap_infocxx . . $ lightmap_info# *LightmapInfocxx . . $ LightmapInfo. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 35 | |
| 36 | static uint16_tcxx . . $ uint16_t# *Free_lmi_listcxx . . $ Free_lmi_list. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 37 | |
| 38 | void CloseLightmapInfoscxx . . $ CloseLightmapInfos(49f6e7a06ebc5aa8).() { |
| 39 | bool final_lightmap = true; |
| 40 | |
| 41 | if (LightmapInfocxx . . $ LightmapInfo.) |
| 42 | mem_freecxx . . $ `mem/mem.h:80:9`!(LightmapInfo); |
| 43 | |
| 44 | if (Free_lmi_listcxx . . $ Free_lmi_list.) |
| 45 | mem_freecxx . . $ `mem/mem.h:80:9`!(Free_lmi_list); |
| 46 | |
| 47 | LightmapInfocxx . . $ LightmapInfo. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 48 | Free_lmi_listcxx . . $ Free_lmi_list. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 49 | } |
| 50 | |
| 51 | // Sets all the lightmaps to unused |
| 52 | void InitLightmapInfocxx . . $ InitLightmapInfo(d4f767463ce0a6b3).(int nummaps) { |
| 53 | int i; |
| 54 | |
| 55 | if (Dedicated_servercxx . . $ Dedicated_server.) |
| 56 | return; |
| 57 | |
| 58 | if (nummaps == 0) { |
| 59 | LightmapInfocxx . . $ LightmapInfo. = (lightmap_infocxx . . $ lightmap_info# *)mem_malloccxx . . $ `mem/mem.h:79:9`!(MAX_LIGHTMAP_INFOScxx . . $ `Descent3/lightmap_info.h:74:9`! * sizeof(lightmap_info)); |
| 60 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(LightmapInfo); |
| 61 | Free_lmi_listcxx . . $ Free_lmi_list. = (uint16_tcxx . . $ uint16_t# *)mem_malloccxx . . $ `mem/mem.h:79:9`!(MAX_LIGHTMAP_INFOScxx . . $ `Descent3/lightmap_info.h:74:9`! * sizeof(uint16_t)); |
| 62 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(Free_lmi_list); |
| 63 | |
| 64 | for (i = 0; i < MAX_LIGHTMAP_INFOScxx . . $ `Descent3/lightmap_info.h:74:9`!; i++) { |
| 65 | LightmapInfocxx . . $ LightmapInfo.[i].usedcxx . . $ lightmap_info#used. = 0; |
| 66 | Free_lmi_listcxx . . $ Free_lmi_list.[i] = i; |
| 67 | } |
| 68 | } |
| 69 | /* //DAJ this did not work! the lm_FreeLightmap() is refcount-- not a free() |
| 70 | else { |
| 71 | LightmapInfo=(lightmap_info *)mem_malloc (nummaps*sizeof(lightmap_info)); |
| 72 | ASSERT (LightmapInfo); |
| 73 | Free_lmi_list=(uint16_t *)mem_malloc (nummaps*sizeof(uint16_t)); |
| 74 | ASSERT (Free_lmi_list); |
| 75 | |
| 76 | |
| 77 | for (i=0;i<nummaps;i++) |
| 78 | { |
| 79 | LightmapInfo[i].used=0; |
| 80 | Free_lmi_list[i]=i; |
| 81 | } |
| 82 | } |
| 83 | */ |
| 84 | Num_of_lightmap_infocxx . . $ Num_of_lightmap_info. = 0; |
| 85 | atexit(CloseLightmapInfoscxx . . $ CloseLightmapInfos(49f6e7a06ebc5aa8).); |
| 86 | } |
| 87 | // Allocs a lightmap of w x h size |
| 88 | // Returns lightmap handle if successful, -1 if otherwise |
| 89 | |
| 90 | int AllocLightmapInfocxx . . $ AllocLightmapInfo(b2eaad3020ba259e).(int w, int h, int type, bool alloc_lightmap) { |
| 91 | int n, i; |
| 92 | |
| 93 | if (Dedicated_servercxx . . $ Dedicated_server.) |
| 94 | Int3cxx . . $ `misc/pserror.h:247:9`!(); // Shouldn't be here! |
| 95 | |
| 96 | if (Num_of_lightmap_infocxx . . $ Num_of_lightmap_info. > MAX_LIGHTMAP_INFOScxx . . $ `Descent3/lightmap_info.h:74:9`!) |
| 97 | Int3cxx . . $ `misc/pserror.h:247:9`!(); // Get Jason, ran out of lightmaps! |
| 98 | |
| 99 | n = Free_lmi_listcxx . . $ Free_lmi_list.[Num_of_lightmap_infocxx . . $ Num_of_lightmap_info.++]; |
| 100 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(LightmapInfo[n].used == 0); |
| 101 | |
| 102 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(n >= 0 && n < MAX_LIGHTMAP_INFOScxx . . $ `Descent3/lightmap_info.h:74:9`!); |
| 103 | |
| 104 | /*for (i=Highest_lmi_index;i<MAX_LIGHTMAP_INFOS;i++) |
| 105 | { |
| 106 | if (LightmapInfo[i].used==0) |
| 107 | { |
| 108 | n=i; |
| 109 | break; |
| 110 | } |
| 111 | }*/ |
| 112 | |
| 113 | // If we can't find a free slot in which to alloc, bail out |
| 114 | /*if (i==MAX_LIGHTMAP_INFOS) |
| 115 | { |
| 116 | Int3(); |
| 117 | mprintf(0,"ERROR! Couldn't find a free lightmap info to alloc!\n"); |
| 118 | return -1; |
| 119 | }*/ |
| 120 | |
| 121 | memset(&LightmapInfocxx . . $ LightmapInfo.[n], 0, sizeof(lightmap_infocxx . . $ lightmap_info#)); |
| 122 | |
| 123 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(w >= 2 && h >= 2); |
| 124 | |
| 125 | if (alloc_lightmap) { |
| 126 | LightmapInfocxx . . $ LightmapInfo.[n].lm_handlecxx . . $ lightmap_info#lm_handle. = lm_AllocLightmapcxx . . $ lm_AllocLightmap(9b79fb6aee4c0440).(w, h); |
| 127 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(LightmapInfo[n].lm_handle != BAD_LM_INDEXcxx . . $ `lib/lightmap.h:25:9`!); // Make sure we have a valid lightmap |
| 128 | |
| 129 | uint16_tcxx . . $ uint16_t# *dest_data = lm_datacxx . . $ lm_data(2fbd6a760478ca0f).(LightmapInfocxx . . $ LightmapInfo.[n].lm_handlecxx . . $ lightmap_info#lm_handle.); |
| 130 | |
| 131 | // Set the lightmap to be transparent |
| 132 | for (i = 0; i < w * h; i++) |
| 133 | dest_data[i] = NEW_TRANSPARENT_COLORcxx . . $ `lib/grdefs.h:71:9`!; |
| 134 | } |
| 135 | |
| 136 | LightmapInfocxx . . $ LightmapInfo.[n].usedcxx . . $ lightmap_info#used. = 1; |
| 137 | LightmapInfocxx . . $ LightmapInfo.[n].typecxx . . $ lightmap_info#type. = type; |
| 138 | LightmapInfocxx . . $ LightmapInfo.[n].dynamiccxx . . $ lightmap_info#dynamic. = BAD_LM_INDEXcxx . . $ `lib/lightmap.h:25:9`!; |
| 139 | LightmapInfocxx . . $ LightmapInfo.[n].spec_mapcxx . . $ lightmap_info#spec_map. = -1; |
| 140 | LightmapInfocxx . . $ LightmapInfo.[n].widthcxx . . $ lightmap_info#width. = w; |
| 141 | LightmapInfocxx . . $ LightmapInfo.[n].heightcxx . . $ lightmap_info#height. = h; |
| 142 | LightmapInfocxx . . $ LightmapInfo.[n].x1cxx . . $ lightmap_info#x1. = 0; |
| 143 | LightmapInfocxx . . $ LightmapInfo.[n].y1cxx . . $ lightmap_info#y1. = 0; |
| 144 | |
| 145 | return n; |
| 146 | } |
| 147 | |
| 148 | // Given a handle, frees the lightmap memory and flags this lightmap as unused |
| 149 | void FreeLightmapInfocxx . . $ FreeLightmapInfo(d4f767463ce0a6b3).(int handle) { |
| 150 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(handle >= 0 && handle <= MAX_LIGHTMAP_INFOScxx . . $ `Descent3/lightmap_info.h:74:9`!); |
| 151 | |
| 152 | if (Dedicated_servercxx . . $ Dedicated_server.) |
| 153 | return; |
| 154 | |
| 155 | // when we free up our rooms, which frees up lightmaps, the lightmap array |
| 156 | // may already be freed |
| 157 | if (!LightmapInfocxx . . $ LightmapInfo.) |
| 158 | return; |
| 159 | |
| 160 | if (LightmapInfocxx . . $ LightmapInfo.[handle].usedcxx . . $ lightmap_info#used. < 1) |
| 161 | return; |
| 162 | |
| 163 | LightmapInfocxx . . $ LightmapInfo.[handle].usedcxx . . $ lightmap_info#used.--; |
| 164 | |
| 165 | if (LightmapInfocxx . . $ LightmapInfo.[handle].usedcxx . . $ lightmap_info#used. == 0) { |
| 166 | if (!Dedicated_servercxx . . $ Dedicated_server.) |
| 167 | rend_FreePreUploadedTexturecxx . . $ rend_FreePreUploadedTexture(3e454b8ccf442868).(LightmapInfocxx . . $ LightmapInfo.[handle].lm_handlecxx . . $ lightmap_info#lm_handle., MAP_TYPE_LIGHTMAPcxx . . $ `lib/renderer.h:363:9`!); |
| 168 | lm_FreeLightmapcxx . . $ lm_FreeLightmap(d4f767463ce0a6b3).(LightmapInfocxx . . $ LightmapInfo.[handle].lm_handlecxx . . $ lightmap_info#lm_handle.); |
| 169 | |
| 170 | Free_lmi_listcxx . . $ Free_lmi_list.[--Num_of_lightmap_infocxx . . $ Num_of_lightmap_info.] = handle; |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | // Gets the width of this lightmap_info handle |
| 175 | int lmi_wcxx . . $ lmi_w(7864480464b09eea).(int handle) { |
| 176 | if (!LightmapInfocxx . . $ LightmapInfo.[handle].usedcxx . . $ lightmap_info#used.) { |
| 177 | Int3cxx . . $ `misc/pserror.h:247:9`!(); // Get Jason |
| 178 | return 0; |
| 179 | } |
| 180 | |
| 181 | return (LightmapInfocxx . . $ LightmapInfo.[handle].widthcxx . . $ lightmap_info#width.); |
| 182 | } |
| 183 | |
| 184 | // Gets the height of this lightmap_info handle |
| 185 | int lmi_hcxx . . $ lmi_h(7864480464b09eea).(int handle) { |
| 186 | if (!LightmapInfocxx . . $ LightmapInfo.[handle].usedcxx . . $ lightmap_info#used.) { |
| 187 | Int3cxx . . $ `misc/pserror.h:247:9`!(); // Get Jason |
| 188 | return 0; |
| 189 | } |
| 190 | |
| 191 | return (LightmapInfocxx . . $ LightmapInfo.[handle].heightcxx . . $ lightmap_info#height.); |
| 192 | } |
| 193 | |
| 194 | // TODO: MTS: unused? |
| 195 | // Softens the edges of lightmaps so there are fewer artifaces |
| 196 | void ShadeLightmapInfoEdgescxx . . $ ShadeLightmapInfoEdges(d4f767463ce0a6b3).(int type) { |
| 197 | int i; |
| 198 | |
| 199 | for (i = 0; i < MAX_LIGHTMAP_INFOScxx . . $ `Descent3/lightmap_info.h:74:9`!; i++) { |
| 200 | if (LightmapInfocxx . . $ LightmapInfo.[i].usedcxx . . $ lightmap_info#used. && LightmapInfocxx . . $ LightmapInfo.[i].typecxx . . $ lightmap_info#type. == type) { |
| 201 | uint16_tcxx . . $ uint16_t# *src_data; |
| 202 | uint16_tcxx . . $ uint16_t# *dest_data = lm_datacxx . . $ lm_data(2fbd6a760478ca0f).(LightmapInfocxx . . $ LightmapInfo.[i].lm_handlecxx . . $ lightmap_info#lm_handle.); |
| 203 | int w = lmi_wcxx . . $ lmi_w(7864480464b09eea).(i); |
| 204 | int h = lmi_hcxx . . $ lmi_h(7864480464b09eea).(i); |
| 205 | int x, y; |
| 206 | |
| 207 | src_data = (uint16_tcxx . . $ uint16_t# *)mem_malloccxx . . $ `mem/mem.h:79:9`!(w * h * 2); |
| 208 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(src_data); |
| 209 | |
| 210 | memcpy(src_data, dest_data, w * h * 2); |
| 211 | |
| 212 | for (y = 0; y < h; y++) { |
| 213 | for (x = 0; x < w; x++) { |
| 214 | if (!(src_data[y * w + x] & OPAQUE_FLAGcxx . . $ `lib/grdefs.h:72:9`!)) { |
| 215 | int r = 0, g = 0, b = 0; |
| 216 | int num = 0; |
| 217 | ddgr_colorcxx . . $ ddgr_color# color; |
| 218 | uint16_tcxx . . $ uint16_t# color16; |
| 219 | |
| 220 | // Left edge |
| 221 | if (x != 0) { |
| 222 | |
| 223 | color16 = src_data[y * w + (x - 1)]; |
| 224 | if (color16 & OPAQUE_FLAGcxx . . $ `lib/grdefs.h:72:9`!) { |
| 225 | color = GR_16_TO_COLORcxx . . $ GR_16_TO_COLOR(909d59720f161188).(color16); |
| 226 | r += GR_COLOR_REDcxx . . $ GR_COLOR_RED(4c679297bf94b9eb).(color); |
| 227 | g += GR_COLOR_GREENcxx . . $ GR_COLOR_GREEN(4c679297bf94b9eb).(color); |
| 228 | b += GR_COLOR_BLUEcxx . . $ GR_COLOR_BLUE(4c679297bf94b9eb).(color); |
| 229 | num++; |
| 230 | } |
| 231 | |
| 232 | if (y != 0) { |
| 233 | color16 = src_data[(y - 1) * w + (x - 1)]; |
| 234 | if (color16 & OPAQUE_FLAGcxx . . $ `lib/grdefs.h:72:9`!) { |
| 235 | color = GR_16_TO_COLORcxx . . $ GR_16_TO_COLOR(909d59720f161188).(color16); |
| 236 | r += GR_COLOR_REDcxx . . $ GR_COLOR_RED(4c679297bf94b9eb).(color); |
| 237 | g += GR_COLOR_GREENcxx . . $ GR_COLOR_GREEN(4c679297bf94b9eb).(color); |
| 238 | b += GR_COLOR_BLUEcxx . . $ GR_COLOR_BLUE(4c679297bf94b9eb).(color); |
| 239 | num++; |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | if (y != h - 1) { |
| 244 | color16 = src_data[(y + 1) * w + (x - 1)]; |
| 245 | if (color16 & OPAQUE_FLAGcxx . . $ `lib/grdefs.h:72:9`!) { |
| 246 | color = GR_16_TO_COLORcxx . . $ GR_16_TO_COLOR(909d59720f161188).(color16); |
| 247 | r += GR_COLOR_REDcxx . . $ GR_COLOR_RED(4c679297bf94b9eb).(color); |
| 248 | g += GR_COLOR_GREENcxx . . $ GR_COLOR_GREEN(4c679297bf94b9eb).(color); |
| 249 | b += GR_COLOR_BLUEcxx . . $ GR_COLOR_BLUE(4c679297bf94b9eb).(color); |
| 250 | num++; |
| 251 | } |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | // Right edge |
| 256 | if (x != (w - 1)) { |
| 257 | |
| 258 | color16 = src_data[y * w + (x + 1)]; |
| 259 | if (color16 & OPAQUE_FLAGcxx . . $ `lib/grdefs.h:72:9`!) { |
| 260 | color = GR_16_TO_COLORcxx . . $ GR_16_TO_COLOR(909d59720f161188).(color16); |
| 261 | r += GR_COLOR_REDcxx . . $ GR_COLOR_RED(4c679297bf94b9eb).(color); |
| 262 | g += GR_COLOR_GREENcxx . . $ GR_COLOR_GREEN(4c679297bf94b9eb).(color); |
| 263 | b += GR_COLOR_BLUEcxx . . $ GR_COLOR_BLUE(4c679297bf94b9eb).(color); |
| 264 | num++; |
| 265 | } |
| 266 | |
| 267 | if (y != 0) { |
| 268 | color16 = src_data[(y - 1) * w + (x + 1)]; |
| 269 | if (color16 & OPAQUE_FLAGcxx . . $ `lib/grdefs.h:72:9`!) { |
| 270 | color = GR_16_TO_COLORcxx . . $ GR_16_TO_COLOR(909d59720f161188).(color16); |
| 271 | r += GR_COLOR_REDcxx . . $ GR_COLOR_RED(4c679297bf94b9eb).(color); |
| 272 | g += GR_COLOR_GREENcxx . . $ GR_COLOR_GREEN(4c679297bf94b9eb).(color); |
| 273 | b += GR_COLOR_BLUEcxx . . $ GR_COLOR_BLUE(4c679297bf94b9eb).(color); |
| 274 | num++; |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | if (y != h - 1) { |
| 279 | color16 = src_data[(y + 1) * w + (x + 1)]; |
| 280 | if (color16 & OPAQUE_FLAGcxx . . $ `lib/grdefs.h:72:9`!) { |
| 281 | color = GR_16_TO_COLORcxx . . $ GR_16_TO_COLOR(909d59720f161188).(color16); |
| 282 | r += GR_COLOR_REDcxx . . $ GR_COLOR_RED(4c679297bf94b9eb).(color); |
| 283 | g += GR_COLOR_GREENcxx . . $ GR_COLOR_GREEN(4c679297bf94b9eb).(color); |
| 284 | b += GR_COLOR_BLUEcxx . . $ GR_COLOR_BLUE(4c679297bf94b9eb).(color); |
| 285 | num++; |
| 286 | } |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | if (y != 0) { |
| 291 | color16 = src_data[(y - 1) * w + (x)]; |
| 292 | if (color16 & OPAQUE_FLAGcxx . . $ `lib/grdefs.h:72:9`!) { |
| 293 | color = GR_16_TO_COLORcxx . . $ GR_16_TO_COLOR(909d59720f161188).(color16); |
| 294 | r += GR_COLOR_REDcxx . . $ GR_COLOR_RED(4c679297bf94b9eb).(color); |
| 295 | g += GR_COLOR_GREENcxx . . $ GR_COLOR_GREEN(4c679297bf94b9eb).(color); |
| 296 | b += GR_COLOR_BLUEcxx . . $ GR_COLOR_BLUE(4c679297bf94b9eb).(color); |
| 297 | num++; |
| 298 | } |
| 299 | } |
| 300 | if (y != h - 1) { |
| 301 | color16 = src_data[(y + 1) * w + (x)]; |
| 302 | if (color16 & OPAQUE_FLAGcxx . . $ `lib/grdefs.h:72:9`!) { |
| 303 | color = GR_16_TO_COLORcxx . . $ GR_16_TO_COLOR(909d59720f161188).(color16); |
| 304 | r += GR_COLOR_REDcxx . . $ GR_COLOR_RED(4c679297bf94b9eb).(color); |
| 305 | g += GR_COLOR_GREENcxx . . $ GR_COLOR_GREEN(4c679297bf94b9eb).(color); |
| 306 | b += GR_COLOR_BLUEcxx . . $ GR_COLOR_BLUE(4c679297bf94b9eb).(color); |
| 307 | num++; |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | if (num > 0) { |
| 312 | r /= num; |
| 313 | g /= num; |
| 314 | b /= num; |
| 315 | color16 = GR_RGB16cxx . . $ GR_RGB16(6461fafb79bad5b9).(r, g, b); |
| 316 | dest_data[y * w + x] = OPAQUE_FLAGcxx . . $ `lib/grdefs.h:72:9`! | color16; |
| 317 | } |
| 318 | } |
| 319 | } |
| 320 | } |
| 321 | mem_freecxx . . $ `mem/mem.h:80:9`!(src_data); |
| 322 | } |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | // TODO: MTS: unused? |
| 327 | // Blurs the lightmaps so a dithering pattern is less noticeable |
| 328 | void BlurLightmapInfoscxx . . $ BlurLightmapInfos(d4f767463ce0a6b3).(int type) { |
| 329 | int i; |
| 330 | |
| 331 | for (i = 0; i < MAX_LIGHTMAP_INFOScxx . . $ `Descent3/lightmap_info.h:74:9`!; i++) { |
| 332 | if (LightmapInfocxx . . $ LightmapInfo.[i].usedcxx . . $ lightmap_info#used. && LightmapInfocxx . . $ LightmapInfo.[i].typecxx . . $ lightmap_info#type. == type) { |
| 333 | uint16_tcxx . . $ uint16_t# *src_data; |
| 334 | uint16_tcxx . . $ uint16_t# *dest_data = lm_datacxx . . $ lm_data(2fbd6a760478ca0f).(LightmapInfocxx . . $ LightmapInfo.[i].lm_handlecxx . . $ lightmap_info#lm_handle.); |
| 335 | int w = lmi_wcxx . . $ lmi_w(7864480464b09eea).(i); |
| 336 | int h = lmi_hcxx . . $ lmi_h(7864480464b09eea).(i); |
| 337 | int x, y; |
| 338 | |
| 339 | src_data = (uint16_tcxx . . $ uint16_t# *)mem_malloccxx . . $ `mem/mem.h:79:9`!(w * h * 2); |
| 340 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(src_data); |
| 341 | |
| 342 | memcpy(src_data, dest_data, w * h * 2); |
| 343 | |
| 344 | for (y = 0; y < h; y++) { |
| 345 | for (x = 0; x < w; x++) { |
| 346 | if (src_data[y * w + x] & OPAQUE_FLAGcxx . . $ `lib/grdefs.h:72:9`!) { |
| 347 | int r = 0, g = 0, b = 0; |
| 348 | int num = 0; |
| 349 | ddgr_colorcxx . . $ ddgr_color# color; |
| 350 | uint16_tcxx . . $ uint16_t# color16; |
| 351 | |
| 352 | color16 = src_data[y * w + (x)]; |
| 353 | color = GR_16_TO_COLORcxx . . $ GR_16_TO_COLOR(909d59720f161188).(color16); |
| 354 | r += GR_COLOR_REDcxx . . $ GR_COLOR_RED(4c679297bf94b9eb).(color); |
| 355 | g += GR_COLOR_GREENcxx . . $ GR_COLOR_GREEN(4c679297bf94b9eb).(color); |
| 356 | b += GR_COLOR_BLUEcxx . . $ GR_COLOR_BLUE(4c679297bf94b9eb).(color); |
| 357 | num++; |
| 358 | |
| 359 | // Left edge |
| 360 | if (x != 0) { |
| 361 | |
| 362 | color16 = src_data[y * w + (x - 1)]; |
| 363 | if (color16 & OPAQUE_FLAGcxx . . $ `lib/grdefs.h:72:9`!) { |
| 364 | color = GR_16_TO_COLORcxx . . $ GR_16_TO_COLOR(909d59720f161188).(color16); |
| 365 | r += GR_COLOR_REDcxx . . $ GR_COLOR_RED(4c679297bf94b9eb).(color); |
| 366 | g += GR_COLOR_GREENcxx . . $ GR_COLOR_GREEN(4c679297bf94b9eb).(color); |
| 367 | b += GR_COLOR_BLUEcxx . . $ GR_COLOR_BLUE(4c679297bf94b9eb).(color); |
| 368 | num++; |
| 369 | } |
| 370 | |
| 371 | if (y != 0) { |
| 372 | color16 = src_data[(y - 1) * w + (x - 1)]; |
| 373 | if (color16 & OPAQUE_FLAGcxx . . $ `lib/grdefs.h:72:9`!) { |
| 374 | color = GR_16_TO_COLORcxx . . $ GR_16_TO_COLOR(909d59720f161188).(color16); |
| 375 | r += GR_COLOR_REDcxx . . $ GR_COLOR_RED(4c679297bf94b9eb).(color); |
| 376 | g += GR_COLOR_GREENcxx . . $ GR_COLOR_GREEN(4c679297bf94b9eb).(color); |
| 377 | b += GR_COLOR_BLUEcxx . . $ GR_COLOR_BLUE(4c679297bf94b9eb).(color); |
| 378 | num++; |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | if (y != h - 1) { |
| 383 | color16 = src_data[(y + 1) * w + (x - 1)]; |
| 384 | if (color16 & OPAQUE_FLAGcxx . . $ `lib/grdefs.h:72:9`!) { |
| 385 | color = GR_16_TO_COLORcxx . . $ GR_16_TO_COLOR(909d59720f161188).(color16); |
| 386 | r += GR_COLOR_REDcxx . . $ GR_COLOR_RED(4c679297bf94b9eb).(color); |
| 387 | g += GR_COLOR_GREENcxx . . $ GR_COLOR_GREEN(4c679297bf94b9eb).(color); |
| 388 | b += GR_COLOR_BLUEcxx . . $ GR_COLOR_BLUE(4c679297bf94b9eb).(color); |
| 389 | num++; |
| 390 | } |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | // Right edge |
| 395 | if (x != (w - 1)) { |
| 396 | |
| 397 | color16 = src_data[y * w + (x + 1)]; |
| 398 | if (color16 & OPAQUE_FLAGcxx . . $ `lib/grdefs.h:72:9`!) { |
| 399 | color = GR_16_TO_COLORcxx . . $ GR_16_TO_COLOR(909d59720f161188).(color16); |
| 400 | r += GR_COLOR_REDcxx . . $ GR_COLOR_RED(4c679297bf94b9eb).(color); |
| 401 | g += GR_COLOR_GREENcxx . . $ GR_COLOR_GREEN(4c679297bf94b9eb).(color); |
| 402 | b += GR_COLOR_BLUEcxx . . $ GR_COLOR_BLUE(4c679297bf94b9eb).(color); |
| 403 | num++; |
| 404 | } |
| 405 | |
| 406 | if (y != 0) { |
| 407 | color16 = src_data[(y - 1) * w + (x + 1)]; |
| 408 | if (color16 & OPAQUE_FLAGcxx . . $ `lib/grdefs.h:72:9`!) { |
| 409 | color = GR_16_TO_COLORcxx . . $ GR_16_TO_COLOR(909d59720f161188).(color16); |
| 410 | r += GR_COLOR_REDcxx . . $ GR_COLOR_RED(4c679297bf94b9eb).(color); |
| 411 | g += GR_COLOR_GREENcxx . . $ GR_COLOR_GREEN(4c679297bf94b9eb).(color); |
| 412 | b += GR_COLOR_BLUEcxx . . $ GR_COLOR_BLUE(4c679297bf94b9eb).(color); |
| 413 | num++; |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | if (y != h - 1) { |
| 418 | color16 = src_data[(y + 1) * w + (x + 1)]; |
| 419 | if (color16 & OPAQUE_FLAGcxx . . $ `lib/grdefs.h:72:9`!) { |
| 420 | color = GR_16_TO_COLORcxx . . $ GR_16_TO_COLOR(909d59720f161188).(color16); |
| 421 | r += GR_COLOR_REDcxx . . $ GR_COLOR_RED(4c679297bf94b9eb).(color); |
| 422 | g += GR_COLOR_GREENcxx . . $ GR_COLOR_GREEN(4c679297bf94b9eb).(color); |
| 423 | b += GR_COLOR_BLUEcxx . . $ GR_COLOR_BLUE(4c679297bf94b9eb).(color); |
| 424 | num++; |
| 425 | } |
| 426 | } |
| 427 | } |
| 428 | |
| 429 | if (y != 0) { |
| 430 | color16 = src_data[(y - 1) * w + (x)]; |
| 431 | if (color16 & OPAQUE_FLAGcxx . . $ `lib/grdefs.h:72:9`!) { |
| 432 | color = GR_16_TO_COLORcxx . . $ GR_16_TO_COLOR(909d59720f161188).(color16); |
| 433 | r += GR_COLOR_REDcxx . . $ GR_COLOR_RED(4c679297bf94b9eb).(color); |
| 434 | g += GR_COLOR_GREENcxx . . $ GR_COLOR_GREEN(4c679297bf94b9eb).(color); |
| 435 | b += GR_COLOR_BLUEcxx . . $ GR_COLOR_BLUE(4c679297bf94b9eb).(color); |
| 436 | num++; |
| 437 | } |
| 438 | } |
| 439 | if (y != h - 1) { |
| 440 | color16 = src_data[(y + 1) * w + (x)]; |
| 441 | if (color16 & OPAQUE_FLAGcxx . . $ `lib/grdefs.h:72:9`!) { |
| 442 | color = GR_16_TO_COLORcxx . . $ GR_16_TO_COLOR(909d59720f161188).(color16); |
| 443 | r += GR_COLOR_REDcxx . . $ GR_COLOR_RED(4c679297bf94b9eb).(color); |
| 444 | g += GR_COLOR_GREENcxx . . $ GR_COLOR_GREEN(4c679297bf94b9eb).(color); |
| 445 | b += GR_COLOR_BLUEcxx . . $ GR_COLOR_BLUE(4c679297bf94b9eb).(color); |
| 446 | num++; |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | if (num > 0) { |
| 451 | r /= num; |
| 452 | g /= num; |
| 453 | b /= num; |
| 454 | color16 = GR_RGB16cxx . . $ GR_RGB16(6461fafb79bad5b9).(r, g, b); |
| 455 | dest_data[y * w + x] = OPAQUE_FLAGcxx . . $ `lib/grdefs.h:72:9`! | color16; |
| 456 | } |
| 457 | } |
| 458 | } |
| 459 | } |
| 460 | mem_freecxx . . $ `mem/mem.h:80:9`!(src_data); |
| 461 | } |
| 462 | } |
| 463 | } |