OpenCores
URL https://opencores.org/ocsvn/video_dithering/video_dithering/trunk

Subversion Repositories video_dithering

[/] [video_dithering/] [trunk/] [dither.vhd] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 Peip_Rober
library IEEE;
2
use IEEE.std_logic_1164.all;
3
use IEEE.numeric_std.all;
4
 
5
entity eDither  is
6
   generic
7
   (
8
      img_width       : integer := 512;
9
      img_height      : integer := 512;
10
      color_width     : integer := 8;
11
      reduced_width   : integer := 4
12
   );
13
   port
14
   (
15
      clk       : in  std_logic;
16
      enable    : in  std_logic;
17
 
18
      x         : in  integer range 0 to img_width-1;
19
 
20
      din_r     : in  std_logic_vector(color_width-1 downto 0);
21
      din_g     : in  std_logic_vector(color_width-1 downto 0);
22
      din_b     : in  std_logic_vector(color_width-1 downto 0);
23
 
24
      dout_r    : out std_logic_vector(color_width-1 downto 0) := (others => '0');
25
      dout_g    : out std_logic_vector(color_width-1 downto 0) := (others => '0');
26
      dout_b    : out std_logic_vector(color_width-1 downto 0) := (others => '0')
27
   );
28
end entity;
29
 
30
architecture arch of eDither is
31
 
32
   constant dither_bits : integer := color_width - reduced_width;
33
 
34
   -- intermediate signals for caclulation
35
   type t_dither_rgb is array(1 to 3) of unsigned(dither_bits-1 downto 0);
36
   signal dither_buffer_next : t_dither_rgb := (others => (others =>'0'));
37
   signal dither_buffer_newline : t_dither_rgb := (others => (others =>'0'));
38
   signal dither_buffer_toRam : t_dither_rgb := (others => (others =>'0'));
39
   signal dither_buffer_fromRam : t_dither_rgb := (others => (others =>'0'));
40
 
41
   -- infered ram for holding old pixel information
42
   type t_dither_buffer is array(0 to img_width-1) of unsigned((dither_bits * 3)-1 downto 0);
43
   signal dither_buffer : t_dither_buffer := (others => (others => '0'));
44
   signal index : integer range 0 to img_width-1 := 0;
45
   signal AddrA : integer range 0 to img_width-1 := 0;
46
   signal AddrB : integer range 0 to img_width-1 := 0;
47
   signal WEA   : std_logic := '0';
48
 
49
 
50
begin
51
 
52
   process (clk)
53
      type t_intermediate is array(1 to 3) of unsigned(color_width downto 0);
54
      variable intermediate_color : t_intermediate;
55
   begin
56
      if rising_edge(clk) then
57
 
58
         -- calculate dithered colors
59
         if (enable = '1') then
60
 
61
            intermediate_color(1) := ("0" & unsigned(din_r)) + dither_buffer_next(1) + unsigned(dither_buffer_fromRam(1));
62
            intermediate_color(2) := ("0" & unsigned(din_g)) + dither_buffer_next(2) + unsigned(dither_buffer_fromRam(2));
63 3 Peip_Rober
            intermediate_color(3) := ("0" & unsigned(din_b)) + dither_buffer_next(3) + unsigned(dither_buffer_fromRam(3));
64 2 Peip_Rober
 
65
            for c in 1 to 3 loop
66
 
67
               if (intermediate_color(c)(8) = '1') then intermediate_color(c) := '0' & to_unsigned((2**color_width) - 1, color_width); end if;
68
 
69
               dither_buffer_next(c) <= "0" & intermediate_color(c)(dither_bits-1 downto 1);
70
               dither_buffer_newline(c) <= "00" & intermediate_color(c)(dither_bits-1 downto 2);
71
               dither_buffer_toRam(c) <= ("00" & intermediate_color(c)(dither_bits-1 downto 2)) + dither_buffer_newline(c);
72
            end loop;
73
 
74
         else
75
            intermediate_color(1) := "0" & unsigned(din_r);
76
            intermediate_color(2) := "0" & unsigned(din_g);
77
            intermediate_color(3) := "0" & unsigned(din_b);
78
         end if;
79
 
80
 
81
         -- calculate address for line buffer + enable
82
         if (x<img_width-2) then
83
            AddrB <= x+2;
84
         elsif (x=img_width-2) then
85
            AddrB <= 0;
86
         else
87
            AddrB <= 1;
88
         end if;
89
 
90
         index <= x;
91
         AddrA <= index;
92
 
93
         if (enable = '1') then
94
            WEA <= '1';
95
         else
96
            WEA <= '0';
97
         end if;
98
 
99
         -- line buffer memory
100
         if (WEA = '1') then
101
            dither_buffer(AddrA) <= dither_buffer_toRam(1) & dither_buffer_toRam(2) & dither_buffer_toRam(3);
102
         end if;
103
 
104
         dither_buffer_fromRam(1) <= dither_buffer(AddrB)((dither_bits * 3)-1 downto (dither_bits * 2));
105
         dither_buffer_fromRam(2) <= dither_buffer(AddrB)((dither_bits * 2)-1 downto dither_bits);
106
         dither_buffer_fromRam(3) <= dither_buffer(AddrB)(dither_bits-1 downto 0);
107
 
108
         -- map outputs
109
         dout_r <= std_logic_vector(intermediate_color(1)(color_width-1 downto 0));
110
         dout_g <= std_logic_vector(intermediate_color(2)(color_width-1 downto 0));
111
         dout_b <= std_logic_vector(intermediate_color(3)(color_width-1 downto 0));
112
 
113
      end if;
114
   end process;
115
 
116
 
117
end architecture;

powered by: WebSVN 2.1.0

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