本文整理汇总了C++中Pixel::mix方法的典型用法代码示例。如果您正苦于以下问题:C++ Pixel::mix方法的具体用法?C++ Pixel::mix怎么用?C++ Pixel::mix使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pixel
的用法示例。
在下文中一共展示了Pixel::mix方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runtime_error
/* Copy another image. Integer rotate is 0 to 7 clockwise. */
Image::Image(const Image& source, int rotate) {
rotate %= 8;
int corner;
if (rotate == 0 || rotate == 4) {
/* Straight or upside down. */
size = source.dimensions();
} else if (rotate == 2 || rotate == 6) {
/* Rotated sideways. */
size = source.dimensions().transpose();
} else {
/* Rotated on a diagonal. */
size.x = size.y = (source.dimensions().x + source.dimensions().y + 1) / 2;
corner = source.dimensions().y / 2;
}
data = new Pixel[size.x * size.y];
for (int y = 0; y < size.y; y++) {
for (int x = 0; x < size.x; x++) {
switch (rotate) {
case 0:
/* Straight copy. */
(*this)(x,y) = source(x,y);
break;
case 4:
/* Upside down. */
(*this)(x,y) = source(size.x - x - 1, size.y - y - 1);
break;
case 2:
/* Rotated 90 degrees clockwise. */
(*this)(x,y) = source(y, size.x - x - 1);
break;
case 6:
/* Rotated 90 degrees counterclockwise. */
(*this)(x,y) = source(size.y - y - 1, x);
break;
default: {
/* Diagonal rotation. */
int s_x = 0; // Source x coordinate.
int s_y = 0; // Source y coordinate.
if (rotate == 1) {
/* 45 degrees from north. ?? */
s_x = y - corner + x;
s_y = source.dimensions().y - (x + corner - y) - 1;
} else if (rotate == 3) {
/* 135 degrees from north. */
s_x = source.dimensions().x - (x + corner - y) - 1;
s_y = source.dimensions().y - (y - corner + x) - 1;
} else if (rotate == 5) {
/* 225 degrees from north. ?? */
s_x = source.dimensions().x - (y - corner + x) - 1;
s_y = x + corner - y;
} else if (rotate == 7) {
/* 315 degrees from north. */
s_x = x + corner - y;
s_y = y - corner + x;
} else {
/* This shouldn't happen. Sheesh. */
throw std::runtime_error("Bad rotation! Go stand in the corner!");
}
if (s_x >= 0 && s_y >= 0 &&
s_x < source.dimensions().x && s_y < source.dimensions().y) {
/* Blend in surrounding pixels. */
Pixel dot;
if (s_x > 0) {
dot = source(s_x - 1, s_y);
}
if (s_y > 0) {
dot.mix(source(s_x, s_y - 1));
} else {
dot.mix({0, 0, 0, 0});
}
if (s_x < source.dimensions().x - 2) {
dot.mix(source(s_x + 1, s_y));
} else {
dot.mix({0, 0, 0, 0});
}
if (s_y < source.dimensions().y - 2) {
dot.mix(source(s_x, s_y + 1));
} else {
dot.mix({0, 0, 0, 0});
}
/* Write result. */
dot.mix(source(s_x, s_y));
(*this)(x,y) = dot;
}
} break;
}
}
}
}