MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / bm_ScaleBitmapToBitmap

Function bm_ScaleBitmapToBitmap

bitmap/bitmain.cpp:1289–1345  ·  view source on GitHub ↗

Given two bitmaps, scales the data from src to the size of dest Not a particularly fast implementation

Source from the content-addressed store, hash-verified

1287// Given two bitmaps, scales the data from src to the size of dest
1288// Not a particularly fast implementation
1289void bm_ScaleBitmapToBitmap(int dest, int src) {
1290 uint16_t *dp = bm_data(dest, 0);
1291 uint16_t *sp = bm_data(src, 0);
1292 ASSERT(GameBitmaps[dest].used && dp);
1293 ASSERT(GameBitmaps[src].used && sp);
1294 int smipped = bm_mipped(src);
1295 int dmipped = bm_mipped(dest);
1296 int limit;
1297 ASSERT(smipped == dmipped);
1298 ASSERT(GameBitmaps[dest].format == GameBitmaps[src].format);
1299
1300 int sw = bm_w(src, 0);
1301 int sh = bm_h(src, 0);
1302 int dw = bm_w(dest, 0);
1303 int dh = bm_h(dest, 0);
1304 int i, t;
1305 uint16_t *sdata;
1306 uint16_t *ddata;
1307 if (sw == dw && sh == dh) {
1308 if (smipped)
1309 limit = bm_miplevels(src);
1310 else
1311 limit = 1;
1312 for (i = 0; i < limit; i++) {
1313 sdata = (uint16_t *)bm_data(src, i);
1314 ddata = (uint16_t *)bm_data(dest, i);
1315 dw = bm_w(dest, i);
1316 dh = bm_h(dest, i);
1317 memcpy(ddata, sdata, dw * dh * sizeof(uint16_t));
1318 }
1319 return;
1320 }
1321 if (smipped)
1322 limit = bm_miplevels(src);
1323 else
1324 limit = 1;
1325 for (int m = 0; m < limit; m++) {
1326 sw = bm_w(src, m);
1327 sh = bm_h(src, m);
1328 dw = bm_w(dest, m);
1329 dh = bm_h(dest, m);
1330
1331 sdata = (uint16_t *)bm_data(src, m);
1332 ddata = (uint16_t *)bm_data(dest, m);
1333 // These are our interpolant variables
1334 float xstep = (float)sw / (float)dw;
1335 float ystep = (float)sh / (float)dh;
1336 float xoff = 0;
1337 float yoff = 0;
1338 for (i = 0; i < dh; i++, yoff += ystep) {
1339 for (xoff = 0, t = 0; t < dw; t++, xoff += xstep) {
1340 ddata[i * dw + t] = sdata[(int)yoff * sw + (int)xoff];
1341 }
1342 }
1343 }
1344 GameBitmaps[dest].flags |= BF_CHANGED;
1345}
1346// given a handle and a miplevel, returns the bytes per bitmap row

Callers 12

UpdateProcViewMethod · 0.85
UpdateTextureViewsMethod · 0.85
UpdateProcViewMethod · 0.85
bm_InitBitmapsFunction · 0.85
bm_AllocLoadFileBitmapFunction · 0.85
bm_AllocLoadBitmapFunction · 0.85
bm_ChangeSizeFunction · 0.85
PageInVClipFunction · 0.85
AllocLoadIFLVClipFunction · 0.85
LoadTextureImageFunction · 0.85
PageInTextureFunction · 0.85

Calls 5

bm_dataFunction · 0.85
bm_mippedFunction · 0.85
bm_wFunction · 0.85
bm_hFunction · 0.85
bm_miplevelsFunction · 0.85

Tested by

no test coverage detected