MCPcopy Create free account
hub / github.com/Kitware/VTK / ResampleToPowerOfTwo

Method ResampleToPowerOfTwo

Rendering/OpenGL2/vtkOpenGLTexture.cxx:444–545  ·  view source on GitHub ↗

------------------------------------------------------------------------------ Creates resampled unsigned char texture map that is a power of two in both x and y.

Source from the content-addressed store, hash-verified

442// Creates resampled unsigned char texture map that is a power of two in both
443// x and y.
444unsigned char* vtkOpenGLTexture::ResampleToPowerOfTwo(
445 int& xs, int& ys, unsigned char* dptr, int bpp, int maxDimGL)
446{
447 unsigned char *tptr, *p, *p1, *p2, *p3, *p4;
448 vtkIdType jOffset, iIdx, jIdx;
449 double pcoords[3], rm, sm, w0, w1, w2, w3;
450 int yInIncr = xs;
451 int xInIncr = 1;
452
453 int xsize = FindPowerOfTwo(xs, maxDimGL);
454 int ysize = FindPowerOfTwo(ys, maxDimGL);
455 if (this->RestrictPowerOf2ImageSmaller)
456 {
457 if (xsize > xs)
458 {
459 xsize /= 2;
460 }
461 if (ysize > ys)
462 {
463 ysize /= 2;
464 }
465 }
466 double hx = xsize > 1 ? (xs - 1.0) / (xsize - 1.0) : 0;
467 double hy = ysize > 1 ? (ys - 1.0) / (ysize - 1.0) : 0;
468
469 // make sure to promote the size calc to size_t as int can easily overflow
470 tptr = p = new unsigned char[static_cast<size_t>(xsize) * static_cast<size_t>(ysize) *
471 static_cast<size_t>(bpp)];
472
473 // Resample from the previous image. Compute parametric coordinates and
474 // interpolate
475 for (int j = 0; j < ysize; j++)
476 {
477 pcoords[1] = j * hy;
478
479 jIdx = static_cast<int>(pcoords[1]);
480 if (jIdx >= (ys - 1)) // make sure to interpolate correctly at edge
481 {
482 if (ys == 1)
483 {
484 jIdx = 0;
485 yInIncr = 0;
486 }
487 else
488 {
489 jIdx = ys - 2;
490 }
491 pcoords[1] = 1.0;
492 }
493 else
494 {
495 pcoords[1] = pcoords[1] - jIdx;
496 }
497 jOffset = jIdx * xs;
498 sm = 1.0 - pcoords[1];
499
500 for (int i = 0; i < xsize; i++)
501 {

Callers 1

LoadMethod · 0.95

Calls 1

FindPowerOfTwoFunction · 0.85

Tested by

no test coverage detected