MCPcopy Create free account
hub / github.com/CruiserOne/Astrolog / BmpCopyBlock2

Function BmpCopyBlock2

xdevice.cpp:379–435  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

377// of integers. Can be used to render only subsections of source pixels.
378
379void BmpCopyBlock2(CONST Bitmap *bs, real x1, real y1, real x2, real y2,
380 Bitmap *bd, int x3, int y3, int x4, int y4)
381{
382 int xd = x4-x3+1, yd = y4-y3+1, x, y, xT, yT, nR, nG, nB;
383 real xs, ys, lonS, latS, rx, ry;
384 byte *pbDst;
385 flag fDoEclipse = fFalse;
386 KV kv;
387
388 // Sanity checks of coordinate bounds, which shouldn't ever fail.
389 Assert(FBetween(x1, 0.0, (real)bs->x - rSmall));
390 Assert(FBetween(y1, 0.0, (real)bs->y - rSmall));
391 Assert(FBetween(x2, 0.0, (real)bs->x - rSmall));
392 Assert(FBetween(y2, 0.0, (real)bs->y - rSmall));
393 Assert(FBetween(x3, 0, bd->x-1));
394 Assert(FBetween(y3, 0, bd->y-1));
395 Assert(FBetween(x4, 0, bd->x-1));
396 Assert(FBetween(y4, 0, bd->y-1));
397
398 if (gs.fMollweide) {
399 lonS = Tropical(planet[oSun]);
400 latS = planetalt[oSun];
401 EclToEqu(&lonS, &latS);
402 lonS = Mod(lonS - cp0.lonMC + rDegHalf - Lon);
403 if (us.fEclipse &&
404 NCheckEclipseSolar(oEar, oMoo, oSun, NULL) > etNone)
405 fDoEclipse = fTrue;
406 }
407
408 xs = (x2-x1) / (real)xd;
409 ys = (y2-y1) / (real)yd;
410 for (y = y3; y <= y4; y++) {
411 pbDst = _PbXY(bd, x3, y);
412 ry = y1 + (real)(y-y3) * ys;
413 yT = (int)ry;
414 if (!gs.fMollweide) {
415 // Fast loop that just copies pixels.
416 for (x = x3; x <= x4; x++) {
417 xT = (int)(x1 + (real)(x-x3) * xs);
418 _GetRGB(_PbXY(bs, xT, yT), &nR, &nG, &nB);
419 _SetRGB(pbDst, nR, nG, nB);
420 pbDst += cbPixelK;
421 }
422 } else {
423 // Slower loop that may modify colors based on position on Earth.
424 ry = ry * rDegMax / (real)bs->x;
425 for (x = x3; x <= x4; x++) {
426 rx = x1 + (real)(x-x3) * xs;
427 xT = (int)rx;
428 rx = rx * rDegMax / (real)bs->x;
429 kv = _GetXY(bs, xT, yT);
430 BmpDarkenKv(rx, ry, lonS, latS, fDoEclipse, &kv);
431 BmpSetXY(bd, x, y, kv);
432 }
433 }
434 }
435}
436

Callers 1

FBmpDrawMap2Function · 0.85

Calls 9

AssertFunction · 0.85
ModFunction · 0.85
NCheckEclipseSolarFunction · 0.85
_PbXYFunction · 0.85
_GetRGBFunction · 0.85
_SetRGBFunction · 0.85
_GetXYFunction · 0.85
BmpDarkenKvFunction · 0.85
BmpSetXYFunction · 0.85

Tested by

no test coverage detected