Ignore:
Timestamp:
May 13, 2011, 9:13:58 AM (12 years ago)
Author:
Sam Hocevar
Message:

imlib: reverse the image::put_image logic.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • abuse/trunk/src/imlib/image.cpp

    r555 r644  
    319319
    320320
    321 void image::put_image(image *screen, int16_t x, int16_t y, char transparent)
     321void image::PutImage(image *im, int16_t x, int16_t y, char transparent)
    322322{
    323323    int16_t i, j, xl, yl;
     
    325325
    326326    // the screen is clipped then we only want to put part of the image
    327     if(screen->m_special)
    328     {
    329         put_part(screen, x, y, 0, 0, m_size.x-1, m_size.y-1, transparent);
     327    if(m_special)
     328    {
     329        PutPart(im, x, y, 0, 0, im->m_size.x-1, im->m_size.y-1, transparent);
    330330        return;
    331331    }
    332332
    333     if(x < screen->Size().x && y < screen->Size().y)
    334     {
    335         xl = m_size.x;
    336         if(x + xl > screen->Size().x) // clip to the border of the screen
    337             xl = screen->Size().x - x;
    338         yl = m_size.y;
    339         if(y + yl > screen->Size().y)
    340             yl = screen->Size().y - y;
     333    if(x < m_size.x && y < m_size.y)
     334    {
     335        xl = im->m_size.x;
     336        if(x + xl > m_size.x) // clip to the border of the screen
     337            xl = m_size.x - x;
     338        yl = im->m_size.y;
     339        if(y + yl > m_size.y)
     340            yl = m_size.y - y;
    341341
    342342        int startx = 0, starty = 0;
     
    355355            return;
    356356
    357         screen->AddDirty(x, y, x + xl, y + yl);
    358         screen->Lock();
     357        AddDirty(x, y, x + xl, y + yl);
    359358        Lock();
     359        im->Lock();
    360360        for(j = starty; j < yl; j++, y++)
    361361        {
    362             pg1 = screen->scan_line(y);
    363             pg2 = scan_line(j);
     362            pg1 = scan_line(y);
     363            pg2 = im->scan_line(j);
    364364            if(transparent)
    365365            {
     
    375375                memcpy(&pg1[x], pg2, xl); // straight copy
    376376        }
     377        im->Unlock();
    377378        Unlock();
    378         screen->Unlock();
    379379    }
    380380}
     
    434434
    435435
    436 void image::put_part(image *screen, int16_t x, int16_t y,
    437         int16_t x1, int16_t y1, int16_t x2, int16_t y2, char transparent)
     436void image::PutPart(image *im, int16_t x, int16_t y, int16_t x1, int16_t y1,
     437                    int16_t x2, int16_t y2, char transparent)
    438438{
    439439  int16_t xlen, ylen, j, i;
     
    442442
    443443  int cx1, cy1, cx2, cy2;
    444   screen->GetClip(cx1, cy1, cx2, cy2);
    445 
     444  GetClip(cx1, cy1, cx2, cy2);
    446445
    447446  // see if the are to be put is outside of actual image, if so adjust
     
    449448  if (x1<0) { x+=-x1; x1=0; }
    450449  if (y1<0) { y+=-y1; y1=0; }
    451   if (x2>=m_size.x) x2=m_size.x-1;
    452   if (y2>=m_size.y) y2=m_size.y-1;
     450  if (x2>=im->m_size.x) x2=im->m_size.x-1;
     451  if (y2>=im->m_size.y) y2=im->m_size.y-1;
    453452  if (x1>x2 || y1>y2) return ;      // return if it was adjusted so that nothing will be put
    454 
    455453
    456454  // see if the image gets clipped off the screen
    457455  if (x >= cx2 || y >= cy2 || x + (x2 - x1) < cx1 || y + (y2 - y1) < cy1)
    458456    return ;
    459 
    460457
    461458  if (x<cx1)
     
    471468  if (x1>x2 || y1>y2) return ;
    472469
    473 
    474 
    475 
    476470  xlen=x2-x1+1;
    477471  ylen=y2-y1+1;
    478472
    479   screen->AddDirty(x, y, x + xlen, y + ylen);
    480 
    481   screen->Lock();
     473  AddDirty(x, y, x + xlen, y + ylen);
     474
    482475  Lock();
    483   pg1=screen->scan_line(y);
    484   pg2=scan_line(y1);
     476  im->Lock();
     477  pg1 = scan_line(y);
     478  pg2 = im->scan_line(y1);
    485479
    486480  if (transparent)
     
    490484      for (i=0, source=&pg2[x1], dest=&pg1[x]; i<xlen; i++, source++, dest++)
    491485        if (*source) *dest=*source;
    492       pg1=screen->next_line(y+j, pg1);
    493       pg2=next_line(y1+j, pg2);
     486      pg1=next_line(y+j, pg1);
     487      pg2=im->next_line(y1+j, pg2);
    494488    }
    495489  }
     
    498492  {
    499493    memcpy(&pg1[x], &pg2[x1], xlen);   // strait copy
    500     pg1=screen->next_line(y+j, pg1);
    501     pg2=next_line(y1+j, pg2);
    502   }
     494    pg1 = next_line(y+j, pg1);
     495    pg2 = im->next_line(y1+j, pg2);
     496  }
     497  im->Unlock();
    503498  Unlock();
    504   screen->Unlock();
    505 }
    506 
    507 void image::put_part_xrev(image *screen, int16_t x, int16_t y,
    508         int16_t x1, int16_t y1, int16_t x2, int16_t y2, char transparent)
     499}
     500
     501void image::PutPartXrev(image *im, int16_t x, int16_t y, int16_t x1,
     502                        int16_t y1, int16_t x2, int16_t y2, char transparent)
    509503{
    510504  int16_t xl, yl, j, i;
     
    512506  CHECK(x1<=x2 && y1<=y2);
    513507
    514   i=x1; x1=m_size.x-x2-1;  // reverse the x locations
    515   x2=m_size.x-i-1;
     508  i=x1; x1=im->m_size.x-x2-1;  // reverse the x locations
     509  x2=im->m_size.x-i-1;
    516510
    517511  if (x1<0)
     
    520514  { y-=y1; y1=0; }
    521515
    522   if (screen->m_special)
     516  if (m_special)
    523517  {
    524518    int cx1, cy1, cx2, cy2;
    525     screen->m_special->GetClip(cx1, cy1, cx2, cy2);
     519    m_special->GetClip(cx1, cy1, cx2, cy2);
    526520    // FIXME: don't we need < cx1 instead of < 0 here?
    527521    if (x >= cx2 || y >= cy2 || x + (x2 - x1) < 0 || y + (y2 - y1) < 0)
     
    536530    { y2 = cy2 - 1 - y + y1; }
    537531  }
    538   else  if (x>screen->Size().x || y>screen->Size().y || x+x2<0 || y+y2<0)
     532  else  if (x > m_size.x || y > m_size.y || x+x2<0 || y+y2<0)
    539533    return ;
    540534
    541   if (x<screen->Size().x && y<screen->Size().y && x1<m_size.x && y1<m_size.y &&
     535  if (x<m_size.x && y<m_size.y && x1<im->m_size.x && y1<im->m_size.y &&
    542536      x1<=x2 && y1<=y2)
    543537  {
    544     if (x2>=m_size.x)
    545       x2=m_size.x-1;
    546     if (y2>=m_size.y)
    547       y2=m_size.y-1;
     538    if (x2>=im->m_size.x)
     539      x2=im->m_size.x-1;
     540    if (y2>=im->m_size.y)
     541      y2=im->m_size.y-1;
    548542    xl=x2-x1+1;
    549     if (x+xl>screen->Size().x)
    550       xl=screen->Size().x-x;
     543    if (x+xl>m_size.x)
     544      xl=m_size.x-x;
    551545    yl=y2-y1+1;
    552     if (y+yl>screen->Size().y)
    553       yl=screen->Size().y-y;
    554     screen->AddDirty(x, y, x + xl, y + yl);
    555     screen->Lock();
     546    if (y+yl>m_size.y)
     547      yl=m_size.y-y;
     548    AddDirty(x, y, x + xl, y + yl);
    556549    Lock();
     550    im->Lock();
    557551    for (j=0; j<yl; j++)
    558552    {
    559       pg1=screen->scan_line(y+j);
    560       pg2=scan_line(y1+j);
     553      pg1=scan_line(y+j);
     554      pg2=im->scan_line(y1+j);
    561555      if (transparent)
    562556      {
     
    569563    }
    570564    Unlock();
    571     screen->Unlock();
    572   }
    573 }
    574 
    575 
    576 void image::put_part_masked(image *screen, image *mask, int16_t x, int16_t y,
    577         int16_t maskx, int16_t masky,
    578         int16_t x1, int16_t y1, int16_t x2, int16_t y2)
     565    im->Unlock();
     566  }
     567}
     568
     569void image::PutPartMasked(image *im, image *mask, int16_t x, int16_t y,
     570                          int16_t maskx, int16_t masky,
     571                          int16_t x1, int16_t y1, int16_t x2, int16_t y2)
    579572{
    580573  int16_t xl, yl, j, i, ml, mh;
     
    582575  CHECK(x1<=x2 && y1<=y2);
    583576
    584   if (screen->m_special)
     577  if (m_special)
    585578  {
    586579    int cx1, cy1, cx2, cy2;
    587     screen->m_special->GetClip(cx1, cy1, cx2, cy2);
     580    m_special->GetClip(cx1, cy1, cx2, cy2);
    588581    if (x >= cx2 || y >= cy2 || x+(x2-x1)<0 || y+(y2-y1)<0) return ;
    589582    if (x<cx1)
     
    596589    { y2 = cy2 - 1 + y1 - y; }
    597590  }
    598   else  if (x>screen->Size().x || y>screen->Size().y || x+x1<0 || y+y1<0)
     591  else  if (x>m_size.x || y>m_size.y || x+x1<0 || y+y1<0)
    599592    return ;
    600593
    601594  ml=mask->Size().x;
    602595  mh=mask->Size().y;
    603   if (x<screen->Size().x && y<screen->Size().y && x1<m_size.x && y1<m_size.y &&
     596  if (x<m_size.x && y<m_size.y && x1<im->m_size.x && y1<im->m_size.y &&
    604597      maskx<ml && masky<mh && x1<=x2 && y1<=y2)
    605598  {
    606599
    607     if (x2>=m_size.x)
    608       x2=m_size.x-1;
    609     if (y2>=m_size.y)
    610       y2=m_size.y-1;
     600    if (x2>=im->m_size.x)
     601      x2=im->m_size.x-1;
     602    if (y2>=im->m_size.y)
     603      y2=im->m_size.y-1;
    611604    xl=x2-x1+1;
    612     if (x+xl>screen->Size().x)
    613       xl=screen->Size().x-x-1;
     605    if (x+xl>m_size.x)
     606      xl=m_size.x-x-1;
    614607    yl=y2-y1+1;
    615     if (y+yl>screen->Size().y)
    616       yl=screen->Size().y-y-1;
    617     screen->AddDirty(x, y, x + xl, y + yl);
    618     screen->Lock();
     608    if (y+yl>m_size.y)
     609      yl=m_size.y-y-1;
     610    AddDirty(x, y, x + xl, y + yl);
     611    Lock();
    619612    mask->Lock();
    620     Lock();
     613    im->Lock();
    621614    for (j=0; j<yl; j++)
    622615    {
    623       pg1=screen->scan_line(y+j);
    624       pg2=scan_line(y1+j);
     616      pg1=scan_line(y+j);
     617      pg2=im->scan_line(y1+j);
    625618      pg3=mask->scan_line(masky++);
    626619      if (masky>=mh)           // wrap the mask around if out of bounds
     
    634627      }
    635628    }
     629    im->Unlock();
     630    mask->Unlock();
    636631    Unlock();
    637     mask->Unlock();
    638     screen->Unlock();
    639632  }
    640633}
Note: See TracChangeset for help on using the changeset viewer.