本文整理汇总了C++中Pixel::Pack方法的典型用法代码示例。如果您正苦于以下问题:C++ Pixel::Pack方法的具体用法?C++ Pixel::Pack怎么用?C++ Pixel::Pack使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pixel
的用法示例。
在下文中一共展示了Pixel::Pack方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: debugModulation
static void Decompress4BPP(const Image &imgA, const Image &imgB,
const std::vector<Block> &blocks,
uint8 *const outBuf,
bool bDebugImages = false) {
const uint32 w = imgA.GetWidth();
const uint32 h = imgA.GetHeight();
assert(imgA.GetWidth() == imgB.GetWidth());
assert(imgA.GetHeight() == imgB.GetHeight());
Image debugModulation(w, h);
const uint8 debugModulationBitDepth[4] = { 8, 4, 4, 4 };
debugModulation.ChangeBitDepth(debugModulationBitDepth);
for(uint32 j = 0; j < h; j++) {
for(uint32 i = 0; i < w; i++) {
const uint32 blockWidth = 4;
const uint32 blockHeight = 4;
const uint32 blockIdx =
(j/blockHeight) * (w/blockWidth) + (i/blockWidth);
const Block &b = blocks[blockIdx];
const uint32 texelIndex =
(j % blockHeight) * blockWidth + (i % blockWidth);
const Pixel &pa = imgA(i, j);
const Pixel &pb = imgB(i, j);
bool punchThrough = false;
uint8 lerpVal = 0;
if(b.GetModeBit()) {
const uint8 lerpVals[3] = { 8, 4, 0 };
uint8 modVal = b.GetLerpValue(texelIndex);
if(modVal >= 2) {
if(modVal == 2) {
punchThrough = true;
}
modVal -= 1;
}
lerpVal = lerpVals[modVal];
} else {
const uint8 lerpVals[4] = { 8, 5, 3, 0 };
lerpVal = lerpVals[b.GetLerpValue(texelIndex)];
}
if(bDebugImages) {
Pixel &modPx = debugModulation(i, j);
modPx.A() = 0xFF;
for(uint32 c = 1; c < 4; c++) {
float fv = (static_cast<float>(lerpVal) / 8.0f) * 15.0f;
modPx.Component(c) = static_cast<uint8>(fv);
}
// Make punch through pixels red.
if(punchThrough) {
modPx.G() = modPx.B() = 0;
}
}
Pixel result = (pa * (8 - lerpVal) + pb * lerpVal) / 8;
if(punchThrough) {
result.A() = 0;
}
uint32 *outPixels = reinterpret_cast<uint32 *>(outBuf);
outPixels[(j * w) + i] = result.Pack();
}
}
if(bDebugImages) {
debugModulation.DebugOutput("Modulation");
}
}
示例2: dbgMod
static void Decompress2BPP(const Image &imgA, const Image &imgB,
const std::vector<Block> &blocks,
uint8 *const outBuf,
bool bDebugImages) {
const uint32 w = imgA.GetWidth();
const uint32 h = imgA.GetHeight();
assert(w > 0);
assert(h > 0);
assert(imgA.GetWidth() == imgB.GetWidth());
assert(imgA.GetHeight() == imgB.GetHeight());
std::vector<uint8> modValues;
modValues.reserve(w * h);
const uint32 blockWidth = 8;
const uint32 blockHeight = 4;
for(uint32 j = 0; j < h; j++) {
for(uint32 i = 0; i < w; i++) {
const uint32 blockIdx =
(j/blockHeight) * (w/blockWidth) + (i/blockWidth);
const Block &b = blocks[blockIdx];
const uint32 texelIndex =
(j % blockHeight) * blockWidth + (i % blockWidth);
uint8 lerpVal = 0;
if(b.GetModeBit()) {
uint32 texelX = texelIndex % blockWidth;
uint32 texelY = texelIndex / blockWidth;
const uint8 lerpVals[4] = { 8, 5, 3, 0 };
if(((texelX ^ texelY) & 0x1) == 0) {
uint32 lerpIdx = texelY * (blockWidth / 2) + (texelX / 2);
lerpVal = lerpVals[b.Get2BPPLerpValue(lerpIdx)];
}
} else {
lerpVal = b.Get2BPPLerpValue(texelIndex);
lerpVal = lerpVal? 0 : 8;
}
modValues.push_back(lerpVal);
}
}
assert(modValues.size() == w * h);
for(uint32 j = 0; j < h; j++) {
for(uint32 i = 0; i < w; i++) {
const uint32 blockIdx =
(j/blockHeight) * (w/blockWidth) + (i/blockWidth);
const Block &b = blocks[blockIdx];
uint8 lerpVal = 0;
#define GET_LERP_VAL(x, y) modValues[(y) * w + (x)]
if(b.GetModeBit() && ((i ^ j) & 0x1)) {
switch(b.Get2BPPSubMode()) {
case Block::e2BPPSubMode_Horizontal:
lerpVal += GET_LERP_VAL((i + w - 1) % w, j);
lerpVal += GET_LERP_VAL((i + w + 1) % w, j);
lerpVal /= 2;
break;
case Block::e2BPPSubMode_Vertical:
lerpVal += GET_LERP_VAL(i, (j + h - 1) % h);
lerpVal += GET_LERP_VAL(i, (j + h + 1) % h);
lerpVal /= 2;
break;
default:
case Block::e2BPPSubMode_All:
lerpVal += GET_LERP_VAL(i, (j + h - 1) % h);
lerpVal += GET_LERP_VAL(i, (j + h + 1) % h);
lerpVal += GET_LERP_VAL((i + w - 1) % w, j);
lerpVal += GET_LERP_VAL((i + w + 1) % w, j);
lerpVal = (lerpVal + 1) / 4;
break;
}
GET_LERP_VAL(i, j) = lerpVal;
} else {
lerpVal = GET_LERP_VAL(i, j);
}
#undef GET_LERP_VAL
const Pixel &pa = imgA(i, j);
const Pixel &pb = imgB(i, j);
Pixel result = (pa * (8 - lerpVal) + pb * lerpVal) / 8;
uint32 *outPixels = reinterpret_cast<uint32 *>(outBuf);
outPixels[(j * w) + i] = result.Pack();
}
}
if(bDebugImages) {
Image dbgMod(w, h);
for(uint32 i = 0; i < h*w; i++) {
float fb = static_cast<float>(modValues[i]);
//.........这里部分代码省略.........