Ejemplo n.º 1
0
  void PixelMap::setSize(const IntSize &size)
  {
    u8 **nmap;

    if(size != 0)
    {
      /* Create new map */
      nmap = new u8*[size.getHeight()];
      for(int y = 0; y < size.getHeight(); y++)
      {
        int linelength = size.getWidth()%8 == 0 ? size.getWidth()/8 : size.getWidth()/8 + 1;

        nmap[y] = new u8[linelength];
          memset(nmap[y], 0, sizeof(*nmap[y]) * linelength);
      }

      /* Copy content */
      if(nmap != NULL)
      {
        for(int y = 0; y < this->size.getHeight() && y < size.getHeight(); y++)
        {
          for(int x = 0; x < this->size.getWidth() && x < size.getWidth(); x++)
          {
            if(is_pixel(x, y))
              set_pixel_on_map(nmap, x, y, 1);
          }
        }
      }

      /* Clear old content */
      if(map != NULL)
      {
        for(int y = 0; y < size.getHeight(); y++)
        {
          delete map[y];
        }
        delete map;
      }

      /* Swap */
      map = nmap;
    }
    else
    {
      map = NULL;
    }

    this->size = size;
  }