Exemple #1
0
LICE_pixel LICE_AlterColorHSV_int(LICE_pixel color, int dH, int dS, int dV)  // H is rolled over [0,384), S and V are clamped [0,255)
{
  int h, s, v;
  LICE_RGB2HSV(LICE_GETR(color), LICE_GETG(color), LICE_GETB(color), &h, &s, &v);
  
  h += dH;
  s += dS;
  v += dV;

  if (h < 0) h += 384;
  else if (h >= 384) h -= 384;
  
  if (s & ~255) 
  {
    if (s<0) s = 0;
    else s = 255;
  }
  
  if (v&~255)
  {
    if (v < 0) v = 0.;
    else v = 255;
  }

  return LICE_HSV2Pix(h, s, v, LICE_GETA(color));
}
Exemple #2
0
IColor IGraphics::GetPoint(int x, int y)
{
  LICE_pixel pix = _LICE::LICE_GetPixel(mDrawBitmap, x, y);
  return IColor(LICE_GETA(pix), LICE_GETR(pix), LICE_GETG(pix), LICE_GETB(pix));
}
Exemple #3
0
void LICE_AlterRectHSV(LICE_IBitmap* src, int x, int y, int w, int h, float dH, float dS, float dV) // H is rolled over, S and V are clamped
{
  if (!src) return;

  if (x < 0) {
    w += x;
    x = 0;
  }
  if (y < 0) {
    h += y;
    y = 0;
  }
  if (x+w > src->getWidth()) {
    w = src->getWidth()-x;
  }
  if (y+h > src->getHeight()) {
    h = src->getHeight()-y;
  }

  int span = src->getRowSpan();
  LICE_pixel* px = src->getBits()+y*span+x;  

  int dHi = (int)(dH*384.0f);
  int dSi = (int)(dS*255.0f);
  int dVi = (int)(dV*255.0f);
  if (dHi > 383) dHi=383;
  else if (dHi < -383) dHi=-383;


  if (!dHi && !dSi && !dVi) return; // no mod

  if (w*h > 8192)
  {
    // generate a table of HSV translations with clip/clamp
    unsigned char stab[256], vtab[256];
    short htab[384];
    int x;
    for(x=0;x<256;x++)
    {
      int a=x+dSi;
      if(a<0)a=0; else if (a>255)a=255;
      stab[x]=a;

      a=x+dVi;
      if(a<0)a=0; else if (a>255)a=255;
      vtab[x]=a;

      a=x+dHi;
      if(a<0)a+=384; else if (a>=384)a-=384;
      htab[x]=a;
    }
    for(;x<384;x++)
    {
      int a=x+dHi;
      if(a<0)a+=384; else if (a>=384)a-=384;
      htab[x]=a;
    }

    while (h-->0)
    {
      LICE_pixel* tpx = px;
      px+=span;
      int xi=w;
      while (xi-->0)
      {
        LICE_pixel color = *tpx;
        int h,s,v;
        LICE_RGB2HSV(LICE_GETR(color), LICE_GETG(color), LICE_GETB(color), &h, &s, &v);
        *tpx++ = LICE_HSV2Pix(htab[h],stab[s],vtab[v],LICE_GETA(color));
      }
    }
  }
  else
  {
    while (h-->0)
    {
      LICE_pixel* tpx = px;
      px+=span;
      int xi=w;
      while (xi-->0)
        *tpx++ = LICE_AlterColorHSV_int(*tpx, dHi, dSi, dVi);
    }
  }
}
void WDL_VirtualStaticText::OnPaint(LICE_IBitmap *drawbm, int origin_x, int origin_y, RECT *cliprect)
{
  RECT r=m_position;
  r.left+=origin_x;
  r.right+=origin_x;
  r.top += origin_y;
  r.bottom += origin_y;

  if (m_bkbm && m_bkbm->bgimage)
  {
    WDL_VirtualWnd_ScaledBlitBG(drawbm,m_bkbm,
      r.left,r.top,r.right-r.left,r.bottom-r.top,
      r.left,r.top,r.right-r.left,r.bottom-r.top,
      1.0,LICE_BLIT_MODE_COPY|LICE_BLIT_FILTER_BILINEAR|LICE_BLIT_USE_ALPHA);

    if (m_dotint && LICE_GETA(m_bg)) 
    {
        float amt = LICE_GETA(m_bg)/255.0f;

        // todo: apply amt

        float rv=LICE_GETR(m_bg)/255.0f;
        float gv=LICE_GETG(m_bg)/255.0f;
        float bv=LICE_GETB(m_bg)/255.0f;

        float avg=(rv+gv+bv)*0.33333f;
        if (avg<0.05f)avg=0.05f;

        float sc=0.5f*amt;
        float sc2 = (amt-sc)/avg;

        float sc3=32.0f * amt;
        float sc4=64.0f*(avg-0.5f) * amt;

        // tint
        LICE_MultiplyAddRect(drawbm,
          r.left,r.top,
            r.right-r.left,
            r.bottom-r.top,
            sc+rv*sc2 + (1.0f-amt),
            sc+gv*sc2 + (1.0f-amt),
            sc+bv*sc2 + (1.0f-amt),
            1.0f,
            (rv-avg)*sc3+sc4,
            (gv-avg)*sc3+sc4,
            (bv-avg)*sc3+sc4,
            0.0f);
    }
  }
  else 
  {
    if (LICE_GETA(m_bg))
    {
      LICE_FillRect(drawbm,r.left,r.top,r.right-r.left,r.bottom-r.top,m_bg,LICE_GETA(m_bg)/255.0f,LICE_BLIT_MODE_COPY);
    }

    if (m_wantborder)
    {    
      int cidx=COLOR_3DSHADOW;

      int pencol = GSC(cidx);
      pencol = LICE_RGBA_FROMNATIVE(pencol,255);

      LICE_Line(drawbm,r.left,r.bottom-1,r.left,r.top,pencol,1.0f,LICE_BLIT_MODE_COPY,false);
      LICE_Line(drawbm,r.left,r.top,r.right-1,r.top,pencol,1.0f,LICE_BLIT_MODE_COPY,false);
      cidx=COLOR_3DHILIGHT;
      pencol = GSC(cidx);
      pencol = LICE_RGBA_FROMNATIVE(pencol,255);
      LICE_Line(drawbm,r.right-1,r.top,r.right-1,r.bottom-1,pencol,1.0f,LICE_BLIT_MODE_COPY,false);
      LICE_Line(drawbm,r.right-1,r.bottom-1,r.left,r.bottom-1,pencol,1.0f,LICE_BLIT_MODE_COPY,false);

      r.left++;
      r.bottom--;
      r.top++;
      r.right--;

    }
  }

  if (m_text.Get()[0])
  {
    r.left += m_margin_l;
    r.right -= m_margin_r;
    r.top += m_margin_t;
    r.bottom -= m_margin_b;

    m_didvert=m_vfont && (r.right-r.left)<(r.bottom-r.top)/2;
    LICE_IFont *font = m_didvert ? m_vfont : m_font;

    if (font)
    {
      font->SetBkMode(TRANSPARENT);    

      m_didalign=m_align;
      if (m_didalign==0)
      {
        RECT r2={0,0,0,0};
        font->DrawText(drawbm,m_text.Get(),-1,&r2,DT_SINGLELINE|DT_NOPREFIX|DT_CALCRECT);
        if (m_didvert)
        {
         if (r2.bottom > r.bottom-r.top) m_didalign=-1;
        }
        else
        {
          if (r2.right > r.right-r.left) m_didalign=-1;
        }
      }

      int dtflags=DT_SINGLELINE|DT_NOPREFIX;

      if (m_didvert)
      {
        dtflags |= DT_CENTER;
        if (m_didalign < 0) dtflags |= DT_TOP;
        else if (m_didalign > 0) dtflags |= DT_BOTTOM;
        else dtflags |= DT_VCENTER;
      }
      else
      {
        dtflags|=DT_VCENTER;

        if (m_didalign < 0) dtflags |= DT_LEFT;
        else if (m_didalign > 0) dtflags |= DT_RIGHT;
        else dtflags |= DT_CENTER;
      }
      const char* txt=m_text.Get();
      const int len = m_text.GetLength();

      int abbrx=0;
      char abbrbuf[64];
      abbrbuf[0]=0;

      if (m_wantabbr)
      {
        if (len && isdigit(txt[len-1]))
        {
          RECT tr = { 0, 0, 0, 0 };
          font->DrawText(drawbm, txt, -1, &tr, DT_SINGLELINE|DT_NOPREFIX|DT_CALCRECT);
          if (m_didvert ? (tr.bottom > r.bottom-r.top) : (tr.right > r.right-r.left))
          {
            strcpy(abbrbuf, "..");
            int i;
            for (i=len-1; i >= 0; --i)
            {
              if (!isdigit(txt[i]) || len-i > 4) break;
            }
            strcat(abbrbuf, txt+i+1);

            int f=dtflags&~(DT_TOP|DT_VCENTER|DT_BOTTOM|DT_LEFT|DT_CENTER|DT_RIGHT);
            RECT tr2 = { 0, 0, 0, 0 };
            if (m_didvert)
            {
              font->DrawText(drawbm, abbrbuf, -1, &tr2, f|DT_CALCRECT);
              abbrx=tr2.bottom;
            }
            else
            {
              font->DrawText(drawbm, abbrbuf, -1, &tr2, f|DT_CALCRECT);
              abbrx=tr2.right;
            }
          }
        }
      }

      int tcol=m_fg ? m_fg : LICE_RGBA_FROMNATIVE(GSC(COLOR_BTNTEXT));
      font->SetTextColor(tcol);
      if (m_fg && LICE_GETA(m_fg) != 0xff) font->SetCombineMode(LICE_BLIT_MODE_COPY,LICE_GETA(m_fg)/255.0f);

      if (abbrx && abbrbuf[0])
      {
        if (m_didvert)
        {
          int f=dtflags&~(DT_TOP|DT_VCENTER|DT_BOTTOM);
          RECT r1 = { r.left, r.top, r.right, r.bottom-abbrx };
          font->DrawText(drawbm, txt, -1, &r1, f|DT_TOP);
          RECT r2 = { r.left, r.bottom-abbrx, r.right, r.bottom };
          font->DrawText(drawbm, abbrbuf, -1, &r2, f|DT_BOTTOM);
        }
        else
        {
          int f=dtflags&~(DT_LEFT|DT_CENTER|DT_RIGHT);
          RECT r1 = { r.left, r.top, r.right-abbrx, r.bottom };
          font->DrawText(drawbm, txt, -1, &r1, f|DT_LEFT);
          RECT r2 = { r.right-abbrx, r.top, r.right, r.bottom };
          font->DrawText(drawbm, abbrbuf, -1, &r2, f|DT_RIGHT);
        }
      }
      else
      {
        font->DrawText(drawbm,txt,-1,&r,dtflags);
      }

      if (m_fg && LICE_GETA(m_fg) != 0xff) font->SetCombineMode(LICE_BLIT_MODE_COPY,1.0f);
    }


  }
  WDL_VWnd::OnPaint(drawbm,origin_x,origin_y,cliprect);
}
Exemple #5
0
void LICECaptureCompressor::BitmapToFrameRec(LICE_IBitmap *fr, frameRec *dest)
{
  unsigned short *outptr = dest->data;
  const LICE_pixel *p = fr->getBits();
  int span = fr->getRowSpan();
  if (fr->isFlipped())
  {
    p+=(fr->getHeight()-1)*span;
    span=-span;
  }
  int h = fr->getHeight(),w=fr->getWidth();
  while (h--)
  {
    int x=w;
    const LICE_pixel *sp = p;
    while (x--)
    {
      LICE_pixel pix = *sp++;
      *outptr++ = (((int)LICE_GETR(pix)&0xF8)>>3) | (((int)LICE_GETG(pix)&0xFC)<<3) | (((int)LICE_GETB(pix)&0xF8)<<8);
    }
    p += span;
  }
}
void WDL_VirtualStaticText::OnPaint(LICE_IBitmap *drawbm, int origin_x, int origin_y, RECT *cliprect)
{
  RECT r=m_position;
  r.left+=origin_x;
  r.right+=origin_x;
  r.top += origin_y;
  r.bottom += origin_y;

  if (m_bkbm && m_bkbm->bgimage)
  {
    WDL_VirtualWnd_ScaledBlitBG(drawbm,m_bkbm,
      r.left,r.top,r.right-r.left,r.bottom-r.top,
      r.left,r.top,r.right-r.left,r.bottom-r.top,
      1.0,LICE_BLIT_MODE_COPY|LICE_BLIT_FILTER_BILINEAR|LICE_BLIT_USE_ALPHA);

    if (m_dotint && LICE_GETA(m_bg)) 
    {
        float amt = LICE_GETA(m_bg)/255.0f;

        // todo: apply amt

        float rv=LICE_GETR(m_bg)/255.0f;
        float gv=LICE_GETG(m_bg)/255.0f;
        float bv=LICE_GETB(m_bg)/255.0f;

        float avg=(rv+gv+bv)*0.33333f;
        if (avg<0.05f)avg=0.05f;

        float sc=0.5f*amt;
        float sc2 = (amt-sc)/avg;

        float sc3=32.0f * amt;
        float sc4=64.0f*(avg-0.5f) * amt;

        // tint
        LICE_MultiplyAddRect(drawbm,
          r.left,r.top,
            r.right-r.left,
            r.bottom-r.top,
            sc+rv*sc2 + (1.0-amt),
            sc+gv*sc2 + (1.0-amt),
            sc+bv*sc2 + (1.0-amt),
            1,
            (rv-avg)*sc3+sc4,
            (gv-avg)*sc3+sc4,
            (bv-avg)*sc3+sc4,
            0);
    }
  }
  else 
  {
    if (LICE_GETA(m_bg))
    {
      LICE_FillRect(drawbm,r.left,r.top,r.right-r.left,r.bottom-r.top,m_bg,LICE_GETA(m_bg)/255.0f,LICE_BLIT_MODE_COPY);
    }

    if (m_wantborder)
    {    
      int cidx=COLOR_3DSHADOW;

      int pencol = WDL_STYLE_GetSysColor(cidx);
      pencol = LICE_RGBA_FROMNATIVE(pencol,255);

      LICE_Line(drawbm,r.left,r.bottom-1,r.left,r.top,pencol,1.0f,LICE_BLIT_MODE_COPY,false);
      LICE_Line(drawbm,r.left,r.top,r.right-1,r.top,pencol,1.0f,LICE_BLIT_MODE_COPY,false);
      cidx=COLOR_3DHILIGHT;
      pencol = WDL_STYLE_GetSysColor(cidx);
      pencol = LICE_RGBA_FROMNATIVE(pencol,255);
      LICE_Line(drawbm,r.right-1,r.top,r.right-1,r.bottom-1,pencol,1.0f,LICE_BLIT_MODE_COPY,false);
      LICE_Line(drawbm,r.right-1,r.bottom-1,r.left,r.bottom-1,pencol,1.0f,LICE_BLIT_MODE_COPY,false);

      r.left++;
      r.bottom--;
      r.top++;
      r.right--;

    }
  }


  if (m_text.Get()[0])
  {

    r.left += m_margin_l;
    r.right -= m_margin_r;
    r.top += m_margin_t;
    r.bottom -= m_margin_b;

    m_didvert=m_vfont && (r.right-r.left)<(r.bottom-r.top);
    LICE_IFont *font = m_didvert ? m_vfont : m_font;


    if (font)
    {
      font->SetBkMode(TRANSPARENT);

    
      m_didalign=m_align;
      if (m_didalign==0)
      {
        RECT r2={0,0,0,0};
        font->DrawText(drawbm,m_text.Get(),-1,&r2,DT_SINGLELINE|DT_VCENTER|DT_LEFT|DT_NOPREFIX|DT_CALCRECT);
        if (r2.right > r.right-r.left) m_didalign=-1;
      }

      int tcol=m_fg ? m_fg : LICE_RGBA_FROMNATIVE(WDL_STYLE_GetSysColor(COLOR_BTNTEXT));
      font->SetTextColor(tcol);
      if (m_fg && LICE_GETA(m_fg) != 0xff) font->SetCombineMode(LICE_BLIT_MODE_COPY,LICE_GETA(m_fg)/255.0f);
      font->DrawText(drawbm,m_text.Get(),-1,&r,DT_SINGLELINE|DT_VCENTER|(m_didalign<0?DT_LEFT:m_didalign>0?DT_RIGHT:DT_CENTER)|DT_NOPREFIX);
      if (m_fg && LICE_GETA(m_fg) != 0xff) font->SetCombineMode(LICE_BLIT_MODE_COPY,1.0f);
    }


  }
  WDL_VWnd::OnPaint(drawbm,origin_x,origin_y,cliprect);
}
Exemple #7
0
static LICE_IBitmap *icoToBitmap(HICON icon, LICE_IBitmap *bmpOut)
{
  int icon_w = 16, icon_h=16;

#ifdef _WIN32
  ICONINFO ii={0,};
  if (GetIconInfo(icon,&ii))
  {
    bool blah=false;
    if (ii.hbmColor)
    {
      BITMAP bm={0,};
      if (GetObject(ii.hbmColor,sizeof(bm),&bm) && bm.bmWidth && bm.bmHeight)
      {
        icon_w=bm.bmWidth;
        icon_h=bm.bmHeight;
        blah=true;
      }
      DeleteObject(ii.hbmColor);
    }
    if (ii.hbmMask)
    {
      BITMAP bm={0,};
      if (!blah && GetObject(ii.hbmMask,sizeof(bm),&bm) && bm.bmWidth && bm.bmHeight)
      {
        icon_w=bm.bmWidth;
        icon_h=bm.bmHeight;
      }
      DeleteObject(ii.hbmMask);
    }
  }
#else
  BITMAP bm={0,};
  if (GetObject(icon,sizeof(bm),&bm) && bm.bmWidth && bm.bmHeight) // SWELL's GetObject() works on icons
  {
    icon_w=bm.bmWidth;
    icon_h=bm.bmHeight;
  }

#endif

  LICE_SysBitmap tempbm(icon_w*2,icon_h);
  LICE_FillRect(&tempbm,0,0,icon_w,icon_h,LICE_RGBA(0,0,0,255),1.0f,LICE_BLIT_MODE_COPY);
#ifdef _WIN32
  DrawIconEx(tempbm.getDC(),0,0,icon,icon_w,icon_h,0,NULL,DI_NORMAL);
#else
  {
    RECT r={0,0,icon_w,icon_h};
    DrawImageInRect(tempbm.getDC(),icon,&r);
  }
#endif

  LICE_FillRect(&tempbm,icon_w,0,icon_w,icon_h,LICE_RGBA(255,255,255,255),1.0f,LICE_BLIT_MODE_COPY);
#ifdef _WIN32
  DrawIconEx(tempbm.getDC(),icon_w,0,icon,icon_w,icon_h,0,NULL,DI_NORMAL);
#else
  {
    RECT r={icon_w,0,icon_w+icon_w,icon_h};
    DrawImageInRect(tempbm.getDC(),icon,&r);
  }
#endif

  if (!bmpOut) bmpOut = new LICE_MemBitmap(icon_w,icon_h);
  else bmpOut->resize(icon_w,icon_h);

  int y; // since we have the image drawn on white and on black, we can calculate the alpha channel...
  for(y=0;y<icon_h;y++)
  {
    int x;
    for(x=0;x<icon_w;x++)
    {
      LICE_pixel p = LICE_GetPixel(&tempbm,x,y);
      LICE_pixel p2 = LICE_GetPixel(&tempbm,x+icon_w,y);

      int r1=LICE_GETR(p);
      int g1=LICE_GETG(p);
      int b1=LICE_GETB(p);

      int alpha=255 - (LICE_GETR(p2)-r1);
      if (alpha>=255) alpha=255;
      else if (alpha>0)
      {
        r1 = (r1*255)/alpha; // LICE stores its alpha channel non-premultiplied, so we need to scale these up.
        g1 = (g1*255)/alpha;
        b1 = (b1*255)/alpha;
        if (r1>255)r1=255;
        if (g1>255)g1=255;
        if (b1>255)b1=255;
      }
      else alpha=0;
      LICE_PutPixel(bmpOut,x,y,LICE_RGBA(r1,g1,b1,alpha),1.0f,LICE_BLIT_MODE_COPY);
    }
  }

  return bmpOut;
}