Changeset 636df0d7bc8d467c915436684e3fb5580e53255f

Show
Ignore:
Timestamp:
01/31/04 06:53:35 (5 years ago)
Author:
Rocky Bernstein <rocky@videolan.org>
git-committer:
Rocky Bernstein <rocky@videolan.org> 1075528415 +0000
git-parent:

[acdfa3528ac2065633045d17717c47dae07f6552]

git-author:
Rocky Bernstein <rocky@videolan.org> 1075528415 +0000
Message:

render.c: RGB2 now gets the right color from the RGB color map.

And a first cut at handling transparancy values properly. However
to do this we merely needed to

pixmap.[ch]: write our own routines for retrieving a close colormap index

given a pixel value. Well, and also had to

video_chroma/i420_rgb.[ch]: save the RGB colormap that is allocated.

Modules.am: forgot new pixmap.c

others: more misc abstraction/cleanup

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/codec/ogt/Modules.am

    r5dab5a0 r636df0d  
    2121    subtitle.h \ 
    2222    cvd_parse.c \ 
     23    pixmap.c \ 
    2324    pixmap.h \ 
    2425    render.c \ 
  • modules/codec/ogt/common.c

    r5dab5a0 r636df0d  
    11/***************************************************************************** 
    2  * Common SVCD and VCD subtitle routines. 
     2 * Common SVCD and CVD subtitle routines. 
    33 ***************************************************************************** 
    44 * Copyright (C) 2003, 2004 VideoLAN 
    5  * $Id: common.c,v 1.11 2004/01/30 13:17:12 rocky Exp $ 
     5 * $Id: common.c,v 1.12 2004/01/31 05:53:35 rocky Exp $ 
    66 * 
    77 * Author: Rocky Bernstein <rocky@panix.com> 
  • modules/codec/ogt/pixmap.c

    r1a86038 r636df0d  
    33 ***************************************************************************** 
    44 * Copyright (C) 2003, 2004 VideoLAN 
    5  * $Id: pixmap.c,v 1.2 2004/01/30 13:23:08 rocky Exp $ 
     5 * $Id: pixmap.c,v 1.3 2004/01/31 05:53:35 rocky Exp $ 
    66 * 
    77 * Author: Rocky Bernstein 
     
    5151       p_rgb_b[i]) 
    5252     */ 
    53     uint8_t  *p_rgb_r;                   /* Red values of palette */ 
    54     uint8_t  *p_rgb_g;                   /* Green values of palette */ 
    55     uint8_t  *p_rgb_b;                   /* Blue values of palette */ 
     53    uint16_t  p_rgb_r[CMAP_RGB2_SIZE];    /* Red values of palette */ 
     54    uint16_t  p_rgb_g[CMAP_RGB2_SIZE];    /* Green values of palette */ 
     55    uint16_t  p_rgb_b[CMAP_RGB2_SIZE];    /* Blue values of palette */ 
    5656}; 
    5757 
    58  
    59 /* Number of entries in RGB palette/colormap*/ 
    60 #define CMAP_SIZE 256 
    6158 
    6259/*  
     
    111108/**  
    112109   Find the nearest colormap entry in p_vout (assumed to have RGB2 
    113    chroma, i.e. 256 RGB entries) that is closest in color to p_yuv.  Set 
    114    RGB to the color found and return the colormap index. -1 is returned 
    115    if there is some error. 
     110   chroma, i.e. 256 RGB 8bpp entries) that is closest in color to p_rgb.  Set 
     111   out_rgb to the color found and return the colormap index. 
     112   INVALID_CMAP_ENTRY is returned if there is some error. 
    116113 
    117114   The closest match is determined by the the Euclidean distance 
     
    122119*/ 
    123120 
    124 in
    125 find_cmap_rgb8_nearest(const vout_thread_t *p_vout, const ogt_yuvt_t *p_yuv
     121cmap_
     122find_cmap_rgb8_nearest(const vout_thread_t *p_vout, const uint8_t *rgb
    126123               uint8_t *out_rgb)  
    127124{ 
    128   uint8_t *p_cmap_r; 
    129   uint8_t *p_cmap_g; 
    130   uint8_t *p_cmap_b; 
    131   uint8_t rgb[RGB_SIZE]; 
     125  uint16_t *p_cmap_r; 
     126  uint16_t *p_cmap_g; 
     127  uint16_t *p_cmap_b; 
    132128   
    133129  int i; 
    134   int i_bestmatch=0
     130  cmap_t i_bestmatch = INVALID_CMAP_ENTRY
    135131  uint32_t i_mindist = 0xFFFFFFFF; /* The largest number here. */ 
    136132 
     
    138134   
    139135  if ( !p_vout && p_vout->output.i_chroma  != VLC_FOURCC('R','G','B','2') ) 
    140     return -1
     136    return INVALID_CMAP_ENTRY
    141137 
    142138  p_cmap_r=p_vout->chroma.p_sys->p_rgb_r; 
     
    144140  p_cmap_b=p_vout->chroma.p_sys->p_rgb_b; 
    145141 
    146   yuv2rgb(p_yuv, rgb); 
    147  
    148   for (i = 0; i < CMAP_SIZE; i++) { 
     142  for (i = 0; i < CMAP_RGB2_SIZE; i++) { 
    149143    /* Interval range calculations to show that we don't overflow the 
    150144       word sizes below. pixels component values start out 8 
     
    171165#define int32_sqr(x) ( ((int32_t) (x)) * ((int32_t) x) ) 
    172166 
    173     uint32_t dr = ( RED_COEF   * ( int32_sqr(rgb[RED_PIXEL]   - p_cmap_r[i]) 
     167    /* colormap entires are scaled to 16 bits, so we need to shift 
     168       them back down to 8. */ 
     169#define CMAP8_RED(i) (p_cmap_r[i]>>8) 
     170#define CMAP8_GREEN(i) (p_cmap_g[i]>>8) 
     171#define CMAP8_BLUE(i) (p_cmap_b[i]>>8) 
     172 
     173    uint32_t dr = ( RED_COEF   * ( int32_sqr(rgb[RED_PIXEL]   - CMAP8_RED(i)) 
    174174                 << SCALEBITS ) ) >> (SCALEBITS*2); 
    175     uint32_t dg = ( GREEN_COEF * ( int32_sqr(rgb[GREEN_PIXEL] - p_cmap_g[i]
     175    uint32_t dg = ( GREEN_COEF * ( int32_sqr(rgb[GREEN_PIXEL] - CMAP8_GREEN(i)
    176176                 << SCALEBITS ) ) >> (SCALEBITS*2); 
    177     uint32_t db = ( BLUE_COEF  * ( int32_sqr(rgb[BLUE_PIXEL]  - p_cmap_b[i]
    178                   << SCALEBITS ) ) >> (SCALEBITS*2); 
     177    uint32_t db = ( BLUE_COEF  * ( int32_sqr(rgb[BLUE_PIXEL]  - CMAP8_BLUE(i)
     178                 << SCALEBITS ) ) >> (SCALEBITS*2); 
    179179 
    180180    uint32_t i_dist = dr + dg + db; 
     
    182182      i_bestmatch = i; 
    183183      i_mindist = i_dist; 
     184#if 0       
     185      printf("+++Change dist to %d RGB cmap %d (%0x, %0x, %0x)\n",  
     186             i_dist, i, p_cmap_r[ i ], p_cmap_g[ i ], p_cmap_b[ i ]); 
     187#endif 
    184188    } 
    185189  } 
    186190 
    187   out_rgb[RED_PIXEL]   = p_cmap_r[i_bestmatch]; 
    188   out_rgb[GREEN_PIXEL] = p_cmap_g[i_bestmatch]; 
    189   out_rgb[BLUE_PIXEL]  = p_cmap_b[i_bestmatch]; 
     191  if (out_rgb)  
     192    { 
     193      out_rgb[RED_PIXEL]   = CMAP8_RED(i_bestmatch); 
     194      out_rgb[GREEN_PIXEL] = CMAP8_GREEN(i_bestmatch); 
     195      out_rgb[BLUE_PIXEL]  = CMAP8_BLUE(i_bestmatch); 
     196    } 
    190197 
    191198  return i_bestmatch; 
     199} 
     200 
     201/** 
     202   Get the the rgb value for a given colormap entry for p_vout (which is' 
     203   assumed to have RGB2 chroma).  
     204 
     205   VLC_FALSE is returned if there was some error. 
     206*/ 
     207vlc_bool_t 
     208query_color(const vout_thread_t *p_vout, cmap_t i_cmap, 
     209            /*out*/ uint8_t *out_rgb)  
     210{ 
     211  uint16_t *p_cmap_r; 
     212  uint16_t *p_cmap_g; 
     213  uint16_t *p_cmap_b; 
     214 
     215  /* Check that we really have RGB2. */ 
     216   
     217  if ( !p_vout && p_vout->output.i_chroma  != VLC_FOURCC('R','G','B','2') ) 
     218    return VLC_FALSE; 
     219 
     220  if ( !out_rgb )  
     221    return VLC_FALSE; 
     222 
     223  p_cmap_r=p_vout->chroma.p_sys->p_rgb_r; 
     224  p_cmap_g=p_vout->chroma.p_sys->p_rgb_g; 
     225  p_cmap_b=p_vout->chroma.p_sys->p_rgb_b; 
     226 
     227  out_rgb[RED_PIXEL]   = CMAP8_RED(i_cmap); 
     228  out_rgb[GREEN_PIXEL] = CMAP8_GREEN(i_cmap); 
     229  out_rgb[BLUE_PIXEL]  = CMAP8_BLUE(i_cmap); 
     230 
     231  return VLC_TRUE; 
    192232} 
    193233 
  • modules/codec/ogt/pixmap.h

    r5dab5a0 r636df0d  
    33 ***************************************************************************** 
    44 * Copyright (C) 2003, 2004 VideoLAN 
    5  * $Id: pixmap.h,v 1.4 2004/01/30 13:17:12 rocky Exp $ 
     5 * $Id: pixmap.h,v 1.5 2004/01/31 05:53:35 rocky Exp $ 
    66 * 
    77 * Author: Rocky Bernstein 
     
    3636  } s; 
    3737} ogt_yuvt_t; 
     38 
     39/** An undefined or invalid colormap index. */ 
     40#define INVALID_CMAP_ENTRY -1 
     41 
     42/** Type of a palette/colormap index*/ 
     43typedef int16_t cmap_t; 
     44 
     45/** Number of entries in RGB palette/colormap*/ 
     46#define CMAP_RGB2_SIZE 256 
    3847 
    3948/** 
     
    114123 */ 
    115124static inline void 
    116 put_rgb24_pixel(const uint8_t *rgb, uint8_t *p_pixel) 
     125put_rgb24_pixel(const uint8_t *rgb, /*out*/ uint8_t *p_pixel) 
    117126{ 
    118127#ifdef WORDS_BIGENDIAN 
     
    125134 
    126135/** 
    127  Find the nearest colormap entry in p_vout (assumed to have RGB2 
    128  chroma, i.e. 256 RGB entries) that is closest in color to p_yuv.  Set 
    129  rgb to the color found and return the colormap index. -1 is returned 
    130  if there is some error. 
     136   Find the nearest colormap entry in p_vout (assumed to have RGB2 
     137   chroma, i.e. 256 RGB 8bpp entries) that is closest in color to p_rgb.  Set 
     138   out_rgb to the color found and return the colormap index.  
     139   INVALID_CMAP_ENTRY is returned if there is some error. 
    131140*/ 
    132 int 
    133 find_cmap_nearest(const vout_thread_t *p_vout, const ogt_yuvt_t *p_yuv, 
    134           uint8_t *rgb); 
     141cmap_t 
     142find_cmap_rgb8_nearest(const vout_thread_t *p_vout, const uint8_t *p_rgb, 
     143                       /*out*/ uint8_t *out_rgb); 
     144 
     145/** 
     146   Get the the rgb value for a given colormap entry for p_vout (which is' 
     147   assumed to have RGB2 chroma).  
     148    
     149   VLC_FALSE is returned if there was some error. 
     150*/ 
     151vlc_bool_t 
     152query_color(const vout_thread_t *p_vout, cmap_t i_cmap, 
     153            /*out*/ uint8_t *rgb); 
    135154 
    136155#endif /* PIXMAP_H */ 
  • modules/codec/ogt/render.c

    rafd56ce r636df0d  
    33 ***************************************************************************** 
    44 * Copyright (C) 2003, 2004 VideoLAN 
    5  * $Id: render.c,v 1.26 2004/01/29 11:50:22 rocky Exp $ 
     5 * $Id: render.c,v 1.27 2004/01/31 05:53:35 rocky Exp $ 
    66 * 
    77 * Author: Rocky Bernstein <rocky@panix.com> 
     
    2626 *****************************************************************************/ 
    2727 
    28 /*#define TESTING_BLENDING 1*/ 
     28/*#define TESTING_TRANSPARENCY 1*/ 
    2929 
    3030/***************************************************************************** 
     
    236236          } 
    237237 
    238 #ifdef TESTING_BLENDING 
     238#ifdef TESTING_TRANSPARENCY 
    239239          if (p_source->s.t == MAX_ALPHA) p_source->s.t >>= 1; 
    240240#endif 
     
    435435            i_avg_tr = ( p_source->s.t + (p_source+1)->s.t ) / 2; 
    436436           
    437 #ifdef TESTING_BLENDING  
     437#ifdef TESTING_TRANSPARENCY  
    438438          if (i_avg_tr == MAX_ALPHA) i_avg_tr >>= 1; 
    439439#endif 
     
    802802          } 
    803803           
    804 #ifdef TESTING_BLENDING 
     804#ifdef TESTING_TRANSPARENCY 
    805805              if (p_source->s.t == MAX_ALPHA) p_source->s.t >>= 1; 
    806806#endif 
     
    11111111          } 
    11121112           
    1113 #ifdef TESTING_BLENDING 
     1113#ifdef TESTING_TRANSPARENCY 
    11141114              if (p_source->s.t == MAX_ALPHA) p_source->s.t >>= 2; 
    11151115#endif 
     
    15751575} 
    15761576 
     1577/* 
     1578  Return the colormap index for the average of p_pixel and a subtitle 
     1579  pixel in RGB form. 
     1580 */ 
     1581static inline cmap_t 
     1582avg_rgb2(const vout_thread_t *p_vout, uint8_t i_pixel, cmap_t i_cmap_sub, 
     1583         const uint8_t rgb_sub[] ) 
     1584{ 
     1585  uint8_t rgb_vout[RGB_SIZE]; 
     1586  static cmap_t avg_cache[CMAP_RGB2_SIZE][NUM_SUBTITLE_COLORS]; 
     1587  static vlc_bool_t b_first_time = VLC_TRUE; 
     1588  int i; 
     1589 
     1590  /* FIXME: really we need to save subtitle number since in theory 
     1591     the palette can change each on each distinct subtitle. In practice 
     1592     this doesn't happen that much. 
     1593   */ 
     1594  if (b_first_time)  
     1595    { 
     1596      int i, j; 
     1597      for (i=0; i<CMAP_RGB2_SIZE; i++)  
     1598        for (j=0; j<NUM_SUBTITLE_COLORS; j++)  
     1599          avg_cache[i][j] = INVALID_CMAP_ENTRY; 
     1600    } 
     1601 
     1602  if ( avg_cache[i_pixel][i_cmap_sub] != INVALID_CMAP_ENTRY )  
     1603    return avg_cache[i_pixel][i_cmap_sub]; 
     1604 
     1605  if ( !query_color(p_vout, i_pixel, rgb_vout) ) return INVALID_CMAP_ENTRY; 
     1606 
     1607  for (i = 0; i < RGB_SIZE; i++)  
     1608    { 
     1609      rgb_vout[i] = (rgb_vout[i] + rgb_sub[i]) / 2; 
     1610    } 
     1611 
     1612#if 0 
     1613 { 
     1614  uint8_t rgb_approx[RGB_SIZE]; 
     1615 
     1616  avg_cache[i_pixel][i_cmap_sub] =  
     1617    find_cmap_rgb8_nearest(p_vout, rgb_vout, rgb_approx); 
     1618  printf( 
     1619         "cmap old %0x new 0%x sub=(%0x, %0x, %0x) " 
     1620         "avg=(%0x, %0x, %0x) vout=(%0x, %0x, %0x)\n",  
     1621         i_pixel, i_cmap, 
     1622         rgb_sub[RED_PIXEL], rgb_sub[GREEN_PIXEL], rgb_sub[BLUE_PIXEL], 
     1623         rgb_approx[RED_PIXEL], rgb_approx[GREEN_PIXEL], rgb_approx[BLUE_PIXEL], 
     1624         rgb_vout[RED_PIXEL], rgb_vout[GREEN_PIXEL], rgb_vout[BLUE_PIXEL]); 
     1625 }   
     1626#else  
     1627  avg_cache[i_pixel][i_cmap_sub] =  
     1628    find_cmap_rgb8_nearest(p_vout, rgb_vout, NULL); 
     1629#endif 
     1630  return avg_cache[i_pixel][i_cmap_sub]; 
     1631} 
     1632 
    15771633#undef  BYTES_PER_PIXEL 
    15781634#define BYTES_PER_PIXEL 1 
     
    16021658    int i_x_start, i_y_start, i_x_end, i_y_end; 
    16031659 
    1604     /* 4 entry colormap */ 
     1660    /* 4-entry array of colormap indices */ 
    16051661    uint8_t cmap[NUM_SUBTITLE_COLORS]; 
    1606     int i_cmap; 
     1662    int i; 
     1663 
     1664    /* Actual RGB values for above; this is used in blending.*/ 
     1665    uint8_t cmap_rgb[NUM_SUBTITLE_COLORS][RGB_SIZE]; 
    16071666 
    16081667    struct subpicture_sys_t *p_sys = p_spu->p_sys; 
     
    16121671                      &i_aspect_x ); 
    16131672     
    1614     /* Find a corresponding colormap entries for our palette entries. */ 
    1615     for( i_cmap = 0; i_cmap < NUM_SUBTITLE_COLORS; i_cmap++ ) 
    1616     { 
    1617       uint8_t Y = p_sys->p_palette[i_cmap].s.y; 
    1618  
    1619       /* FIXME: when we have a way to look at colormap entries we can 
    1620          do better.  For now we have to use 0xff for white 0x00 for 
    1621          black and 0x44 for something in between. To do this we use 
    1622          only the Y component. 
    1623       */ 
    1624       if (Y > 0x70)  
    1625         cmap[i_cmap] = 0xff; /* Use white. */ 
    1626       else if (Y < 0x10)  
    1627         cmap[i_cmap] = 0x00; /* Use black. */ 
    1628       else  
    1629         cmap[i_cmap] = 0x44; /* Use something else. */ 
    1630     } 
    1631  
    16321673    i_xscale = (( p_vout->output.i_width << ASCALE ) * i_aspect_x) 
    16331674      / (i_aspect_y * p_vout->render.i_width); 
     
    16441685    i_width  = p_spu->i_width  * i_xscale; 
    16451686    i_height = p_spu->i_height * i_yscale; 
     1687 
     1688 
     1689    /** FIXME: do once per subtitle in subtitle processing, not here 
     1690        each time we render.  */ 
     1691    /* Find a corresponding colormap entries for our palette entries. */ 
     1692    for( i = 0; i < NUM_SUBTITLE_COLORS; i++ ) 
     1693    { 
     1694 
     1695      if ( p_sys->p_palette[i].s.t != 0 ) { 
     1696        uint8_t rgb[RGB_SIZE];  
     1697        uint8_t approx_rgb[RGB_SIZE];  
     1698        yuv2rgb(&(p_sys->p_palette[i]), rgb); 
     1699        cmap[i] =  
     1700          find_cmap_rgb8_nearest(p_vout, rgb, approx_rgb); 
     1701        dbg_print( (DECODE_DBG_RENDER),  
     1702                   "palette %d RGB=(%0x, %0x, %0x)\n", i, 
     1703                   rgb[RED_PIXEL], rgb[GREEN_PIXEL], rgb[BLUE_PIXEL]); 
     1704      } 
     1705    } 
    16461706 
    16471707    /* Set where we will start blending subtitle from using 
     
    17071767               
    17081768              p_yuvt = p_sys->p_palette[*p_source & 0x3]; 
    1709               if ( (p_yuvt.s.t) < (MAX_ALPHA) / 2 ) { 
    1710                 /* Completely or relatively transparent. Don't change pixel. */ 
    1711                 ; 
     1769 
     1770#ifdef TESTING_TRANSPARENCY 
     1771              if (p_yuvt.s.t == MAX_ALPHA) p_yuvt.s.t >>= 1; 
     1772#endif 
     1773 
     1774              switch ( p_yuvt.s.t )  
     1775                { 
     1776                case 0: 
     1777          /* Completely transparent. Don't change pixel. */ 
    17121778#if 0 
    1713                 printf(" "); /*++++*/ 
    1714 #endif 
    1715               } else { 
    1716                 uint32_t i_xdest = ( ((i_x*i_xscale) >> ASCALE)  
    1717                                      * BYTES_PER_PIXEL ); 
    1718                 uint32_t i_xlast = ( (((i_x+1)*i_xscale) >> ASCALE) 
    1719                                      * BYTES_PER_PIXEL ); 
    1720                 /* This is the pixel that's going to change;*/ 
    1721                 uint8_t *p_dest = p_pixel_base_y + i_xdest; 
    1722                 memset( p_dest, cmap[*p_source & 0x3], i_xlast - i_xdest ); 
     1779                  printf(" "); /*++++*/ 
     1780#endif 
     1781                  break; 
     1782                case MAX_ALPHA:  
     1783                  { 
     1784                    uint32_t i_xdest = ( ((i_x*i_xscale) >> ASCALE)  
     1785                                         * BYTES_PER_PIXEL ); 
     1786                    uint32_t i_xlast = ( (((i_x+1)*i_xscale) >> ASCALE) 
     1787                                         * BYTES_PER_PIXEL ); 
     1788                    /* This is the pixel that's going to change;*/ 
     1789                    uint8_t *p_dest = p_pixel_base_y + i_xdest; 
     1790                    memset( p_dest, cmap[*p_source & 0x3], i_xlast - i_xdest ); 
    17231791#if 0 
    1724                 printf("%1d", *p_source); /*++++*/ 
    1725 #endif 
    1726               } 
    1727                
     1792                    printf("%1d", *p_source); /*++++*/ 
     1793#endif 
     1794                    break; 
     1795                  } 
     1796                default: 
     1797                  { 
     1798                    uint32_t i_xdest = ( ((i_x*i_xscale) >> ASCALE)  
     1799                                         * BYTES_PER_PIXEL ); 
     1800                    uint32_t i_xlast = ( (((i_x+1)*i_xscale) >> ASCALE) 
     1801                                         * BYTES_PER_PIXEL ); 
     1802                    /* This is the pixel that's going to change;*/ 
     1803                    uint8_t *p_pixel = p_pixel_base_y + i_xdest; 
     1804                    uint32_t len     = i_xlast - i_xdest; 
     1805 
     1806                    for ( len = i_xlast - i_xdest -1; len >= 0; len-- )  
     1807                      { 
     1808                        cmap_t i_cmap  = avg_rgb2(p_vout, *p_pixel,  
     1809                                                  cmap[*p_source], 
     1810                                                  cmap_rgb[*p_source]); 
     1811                        if (i_cmap != INVALID_CMAP_ENTRY)  
     1812                          *p_pixel= (uint8_t) i_cmap; 
     1813                        p_pixel++; 
     1814                      } 
     1815#if 0 
     1816                    printf("%1d", *p_source); /*++++*/ 
     1817#endif 
     1818                  } 
     1819                } 
    17281820            } 
    17291821#if 0 
     
    17591851              } 
    17601852               
    1761               if ( (p_yuvt.s.t) < (MAX_ALPHA) / 2 ) { 
    1762                 /* Completely or relatively transparent. Don't change pixel. */ 
    1763                 ; 
     1853#ifdef TESTING_TRANSPARENCY 
     1854              if (p_yuvt.s.t == MAX_ALPHA) p_yuvt.s.t >>= 1; 
     1855#endif 
     1856              switch ( p_yuvt.s.t )  
     1857                { 
     1858                case 0: 
     1859          /* Completely transparent. Don't change pixel. */ 
    17641860#if 0 
    1765                 printf(" "); /*++++*/ 
    1766 #endif 
    1767               } else { 
    1768                 uint32_t i_xdest = ( ((i_x*i_xscale) >> ASCALE)  
    1769                                      * BYTES_PER_PIXEL ); 
    1770                 uint32_t i_xlast = ( (((i_x+1)*i_xscale) >> ASCALE) 
    1771                                      * BYTES_PER_PIXEL ); 
    1772                 uint32_t len     = i_xlast - i_xdest; 
     1861                  printf(" "); /*++++*/ 
     1862#endif 
     1863                  break; 
     1864                case MAX_ALPHA:  
     1865                  { 
     1866                    uint32_t i_xdest = ( ((i_x*i_xscale) >> ASCALE)  
     1867                                         * BYTES_PER_PIXEL ); 
     1868                    uint32_t i_xlast = ( (((i_x+1)*i_xscale) >> ASCALE) 
     1869                                         * BYTES_PER_PIXEL ); 
     1870                    uint32_t len     = i_xlast - i_xdest; 
    17731871#if 0 
    1774                 printf("%1d", *p_source); /*++++*/ 
    1775 #endif 
    1776                 for( i_ytmp = i_yreal ; i_ytmp < i_ynext ; 
    1777                      i_ytmp += p_pic->p->i_pitch ) { 
    1778                   uint8_t *p_dest = p_pixel_base + i_ytmp + i_xdest; 
    1779                   memset( p_dest, cmap[*p_source & 0x3], len ); 
     1872                    printf("%1d", *p_source); /*++++*/ 
     1873#endif 
     1874                    for( i_ytmp = i_yreal ; i_ytmp < i_ynext ; 
     1875                         i_ytmp += p_pic->p->i_pitch ) { 
     1876                      uint8_t *p_dest = p_pixel_base + i_ytmp + i_xdest; 
     1877                      memset( p_dest, cmap[*p_source & 0x3], len ); 
     1878                    } 
     1879                    break; 
     1880                  } 
     1881                default: 
     1882                  { 
     1883                    uint32_t i_xdest = ( ((i_x*i_xscale) >> ASCALE)  
     1884                                         * BYTES_PER_PIXEL ); 
     1885                    uint32_t i_xlast = ( (((i_x+1)*i_xscale) >> ASCALE) 
     1886                                         * BYTES_PER_PIXEL ); 
     1887                    int32_t len; 
     1888#if 0 
     1889                    printf("%1d", *p_source); /*++++*/ 
     1890#endif 
     1891 
     1892                    for( i_ytmp = i_yreal ; i_ytmp < i_ynext ; 
     1893                         i_ytmp += p_pic->p->i_pitch ) { 
     1894                      /* This is the pixel that's going to change;*/ 
     1895                      uint8_t *p_pixel = p_pixel_base + i_ytmp + i_xdest; 
     1896                      for ( len = i_xlast - i_xdest -1; len >= 0; len-- )  
     1897                        { 
     1898                          cmap_t i_cmap  = avg_rgb2(p_vout, *p_pixel,  
     1899                                                    cmap[*p_source], 
     1900                                                    cmap_rgb[*p_source]); 
     1901                          if (i_cmap != INVALID_CMAP_ENTRY)  
     1902                            *p_pixel= (uint8_t) i_cmap; 
     1903                          p_pixel++; 
     1904                        } 
     1905                    } 
     1906                  } 
    17801907                } 
    1781               } 
    1782             } 
    1783  
     1908             } 
    17841909        } 
    17851910      } 
  • modules/video_chroma/i420_rgb.c

    r5ca0ebc r636df0d  
    22 * i420_rgb.c : YUV to bitmap RGB conversion module for vlc 
    33 ***************************************************************************** 
    4  * Copyright (C) 2000, 2001 VideoLAN 
    5  * $Id: i420_rgb.c,v 1.6 2003/12/22 14:32:56 sam Exp $ 
     4 * Copyright (C) 2000, 2001, 2004 VideoLAN 
     5 * $Id: i420_rgb.c,v 1.7 2004/01/31 05:53:35 rocky Exp $ 
    66 * 
    77 * Author: Sam Hocevar <sam@zoy.org> 
     
    345345    int r,g,b; 
    346346    int i = 0, j = 0; 
    347     uint16_t red[ 256 ], green[ 256 ], blue[ 256 ]; 
     347    uint16_t *p_cmap_r=p_vout->chroma.p_sys->p_rgb_r; 
     348    uint16_t *p_cmap_g=p_vout->chroma.p_sys->p_rgb_g; 
     349    uint16_t *p_cmap_b=p_vout->chroma.p_sys->p_rgb_b; 
     350 
    348351    unsigned char p_lookup[PALETTE_TABLE_SIZE]; 
    349352 
     
    372375 
    373376                    /* Clip the colors */ 
    374                     red[ j ] = CLIP( r ); 
    375                     green[ j ] = CLIP( g ); 
    376                     blue[ j ] = CLIP( b ); 
     377                    p_cmap_r[ j ] = CLIP( r ); 
     378                    p_cmap_g[ j ] = CLIP( g ); 
     379                    p_cmap_b[ j ] = CLIP( b ); 
     380 
     381#if 0 
     382            printf("+++Alloc RGB cmap %d (%d, %d, %d)\n", j, 
     383               p_cmap_r[ j ] >>8, p_cmap_g[ j ] >>8,  
     384               p_cmap_b[ j ] >>8); 
     385#endif 
    377386 
    378387                    /* Allocate color */ 
     
    391400 
    392401    /* The colors have been allocated, we can set the palette */ 
    393     p_vout->output.pf_setpalette( p_vout, red, green, blue ); 
     402    p_vout->output.pf_setpalette( p_vout, p_cmap_r, p_cmap_g, p_cmap_b ); 
    394403 
    395404#if 0 
  • modules/video_chroma/i420_rgb.h

    r41a8349 r636df0d  
    22 * i420_rgb.h : YUV to bitmap RGB conversion module for vlc 
    33 ***************************************************************************** 
    4  * Copyright (C) 2000 VideoLAN 
    5  * $Id: i420_rgb.h,v 1.4 2003/08/29 18:58:05 fenrir Exp $ 
     4 * Copyright (C) 2000, 2004 VideoLAN 
     5 * $Id: i420_rgb.h,v 1.5 2004/01/31 05:53:35 rocky Exp $ 
    66 * 
    77 * Authors: Samuel Hocevar <sam@zoy.org> 
     
    2222 *****************************************************************************/ 
    2323 
    24 /***************************************************************************** 
     24/** Number of entries in RGB palette/colormap */ 
     25#define CMAP_RGB2_SIZE 256 
     26 
     27/** 
    2528 * chroma_sys_t: chroma method descriptor 
    26  ***************************************************************************** 
     29 
    2730 * This structure is part of the chroma transformation descriptor, it 
    2831 * describes the yuv2rgb specific properties. 
    29  *****************************************************************************
     32 *
    3033struct chroma_sys_t 
    3134{ 
     
    3437 
    3538#ifdef MODULE_NAME_IS_i420_rgb 
    36     /* Pre-calculated conversion tables */ 
    37     void *p_base;                          /* base for all conversion tables */ 
    38     uint8_t   *p_rgb8;                                   /* RGB 8 bits table */ 
    39     uint16_t  *p_rgb16;                                 /* RGB 16 bits table */ 
    40     uint32_t  *p_rgb32;                                 /* RGB 32 bits table */ 
     39    /**< Pre-calculated conversion tables */ 
     40    void *p_base;                      /**< base for all conversion tables */ 
     41    uint8_t   *p_rgb8;                 /**< RGB 8 bits table */ 
     42    uint16_t  *p_rgb16;                /**< RGB 16 bits table */ 
     43    uint32_t  *p_rgb32;                /**< RGB 32 bits table */ 
     44 
     45    /**< To get RGB value for palette entry i, use (p_rgb_r[i], p_rgb_g[i], 
     46       p_rgb_b[i]). Note these are 16 bits per pixel. For 8bpp entries, 
     47       shift right 8 bits. 
     48    */ 
     49    uint16_t  p_rgb_r[CMAP_RGB2_SIZE];  /**< Red values of palette */ 
     50    uint16_t  p_rgb_g[CMAP_RGB2_SIZE];  /**< Green values of palette */ 
     51    uint16_t  p_rgb_b[CMAP_RGB2_SIZE];  /**< Blue values of palette */ 
    4152#endif 
    4253};