Ejemplo n.º 1
0
void
Canvas::StretchMono(PixelScalar dest_x, PixelScalar dest_y,
                    UPixelScalar dest_width, UPixelScalar dest_height,
                    const Bitmap &src,
                    PixelScalar src_x, PixelScalar src_y,
                    UPixelScalar src_width, UPixelScalar src_height,
                    Color fg_color, Color bg_color)
{
  assert(IsDefined());
  assert(src.IsDefined());

  SDL_Surface *src_surface = src.GetNative();
  assert(src_surface->format->palette != NULL &&
         src_surface->format->palette->ncolors == 2);

  SDL_Surface *zoomed =
    ::zoomSurface(src_surface, (double)dest_width / (double)src_width,
                  (double)dest_height / (double)src_height,
                  SMOOTHING_OFF);
  if (zoomed == NULL)
    return;

  assert(zoomed->format->palette != NULL &&
         zoomed->format->palette->ncolors == 2);

  ::SDL_SetColorKey(zoomed, 0, 0);
  zoomed->format->palette->colors[0] = text_color;
  zoomed->format->palette->colors[1] = bg_color;

  copy(dest_x, dest_y, dest_width, dest_height,
       zoomed, (src_x * dest_width) / src_width,
       (src_y * dest_height) / src_height);
  ::SDL_FreeSurface(zoomed);
}
Ejemplo n.º 2
0
void
Canvas::StretchNot(const Bitmap &src)
{
  assert(src.IsDefined());

#ifdef USE_GLSL
  OpenGL::invert_shader->Use();
#else
  const GLEnable scope(GL_TEXTURE_2D);

  OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);

  /* invert the texture color */
  OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);
  OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE);
  OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_ONE_MINUS_SRC_COLOR);

  /* copy the texture alpha */
  OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
  OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_TEXTURE);
  OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
