Exemplo n.º 1
0
Image::Image(image_ptr this_) :
    ObjectWrap(),
    this_(this_),
    estimated_size_(this_->width() * this_->height() * 4)
    {
        V8::AdjustAmountOfExternalAllocatedMemory(estimated_size_);
    }
Exemplo n.º 2
0
 //! @brief テクスチャバッファを生成し、
 //!        バッファへ画像をバインドする
 void bind_image(image_ptr img){
     uint_t id;
     glGenTextures(1, &id);
     glBindTexture(GL_TEXTURE_2D, id);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
     glTexImage2D(GL_TEXTURE_2D, 0, img->internal_format(), img->width(), img->height(), 0,
                  img->pixel_format(), GL_UNSIGNED_BYTE, img->data_front());
     glBindTexture(GL_TEXTURE_2D, 0);
     info.reset(new texture_info(id, img));
 }
Exemplo n.º 3
0
void image_base::resize(image_ptr target) {
  if (target->get_width() > get_width()) {
    // scale up
    unsigned int factor = target->get_width() / get_width();
    boost::shared_array<color> line(new color[get_width()]);

    unsigned int scanline = 0;
    bool first = false;

    for (pos_t y = 0; y < target->get_height(); y++) {
      pos_t y_p = (y / factor);

      if (y_p != scanline || !first) {
        get_line(y_p, pos_t(0), get_width(), line.get());
        first = true;
        scanline = y_p;
      }

      for (pos_t x = 0; x < target->get_width(); x++) {
        pos_t x_p = (x / factor);
        target->set_pixel(x, y, line[x_p]);
      }
    }
  }
  else {
    // scale down
    unsigned int factor = get_width() / target->get_width();

    boost::shared_array<color> line(new color[get_width()]);

    for (pos_t y = 0; y < target->get_height(); y++) {
      pos_t y_p = ((y * factor) + factor / 2);
      get_line(y_p, pos_t(0), get_width(), line.get());
      
      for (pos_t x = 0; x < target->get_width(); x++) {
        pos_t x_p = ((x * factor) + factor / 2);
        target->set_pixel(x, y, line[x_p]);
      }
    }
  }
}