【发布时间】:2015-06-30 10:53:15
【问题描述】:
这是一个奇怪的问题,我很难为它写标题。
我正在处理像素(更具体地说是位图),但无法计算出实用访问每个数组单元格的(简单)数学。
我的画布是 [n16 x 16] 像素,n 始终为 1 或更大。
这是一张基本 n = 2 画布的照片:
http://i.imgur.com/mabwQfJ.png
我希望我的魔法算法从 0 运行到 495 而不触及浅灰色区域,然后从 16 运行到 512(实际上是 511 单元格,我的错)而不触及深灰色区域。
所以,从 0 到 15,跳过 16 到 31,然后是 32 到 47,等等。
对于 n = 3:
http://i.imgur.com/TqJMWl6.png
在这种情况下,0-735 会跳过较浅的灰色区域,16-751 会跳过两侧的区域,32-767 会跳过较深的灰色区域。
我尝试了什么:
这是我的代码的摘录,希望它有用并展示了我已经尝试过的内容。它是计算“idxpos”价值的部分。
// Let's say length = 3 for now.
for (int character = 0; character < length; ++character)
{
// in case you're wondering, it grabs 16x16 characters from an ASCII spritesheet
charpos = (string[character] - ' ') * 16 * 16;
// Runs through the spritesheet character map
// this is a huge 16x1520 bitmap.
for (int pixel = 0; pixel < 16 * 16; ++pixel)
{
// ignore this, just me messing around with pixel tinting
r = (((CharMap[charpos + pixel] >> 0) & 0xFF) + 255 - u);
g = (((CharMap[charpos + pixel] >> 8) & 0xFF) + 255 - v);
b = (((CharMap[charpos + pixel] >> 16) & 0xFF) + 255 - w);
newcolour = RGB(r, g, b);
// THIS is the part I am stuck on:
idxpos = pixel + (character * 16 * 16);
bitmap[idxpos] = CharMap[charpos + j];
}
}
你可能明白了。对我来说这听起来很简单,但我想不通。
哦,我对可以为我处理所有位图内容的神奇库不感兴趣,我无法使用它。
【问题讨论】:
-
始终以独占方式迭代范围 [0, 496):row = i/16;列 = i%16; gray_index = row * total_number_of_columns + current_gray * 16 + column;
-
我无法理解“在这种情况下,0-735 会跳过较浅的灰色区域,16-751 会跳过两侧的区域,32-767 会跳过较深的灰色区域。”这是正确的吗?
-
我喜欢上面的图片。这会让你从我这里得到一些额外的爱。
标签: c++ arrays algorithm bitmap