Statistics
| Branch: | Revision:

ffmpeg / postproc / rgb2rgb_template.c @ b238eb2e

History | View | Annotate | Download (1.81 KB)

1
#include <inttypes.h>
2
#include "../config.h"
3
#include "rgb2rgb.h"
4
#include "mmx.h"
5

    
6
/* TODO: MMX optimization */
7

    
8
void rgb24to32(uint8_t *src,uint8_t *dst,uint32_t src_size)
9
{
10
  uint32_t *dest = (uint32_t *)dst;
11
  uint8_t *s = src;
12
  uint8_t *end;
13
  end = s + src_size;
14
  while(s < end)
15
  {
16
    uint32_t rgb0;
17
    rgb0 = *(uint32_t *)s;
18
    *dest++ = rgb0 & 0xFFFFFFUL;
19
    s += 3;
20
  }
21
}
22

    
23
void rgb32to24(uint8_t *src,uint8_t *dst,uint32_t src_size)
24
{
25
  uint8_t *dest = dst;
26
  uint8_t *s = src;
27
  uint8_t *end;
28
  end = s + src_size;
29
  while(s < end)
30
  {
31
    *dest++ = *s++;
32
    *dest++ = *s++;
33
    *dest++ = *s++;
34
    s++;
35
  }
36
}
37

    
38
/* Original by Strepto/Astral
39
 ported to gcc & bugfixed : A'rpi */
40
void rgb15to16(uint8_t *src,uint8_t *dst,uint32_t src_size)
41
{
42
#ifdef HAVE_MMX
43
  static uint64_t mask_b  = 0x001F001F001F001FLL; // 00000000 00011111  xxB
44
  static uint64_t mask_rg = 0x7FE07FE07FE07FE0LL; // 01111111 11100000  RGx
45
  register char* s=src+src_size;
46
  register char* d=dst+src_size;
47
  register int offs=-src_size;
48
  movq_m2r (mask_b,  mm4);
49
  movq_m2r (mask_rg, mm5);
50
  while(offs<0){
51
    movq_m2r (*(s+offs), mm0);
52
    movq_r2r (mm0, mm1);
53

    
54
    movq_m2r (*(s+8+offs), mm2);
55
    movq_r2r (mm2, mm3);
56
    
57
    pand_r2r (mm4, mm0);
58
    pand_r2r (mm5, mm1);
59
    
60
    psllq_i2r(1,mm1);
61
    pand_r2r (mm4, mm2);
62

    
63
    pand_r2r (mm5, mm3);
64
    por_r2r  (mm1, mm0);
65

    
66
    psllq_i2r(1,mm3);
67
    movq_r2m (mm0,*(d+offs));
68

    
69
    por_r2r  (mm3,mm2);
70
    movq_r2m (mm2,*(d+8+offs));
71

    
72
    offs+=16;
73
  }
74
  emms();
75
#else
76
   uint16_t *s1=( uint16_t * )src;
77
   uint16_t *d1=( uint16_t * )dst;
78
   uint16_t *e=((uint8_t *)s1)+src_size;
79
   while( s1<e ){
80
     register int x=*( s1++ );
81
     /* rrrrrggggggbbbbb
82
        0rrrrrgggggbbbbb
83
        0111 1111 1110 0000=0x7FE0
84
        00000000000001 1111=0x001F */
85
     *( d1++ )=( x&0x001F )|( ( x&0x7FE0 )<<1 );
86
   }
87
#endif
88
}