Logo Search packages:      
Sourcecode: race version File versions

CL_Canvas * Blitter::create_canvas ( CL_SurfaceProvider *  prov  )  [static]

Returns a newly allocated canvas. The canvas contains the same image as the given surface provider

Definition at line 250 of file blitter.cpp.

References put_surface().

{
  CL_Canvas* canvas = new CL_Canvas(prov->get_width(), prov->get_height());

  switch (prov->get_bytes_per_pixel())
    {
    case 3:
      {
      canvas->lock();
      prov->lock();
      
      int buffer_size = prov->get_pitch () * prov->get_height ();
      unsigned char* sbuffer = static_cast<unsigned char*>(prov->get_data ());
      unsigned char* tbuffer = static_cast<unsigned char*>(canvas->get_data ());
      
      for (int si = 0, ti = 0; si < buffer_size; si += 3, ti += 4)
        {
          tbuffer[ti + 0] = 255;
          tbuffer[ti + 1] = sbuffer[si + 0];
          tbuffer[ti + 2] = sbuffer[si + 1];
          tbuffer[ti + 3] = sbuffer[si + 2];
        }
        
      prov->unlock();
      canvas->unlock();
      }

    case 4:
      canvas->lock();
      prov->lock();
      memcpy(canvas->get_data(), prov->get_data(),
           sizeof(unsigned char) * prov->get_height() * prov->get_pitch());
      prov->unlock();
      canvas->unlock();
      break;

    default:
      put_surface(canvas, prov, 0, 0);
      break;
    }
  return canvas;
}


Generated by  Doxygen 1.6.0   Back to index