当前位置: 首页>>代码示例>>C++>>正文


C++ Pixel::mix方法代码示例

本文整理汇总了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;
      }
    }
  }
}
开发者ID:pianosaurus,项目名称:Hubward,代码行数:99,代码来源:image.cpp


注:本文中的Pixel::mix方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。