OpenCores
URL https://opencores.org/ocsvn/mb-jpeg/mb-jpeg/trunk

Subversion Repositories mb-jpeg

[/] [mb-jpeg/] [tags/] [arelease/] [decoder/] [color.c] - Blame information for rev 66

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 quickwayne
/*-----------------------------------------*/
2
/* File : color.c, utilities for jfif view */
3
/* Author : Pierre Guerrier, march 1998    */
4
/*-----------------------------------------*/
5
 
6
#include <stdlib.h>
7
#include <stdio.h>
8
 
9
/* Ensure number is >=0 and <=255                          */
10
#define Saturate(n)     ((n) > 0 ? ((n) < 255 ? (n) : 255) : 0)
11
 
12
/*------------------------------------------------------------*/
13
 
14
 
15
/* internal color conversion utility */
16
/*
17
static unsigned char
18
get_comp(int n, int i, int j)
19
{
20
  int ip = i >> comp[n].VDIV;   / * get coordinates in n-th comp pixels * /
21
  int jp = j >> comp[n].HDIV;   / * within the MCU * /
22
 
23
  return MCU_buff[comp[n].IDX+comp[n].HS*(ip>>3)+(jp>>3)]->block[ip&7][jp&7];
24
  / * this is the right block in MCU, and this right sample * /
25
}
26
*/
27
/* and alternate macro, a little faster */
28
/*
29
#define get_comp(t,n,i,j) { int ip = i >> comp[n].VDIV; \
30
                            int jp = j >> comp[n].HDIV; \
31
t = MCU_buff[comp[n].IDX+comp[n].HS*(ip>>3)+(jp>>3) ]->block[ip&7][jp& 7]; \
32
                        }
33
*/
34
 
35
/*---------------------------------------*/
36
/* rules for color conversion:           */
37
/*  r = y               +1.402  v        */
38
/*  g = y -0.34414u     -0.71414v        */
39
/*  b = y +1.772  u                      */
40
/* Approximations: 1.402 # 7/5 = 1.400   */
41
/*              .71414 # 357/500 = 0.714 */
42
/*              .34414 # 43/125 = 0.344  */
43
/*              1.772  = 443/250         */
44
/*---------------------------------------*/
45
/* Approximations: 1.402 # 359/256 = 1.40234 */
46
/*              .71414 # 183/256 = 0.71484 */
47
/*              .34414 # 11/32 = 0.34375 */
48
/*              1.772 # 227/128 = 1.7734 */
49
/*----------------------------------*/
50
 
51
void
52
color_conversion(void)
53
{
54
  int  i, j;
55
  unsigned char y,cb,cr;
56
  signed char rcb, rcr;
57
  long r,g,b;
58
  long offset;
59
 
60
  for (i = 0; i < MCU_sy; i++)   /* pixel rows */
61
    {
62
      int ip_0 = i >> comp[0].VDIV;
63
      int ip_1 = i >> comp[1].VDIV;
64
      int ip_2 = i >> comp[2].VDIV;
65
      int inv_ndx_0 = comp[0].IDX + comp[0].HS * (ip_0 >> 3);
66
      int inv_ndx_1 = comp[1].IDX + comp[1].HS * (ip_1 >> 3);
67
      int inv_ndx_2 = comp[2].IDX + comp[2].HS * (ip_2 >> 3);
68
      int ip_0_lsbs = ip_0 & 7;
69
      int ip_1_lsbs = ip_1 & 7;
70
      int ip_2_lsbs = ip_2 & 7;
71
      int i_times_MCU_sx = i * MCU_sx;
72
 
73
      for (j = 0; j < MCU_sx; j++)   /* pixel columns */
74
        {
75
          int jp_0 = j >> comp[0].HDIV;
76
          int jp_1 = j >> comp[1].HDIV;
77
          int jp_2 = j >> comp[2].HDIV;
78
 
79
          y  = MCU_buff[inv_ndx_0 + (jp_0 >> 3)]->block[ip_0_lsbs][jp_0 & 7];
80
          cb = MCU_buff[inv_ndx_1 + (jp_1 >> 3)]->block[ip_1_lsbs][jp_1 & 7];
81
          cr = MCU_buff[inv_ndx_2 + (jp_2 >> 3)]->block[ip_2_lsbs][jp_2 & 7];
82
 
83
          rcb = cb - 128;
84
          rcr = cr - 128;
85
 
86
          r = y + ((359 * rcr) >> 8);
87
          g = y - ((11 * rcb) >> 5) - ((183 * rcr) >> 8);
88
          b = y + ((227 * rcb) >> 7);
89
 
90
          offset = 3 * (i_times_MCU_sx + j);
91
          ColorBuffer[offset + 2] = Saturate(r);
92
          ColorBuffer[offset + 1] = Saturate(g);
93
          ColorBuffer[offset + 0] = Saturate(b);
94
          /* note that this is SunRaster color ordering */
95
        }
96
    }
97
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.