Ignore:
Timestamp:
Apr 22, 2011, 7:32:13 PM (12 years ago)
Author:
Sam Hocevar
Message:

imlib: rename trans_image to TImage. The code is now clean enough.

File:
1 edited

Legend:

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

    r532 r533  
    1111#include "config.h"
    1212
     13#include <cstdio>
     14#include <cstring>
     15
    1316#include "common.h"
    1417
    1518#include "timage.h"
    1619
    17 trans_image::trans_image(image *im, char const *name)
     20TImage::TImage(image *im, char const *name)
    1821{
    1922    m_size = im->Size();
     
    5053    if (!parser)
    5154    {
    52         printf("size = %d %d (%d bytes)\n",im->Size().x,im->Size().y,bytes);
    53         CONDITION(parser, "malloc error for trans_image::m_data");
     55        printf("size = %d %d (%d bytes)\n", m_size.x, m_size.y, bytes);
     56        CONDITION(parser, "malloc error for TImage::m_data");
    5457    }
    5558
     
    8891}
    8992
    90 trans_image::~trans_image()
     93TImage::~TImage()
    9194{
    9295    free(m_data);
    9396}
    9497
    95 image *trans_image::ToImage()
     98image *TImage::ToImage()
    9699{
    97100    image *im = new image(m_size);
     
    102105    im->Unlock();
    103106
    104     PutImage(im, 0, 0);
     107    PutImage(im, vec2i(0));
    105108    return im;
    106109}
    107110
    108 uint8_t *trans_image::ClipToLine(image *screen, int x1, int y1, int x2, int y2,
    109                                  int x, int &y, int &ysteps)
     111uint8_t *TImage::ClipToLine(image *screen, vec2i pos1, vec2i pos2,
     112                            vec2i &pos, int &ysteps)
    110113{
    111114    // check to see if it is totally clipped out first
    112     if (y + m_size.y <= y1 || y >= y2 || x >= x2 || x + m_size.x <= x1)
     115    if (pos.y + m_size.y <= pos1.y || pos.y >= pos2.y
     116         || pos.x >= pos2.x || pos.x + m_size.x <= pos1.x)
    113117        return NULL;
    114118
    115119    uint8_t *parser = m_data;
    116120
    117     int skiplines = Max(y1 - y, 0); // number of lines to skip
    118     ysteps = Min(y2 - y, m_size.y - skiplines); // number of lines to draw
    119     y += skiplines; // first line to draw
     121    // Number of lines to skip, number of lines to draw, first line to draw
     122    int skiplines = Max(pos1.y - pos.y, 0);
     123    ysteps = Min(pos2.y - pos.y, m_size.y - skiplines);
     124    pos.y += skiplines;
    120125
    121126    while (skiplines--)
     
    133138    }
    134139
    135     screen->AddDirty(Max(x, x1), y, Min(x + m_size.x, x2), y + m_size.y);
     140    screen->AddDirty(Max(pos.x, pos1.x), pos.y,
     141                     Min(pos.x + m_size.x, pos2.x), pos.y + m_size.y);
    136142    return parser;
    137143}
    138144
    139145template<int N>
    140 void trans_image::PutImageGeneric(image *screen, int x, int y, uint8_t color,
    141                                   image *blend, int bx, int by,
    142                                   uint8_t *remap, uint8_t *remap2,
    143                                   int amount, int total_frames,
    144                                   uint8_t *tint, color_filter *f, palette *pal)
    145 {
    146     int x1, y1, x2, y2;
     146void TImage::PutImageGeneric(image *screen, vec2i pos, uint8_t color,
     147                             image *blend, vec2i bpos, uint8_t *map,
     148                             uint8_t *map2, int amount, int total_frames,
     149                             uint8_t *tint, color_filter *f, palette *pal)
     150{
     151    vec2i pos1, pos2;
    147152    int ysteps, mul = 0;
    148153
    149     screen->GetClip(x1, y1, x2, y2);
     154    screen->GetClip(pos1.x, pos1.y, pos2.x, pos2.y);
    150155
    151156    if (N == SCANLINE)
    152157    {
    153         y1 = Max(y1, y + amount);
    154         y2 = Min(y2, y + amount + 1);
    155         if (y1 >= y2)
     158        pos1.y = Max(pos1.y, pos.y + amount);
     159        pos2.y = Min(pos2.y, pos.y + amount + 1);
     160        if (pos1.y >= pos2.y)
    156161            return;
    157162    }
    158163
    159     uint8_t *datap = ClipToLine(screen, x1, y1, x2, y2, x, y, ysteps),
     164    uint8_t *datap = ClipToLine(screen, pos1, pos2, pos, ysteps),
    160165            *screen_line, *blend_line = NULL, *paddr = NULL;
    161166    if (!datap)
    162167        return; // if ClipToLine says nothing to draw, return
    163168
    164     CONDITION(N == BLEND && y >= by && y + ysteps < by + blend->Size().y + 1,
    165               "Blend doesn't fit on trans_image");
     169    CONDITION(N == BLEND && pos.y >= bpos.y
     170                         && pos.y + ysteps < bpos.y + blend->Size().y + 1,
     171              "Blend doesn't fit on TImage");
    166172
    167173    if (N == FADE || N == FADE_TINT || N == BLEND)
     
    174180
    175181    if (N == PREDATOR)
    176         ysteps = Min(ysteps, y2 - 1 - y - 2);
     182        ysteps = Min(ysteps, pos2.y - 1 - pos.y - 2);
    177183
    178184    screen->Lock();
    179185
    180     screen_line = screen->scan_line(y) + x;
     186    screen_line = screen->scan_line(pos.y) + pos.x;
    181187    int sw = screen->Size().x;
    182     x1 -= x; x2 -= x;
    183 
    184     for (; ysteps > 0; ysteps--, y++)
     188    pos1.x -= pos.x; pos2.x -= pos.x;
     189
     190    for (; ysteps > 0; ysteps--, pos.y++)
    185191    {
    186192        if (N == BLEND)
    187             blend_line = blend->scan_line(y - by);
     193            blend_line = blend->scan_line(pos.y - bpos.y);
    188194
    189195        for (int ix = 0; ix < m_size.x; )
     
    203209
    204210            // Chop left side if necessary, but no more than todo
    205             int tochop = Min(todo, Max(x1 - ix, 0));
     211            int tochop = Min(todo, Max(pos1.x - ix, 0));
    206212
    207213            ix += tochop;
     
    211217
    212218            // Chop right side if necessary and process the remaining pixels
    213             int count = Min(todo, Max(x2 - ix, 0));
     219            int count = Min(todo, Max(pos2.x - ix, 0));
    214220
    215221            if (N == NORMAL || N == SCANLINE)
     
    229235                uint8_t *sl = screen_line, *sl2 = datap;
    230236                while (count--)
    231                     *sl++ = remap[*sl2++];
     237                    *sl++ = map[*sl2++];
    232238            }
    233239            else if (N == REMAP2)
     
    235241                uint8_t *sl = screen_line, *sl2 = datap;
    236242                while (count--)
    237                     *sl++ = remap2[remap[*sl2++]];
     243                    *sl++ = map2[map[*sl2++]];
    238244            }
    239245            else if (N == FADE || N == FADE_TINT || N == BLEND)
    240246            {
    241247                uint8_t *sl = screen_line;
    242                 uint8_t *sl2 = (N == BLEND) ? blend_line + x + ix - bx : sl;
     248                uint8_t *sl2 = (N == BLEND) ? blend_line + pos.x + ix - bpos.x
     249                                            : sl;
    243250                uint8_t *sl3 = datap;
    244251
     
    246253                {
    247254                    uint8_t *p1 = paddr + 3 * *sl2++;
    248                     uint8_t *p2 = paddr + 3 * (N == FADE_TINT ? tint[*sl3++] : *sl3++);
     255                    uint8_t *p2 = paddr + 3 * (N == FADE_TINT ? tint[*sl3++]
     256                                                              : *sl3++);
    249257
    250258                    uint8_t r = ((((int)p1[0] - p2[0]) * mul) >> 16) + p2[0];
     
    265273}
    266274
    267 void trans_image::PutImage(image *screen, int x, int y)
    268 {
    269     PutImageGeneric<NORMAL>(screen, x, y, 0, NULL, 0, 0, NULL, NULL,
     275void TImage::PutImage(image *screen, vec2i pos)
     276{
     277    PutImageGeneric<NORMAL>(screen, pos, 0, NULL, 0, NULL, NULL,
    270278                            0, 1, NULL, NULL, NULL);
    271279}
    272280
    273 void trans_image::PutRemap(image *screen, int x, int y, uint8_t *remap)
    274 {
    275     PutImageGeneric<REMAP>(screen, x, y, 0, NULL, 0, 0, remap, NULL,
     281void TImage::PutRemap(image *screen, vec2i pos, uint8_t *map)
     282{
     283    PutImageGeneric<REMAP>(screen, pos, 0, NULL, 0, map, NULL,
    276284                           0, 1, NULL, NULL, NULL);
    277285}
    278286
    279 void trans_image::PutDoubleRemap(image *screen, int x, int y,
    280                                  uint8_t *remap, uint8_t *remap2)
    281 {
    282     PutImageGeneric<REMAP2>(screen, x, y, 0, NULL, 0, 0, remap, remap2,
     287void TImage::PutDoubleRemap(image *screen, vec2i pos,
     288                            uint8_t *map, uint8_t *map2)
     289{
     290    PutImageGeneric<REMAP2>(screen, pos, 0, NULL, 0, map, map2,
    283291                            0, 1, NULL, NULL, NULL);
    284292}
    285293
    286294// Used when eg. the player teleports, or in rocket trails
    287 void trans_image::PutFade(image *screen, int x, int y,
    288                           int amount, int total_frames,
    289                           color_filter *f, palette *pal)
    290 {
    291     PutImageGeneric<FADE>(screen, x, y, 0, NULL, 0, 0, NULL, NULL,
     295void TImage::PutFade(image *screen, vec2i pos, int amount, int total_frames,
     296                     color_filter *f, palette *pal)
     297{
     298    PutImageGeneric<FADE>(screen, pos, 0, NULL, 0, NULL, NULL,
    292299                          amount, total_frames, NULL, f, pal);
    293300}
    294301
    295 void trans_image::PutFadeTint(image *screen, int x, int y,
    296                               int amount, int total_frames,
    297                               uint8_t *tint, color_filter *f, palette *pal)
    298 {
    299     PutImageGeneric<FADE_TINT>(screen, x, y, 0, NULL, 0, 0, NULL, NULL,
     302void TImage::PutFadeTint(image *screen, vec2i pos, int amount, int total_frames,
     303                         uint8_t *tint, color_filter *f, palette *pal)
     304{
     305    PutImageGeneric<FADE_TINT>(screen, pos, 0, NULL, 0, NULL, NULL,
    300306                               amount, total_frames, tint, f, pal);
    301307}
    302308
    303 void trans_image::PutColor(image *screen, int x, int y, uint8_t color)
    304 {
    305     PutImageGeneric<COLOR>(screen, x, y, color, NULL, 0, 0, NULL, NULL,
     309void TImage::PutColor(image *screen, vec2i pos, uint8_t color)
     310{
     311    PutImageGeneric<COLOR>(screen, pos, color, NULL, 0, NULL, NULL,
    306312                           0, 1, NULL, NULL, NULL);
    307313}
     
    309315// This method is unused but is believed to work.
    310316// Assumes that the blend image completely covers the transparent image.
    311 void trans_image::PutBlend(image *screen, int x, int y,
    312                            image *blend, int bx, int by,
    313                            int amount, color_filter *f, palette *pal)
    314 {
    315     PutImageGeneric<BLEND>(screen, x, y, 0, blend, bx, by, NULL, NULL,
     317void TImage::PutBlend(image *screen, vec2i pos, image *blend, vec2i bpos,
     318                      int amount, color_filter *f, palette *pal)
     319{
     320    PutImageGeneric<BLEND>(screen, pos, 0, blend, bpos, NULL, NULL,
    316321                           amount, 1, NULL, f, pal);
    317322}
    318323
    319 void trans_image::PutFilled(image *screen, int x, int y, uint8_t color)
    320 {
    321     PutImageGeneric<FILLED>(screen, x, y, color, NULL, 0, 0, NULL, NULL,
     324void TImage::PutFilled(image *screen, vec2i pos, uint8_t color)
     325{
     326    PutImageGeneric<FILLED>(screen, pos, color, NULL, 0, NULL, NULL,
    322327                            0, 1, NULL, NULL, NULL);
    323328}
    324329
    325 void trans_image::PutPredator(image *screen, int x, int y)
    326 {
    327     PutImageGeneric<PREDATOR>(screen, x, y, 0, NULL, 0, 0, NULL, NULL,
     330void TImage::PutPredator(image *screen, vec2i pos)
     331{
     332    PutImageGeneric<PREDATOR>(screen, pos, 0, NULL, 0, NULL, NULL,
    328333                              0, 1, NULL, NULL, NULL);
    329334}
    330335
    331 void trans_image::PutScanLine(image *screen, int x, int y, int line)
    332 {
    333     PutImageGeneric<SCANLINE>(screen, x, y, 0, NULL, 0, 0, NULL, NULL,
     336void TImage::PutScanLine(image *screen, vec2i pos, int line)
     337{
     338    PutImageGeneric<SCANLINE>(screen, pos, 0, NULL, 0, NULL, NULL,
    334339                              line, 1, NULL, NULL, NULL);
    335340}
    336341
    337 size_t trans_image::MemUsage()
     342size_t TImage::MemUsage()
    338343{
    339344    uint8_t *d = m_data;
Note: See TracChangeset for help on using the changeset viewer.