#endif

  GLTexture &texture = *src.GetNative();
  texture.Draw(0, 0, GetWidth(), GetHeight(),
               0, 0, src.GetWidth(), src.GetHeight());
}
Ejemplo n.º 3
0
void
Canvas::Copy(const Bitmap &_src)
{
  ConstImageBuffer src = _src.GetNative();

  Copy(0, 0, src.width, src.height, src, 0, 0);
}
Ejemplo n.º 4
0
void
Canvas::StretchMono(int dest_x, int dest_y,
                    unsigned dest_width, unsigned dest_height,
                    const Bitmap &src,
                    int src_x, int src_y,
                    unsigned src_width, unsigned src_height,
                    Color fg_color, Color bg_color)
{
  /* note that this implementation ignores the background color; it is
     not mandatory, and we can assume that the background is already
     set; it is only being passed to this function because the GDI
     implementation will be faster when erasing the background
     again */

  OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);

  /* replace the texture color with the selected text color */
  OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);
  OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS);
  OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);

  /* invert texture alpha (our bitmaps have black text on white
     background) */
  OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
  OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_TEXTURE);
  OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

  const GLEnable scope(GL_TEXTURE_2D);
  const GLBlend blend(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

  GLTexture &texture = *src.GetNative();
  texture.Bind();
  texture.Draw(dest_x, dest_y, dest_width, dest_height,
               src_x, src_y, src_width, src_height);
}
Ejemplo n.º 5
0
void
Canvas::invert_stretch_transparent(const Bitmap &src, Color key)
{
  assert(src.IsDefined());

  SDL_Surface *src_surface = src.GetNative();
  const UPixelScalar src_x = 0, src_y = 0;
  const UPixelScalar src_width = src_surface->w;
  const UPixelScalar src_height = src_surface->h;
  const UPixelScalar dest_x = 0, dest_y = 0;
  const UPixelScalar dest_width = get_width();
  const UPixelScalar dest_height = get_height();

  SDL_Surface *zoomed =
    ::zoomSurface(src_surface, (double)dest_width / (double)src_width,
                  (double)dest_height / (double)src_height,
                  SMOOTHING_OFF);

  if (zoomed == NULL)
    return;

  ::SDL_SetColorKey(zoomed, SDL_SRCCOLORKEY,
                    ::SDL_MapRGB(zoomed->format, key.value.r,
                                 key.value.g, key.value.b));

  copy_not(dest_x, dest_y, dest_width, dest_height,
           zoomed, (src_x * dest_width) / src_width,
           (src_y * dest_height) / src_height);
  ::SDL_FreeSurface(zoomed);
}
Ejemplo n.º 6
0
void
Canvas::invert_stretch_transparent(const Bitmap &src, Color key)
{
  assert(IsDefined());
  assert(src.IsDefined());

  HDC virtual_dc = GetCompatibleDC();
  HBITMAP old = (HBITMAP)::SelectObject(virtual_dc, src.GetNative());
  const PixelSize size = src.GetSize();

  BufferCanvas inverted(*this, size.cx, size.cy);
  ::BitBlt(inverted, 0, 0, size.cx, size.cy,
           virtual_dc, 0, 0, NOTSRCCOPY);
  ::SelectObject(virtual_dc, old);

#ifdef _WIN32_WCE
  ::TransparentImage(dc, 0, 0, get_width(), get_height(),
                     inverted, 0, 0, size.cx, size.cy,
                     key);
#else
  ::TransparentBlt(dc, 0, 0, get_width(), get_height(),
                   inverted, 0, 0, size.cx, size.cy,
                   key);
#endif
}
Ejemplo n.º 7
0
void
Canvas::copy(PixelScalar dest_x, PixelScalar dest_y,
             UPixelScalar dest_width, UPixelScalar dest_height,
             const Bitmap &src, PixelScalar src_x, PixelScalar src_y)
{
  copy(dest_x, dest_y, dest_width, dest_height,
       src.GetNative(), src_x, src_y);
}
Ejemplo n.º 8
0
void
Canvas::Copy(int dest_x, int dest_y,
             unsigned dest_width, unsigned dest_height,
             const Bitmap &src, int src_x, int src_y)
{
  Copy(dest_x, dest_y, dest_width, dest_height,
       src.GetNative(), src_x, src_y);
}
Ejemplo n.º 9
0
void
Canvas::copy_and(PixelScalar dest_x, PixelScalar dest_y,
                 UPixelScalar dest_width, UPixelScalar dest_height,
                 const Bitmap &src, PixelScalar src_x, PixelScalar src_y)
{
  assert(src.IsDefined());

  copy_and(dest_x, dest_y, dest_width, dest_height,
           src.GetNative(), src_x, src_y);
}
Ejemplo n.º 10
0
void
Canvas::CopyAnd(int dest_x, int dest_y,
                unsigned dest_width, unsigned dest_height,
                const Bitmap &src, int src_x, int src_y)
{
  assert(src.IsDefined());

  CopyAnd(dest_x, dest_y, dest_width, dest_height,
          src.GetNative(), src_x, src_y);
}
Ejemplo n.º 11
0
void
Brush::Set(const Bitmap &bitmap)
{
  /* GDI works best when the bitmap is 8x8 - to avoid bad performance,
     disallow using any other bitmap size */
  assert(bitmap.GetSize().cx == 8);
  assert(bitmap.GetSize().cy == 8);

  Reset();
  brush = ::CreatePatternBrush(bitmap.GetNative());
}
Ejemplo n.º 12
0
void
Canvas::Stretch(int dest_x, int dest_y,
                unsigned dest_width, unsigned dest_height,
                const Bitmap &_src)
{
  assert(IsDefined());
  assert(_src.IsDefined());

  ConstImageBuffer src = _src.GetNative();
  Stretch(dest_x, dest_y, dest_width, dest_height,
          src, 0, 0, src.width, src.height);
}
Ejemplo n.º 13
0
void
Canvas::stretch(PixelScalar dest_x, PixelScalar dest_y,
                UPixelScalar dest_width, UPixelScalar dest_height,
                const Bitmap &src)
{
  assert(IsDefined());
  assert(src.IsDefined());

  SDL_Surface *surface = src.GetNative();
  stretch(dest_x, dest_y, dest_width, dest_height,
          surface, 0, 0, surface->w, surface->h);
}
Ejemplo n.º 14
0
void
Canvas::StretchNot(const Bitmap &src)
{
  assert(IsDefined());
  assert(src.IsDefined());

  const PixelSize size = src.GetSize();

  Stretch(0, 0, GetWidth(), GetHeight(),
          src.GetNative(), 0, 0, size.cx, size.cy,
          NOTSRCCOPY);
}
Ejemplo n.º 15
0
void
Canvas::stretch_transparent(const Bitmap &src, Color key)
{
  assert(src.IsDefined());

  SDL_Surface *surface = src.GetNative();

  ::SDL_SetColorKey(surface, SDL_SRCCOLORKEY,
                    ::SDL_MapRGB(surface->format, key.value.r,
                                 key.value.g, key.value.b));
  stretch(surface);
  ::SDL_SetColorKey(surface, 0, 0);
}
Ejemplo n.º 16
0
void
Canvas::Stretch(int dest_x, int dest_y,
                unsigned dest_width, unsigned dest_height,
                const Bitmap &src,
                int src_x, int src_y,
                unsigned src_width, unsigned src_height)
{
  assert(IsDefined());
  assert(src.IsDefined());

  Stretch(dest_x, dest_y, dest_width, dest_height,
          src.GetNative(),
          src_x, src_y, src_width, src_height);
}
Ejemplo n.º 17
0
void
Canvas::stretch(PixelScalar dest_x, PixelScalar dest_y,
                UPixelScalar dest_width, UPixelScalar dest_height,
                const Bitmap &src,
                PixelScalar src_x, PixelScalar src_y,
                UPixelScalar src_width, UPixelScalar src_height)
{
  assert(IsDefined());
  assert(src.IsDefined());

  stretch(dest_x, dest_y, dest_width, dest_height,
          src.GetNative(),
          src_x, src_y, src_width, src_height);
}
Ejemplo n.º 18
0
void
Canvas::Stretch(int dest_x, int dest_y,
                unsigned dest_width, unsigned dest_height,
                const Bitmap &src)
{
#ifdef HAVE_GLES
  assert(offset == OpenGL::translate);
#endif
  assert(src.IsDefined());

  OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

  GLTexture &texture = *src.GetNative();
  GLEnable scope(GL_TEXTURE_2D);
  texture.Bind();
  texture.Draw(dest_x, dest_y, dest_width, dest_height,
               0, 0, src.GetWidth(), src.GetHeight());
}
Ejemplo n.º 19
0
void
Canvas::StretchNot(const Bitmap &_src)
{
  assert(_src.IsDefined());

  ConstImageBuffer src = _src.GetNative();
  const unsigned src_x = 0, src_y = 0;
  const unsigned dest_x = 0, dest_y = 0;
  const unsigned dest_width = GetWidth();
  const unsigned dest_height = GetHeight();

  SDLRasterCanvas canvas(buffer);
  BitNotPixelOperations<ActivePixelTraits> operations;

  canvas.ScaleRectangle(dest_x, dest_y, dest_width, dest_height,
                        src.At(src_x, src_y), src.pitch, src.width, src.height,
                        operations);
}
Ejemplo n.º 20
0
void
Canvas::StretchAnd(int dest_x, int dest_y,
               unsigned dest_width, unsigned dest_height,
               const Bitmap &src, 
               int src_x, int src_y, unsigned src_width, unsigned src_height)
{
  assert(IsDefined());
  assert(src.IsDefined());
  
  ConstImageBuffer srcImg = src.GetNative();  
  
  SDLRasterCanvas canvas(buffer);
  BitAndPixelOperations<ActivePixelTraits> operations;

  canvas.ScaleRectangle(dest_x, dest_y, dest_width, dest_height,
                       srcImg.At(src_x, src_y), srcImg.pitch, src_width, src_height,
                       operations);
}
Ejemplo n.º 21
0
void
Canvas::Stretch(PixelScalar dest_x, PixelScalar dest_y,
                UPixelScalar dest_width, UPixelScalar dest_height,
                const Bitmap &src, PixelScalar src_x, PixelScalar src_y,
                UPixelScalar src_width, UPixelScalar src_height)
{
#ifdef HAVE_GLES
  assert(x_offset == OpenGL::translate_x);
  assert(y_offset == OpenGL::translate_y);
#endif
  assert(src.IsDefined());

  OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

  GLTexture &texture = *src.GetNative();
  GLEnable scope(GL_TEXTURE_2D);
  texture.Bind();
  texture.Draw(dest_x, dest_y, dest_width, dest_height,
               src_x, src_y, src_width, src_height);
}
Ejemplo n.º 22
0
void
Canvas::Stretch(int dest_x, int dest_y,
                unsigned dest_width, unsigned dest_height,
                const Bitmap &src, int src_x, int src_y,
                unsigned src_width, unsigned src_height)
{
#ifdef HAVE_GLES
  assert(offset == OpenGL::translate);
#endif
  assert(src.IsDefined());

#ifdef USE_GLSL
  OpenGL::texture_shader->Use();
#else
  const GLEnable scope(GL_TEXTURE_2D);
  OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
#endif

  GLTexture &texture = *src.GetNative();
  texture.Bind();
  texture.Draw(dest_x, dest_y, dest_width, dest_height,
               src_x, src_y, src_width, src_height);
}
Ejemplo n.º 23
0
void
Canvas::CopyAnd(const Bitmap &src)
{
  CopyAnd(0, 0, GetWidth(), GetHeight(),
          src.GetNative(), 0, 0);
}
Ejemplo n.º 24
0
void
Canvas::copy(const Bitmap &src)
{
  SDL_Surface *surface = src.GetNative();
  copy(0, 0, surface->w, surface->h, surface, 0, 0);
}
Ejemplo n.º 25
0
void
Brush::Set(const Bitmap &bitmap)
{
  Reset();
  brush = ::CreatePatternBrush(bitmap.GetNative());
}
Ejemplo n.º 26
0
void
Canvas::StretchMono(PixelScalar dest_x, PixelScalar dest_y,
                    UPixelScalar dest_width, UPixelScalar dest_height,
                    const Bitmap &src,
                    PixelScalar src_x, PixelScalar src_y,
                    UPixelScalar src_width, UPixelScalar src_height,
                    Color fg_color, Color bg_color)
{
  /* note that this implementation ignores the background color; it is
     not mandatory, and we can assume that the background is already
     set; it is only being passed to this function because the GDI
     implementation will be faster when erasing the background
     again */

  GLTexture &texture = *src.GetNative();
  GLEnable scope(GL_TEXTURE_2D);
  texture.Bind();

  OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

  if (fg_color == COLOR_WHITE) {
    /* white text requested: use this trivial implementation */
    GLLogicOp logic_op(GL_OR_INVERTED);
    texture.Draw(dest_x, dest_y, dest_width, dest_height,
                 src_x, src_y, src_width, src_height);
    return;
  }

  /* apply the mask, pixels will be black then */
  GLLogicOp logic_op(GL_AND);
  if (bg_color != COLOR_BLACK)
    texture.Draw(dest_x, dest_y, dest_width, dest_height,
                 src_x, src_y, src_width, src_height);

  if (fg_color != COLOR_BLACK) {
    /* draw */

#ifndef HAVE_GLES
    if (fg_color != COLOR_WHITE) {
      /* XXX OpenGL/ES doesn't support GL_OPERAND0_RGB; we can't print
         colored mono images currently */

      OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
      OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);
      OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB,
                        GL_ONE_MINUS_SRC_COLOR);

      const GLfloat color[] = {
        GLfloat(fg_color.Red() / 256.),
        GLfloat(fg_color.Green() / 256.),
        GLfloat(fg_color.Blue() / 256.),
        GLfloat(1.0),
      };

      OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_CONSTANT);
      OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
      OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
      glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color);

      logic_op.set(GL_OR);
    } else
#endif
      logic_op.set(GL_OR_INVERTED);

    texture.Draw(dest_x, dest_y, dest_width, dest_height,
                 src_x, src_y, src_width, src_height);
  }
}