image_patterns.c 3.52 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "image_patterns.h"
#include "frame_buffer_control.h"
#include "waveform_patterns.h"
#include "motion_patterns.h"
#include "ram.h"

// private variables
unsigned char img_pattern_data[IMG_MAX_NUM_IMAGES][IMG_MAX_IMAGE_WIDTH][IMG_MAX_IMAGE_HEIGHT][3]={{{{0}}}};

// private functions
void img_patterns_compute_range(unsigned short int area_min,unsigned short int area_max,short int pattern_start,unsigned short int max_size,unsigned short int *buff_start, unsigned short int *buff_end,unsigned char *img_start)
{
  unsigned short int cp_size;

  if(pattern_start<0)
  {
    *buff_start=area_min;
    *img_start=-pattern_start;
    if((-pattern_start)<max_size)
      cp_size=max_size+pattern_start;
    else
      cp_size=0;
  } 
  else if(pattern_start>(area_max-area_min))
  {
    *buff_start=0;
    *img_start=0;
    cp_size=0;
  }
  else
  {
    *buff_start=area_min+pattern_start;
    *img_start=0;
    cp_size=max_size-1;
  }
  if(*buff_start+cp_size>area_max)
  {
    *buff_end=area_max;
    cp_size-=area_max;
  }
  else
    *buff_end=*buff_start+cp_size;
}

// public functions
void img_patterns_init(unsigned short int ram_base_address)
{
  //initialize internal variables (read only variables)
  ram_data[ram_base_address+FRAME_BUFFER_CONTROL_IMG_MAX_WIDTH_OFFSET]=IMG_MAX_IMAGE_WIDTH;
  ram_data[ram_base_address+FRAME_BUFFER_CONTROL_IMG_MAX_HEIGHT_OFFSET]=IMG_MAX_IMAGE_HEIGHT;
  ram_data[ram_base_address+FRAME_BUFFER_CONTROL_IMG_NUM_IMGS_OFFSET]=IMG_MAX_NUM_IMAGES;
}

void img_general(TLEDArea *area,TIMGDisplayData *pattern_data,unsigned char buffer_id,unsigned short int period,TFBControl *control)
{
  unsigned short int buff_row=0,buff_col=0,img_row=0,img_col=0;
  unsigned short int buff_start_row=0,buff_end_row=0,buff_start_col=0,buff_end_col=0;
  unsigned char img_start_row=0,img_start_col=0;
  short int row_offset,col_offset;
  TWaveform *waveform;
  TMotion *motion;
  TPixelRGB pixel;

  // execute motion
  if(pattern_data->motion_index!=0xFF)
  {
    motion=(TMotion *)frame_buffer_control_get_parameters(control,pattern_data->motion_index);
    mtn_compute(motion);
    col_offset=motion->current_col;
    row_offset=motion->current_row;
  }
  else
  {
    col_offset=0;
    row_offset=0;
  }
  // compute displayed area
  img_patterns_compute_range(area->min_row,area->max_row,row_offset,IMG_MAX_IMAGE_HEIGHT,&buff_start_row,&buff_end_row,&img_start_row);
  img_patterns_compute_range(area->min_col,area->max_col,col_offset,IMG_MAX_IMAGE_WIDTH,&buff_start_col,&buff_end_col,&img_start_col);
  // execute waveform
  for(buff_row=buff_start_row,img_row=img_start_row;buff_row<=buff_end_row;buff_row++,img_row++)
    for(buff_col=buff_start_col,img_col=img_start_col;buff_col<=buff_end_col;buff_col++,img_col++)
    {
      if(pattern_data->waveform_index!=0xFF)
      {
        waveform=(TWaveform *)frame_buffer_control_get_parameters(control,pattern_data->waveform_index);
        waveform->max.R=img_pattern_data[pattern_data->buffer_id][img_row][img_col][0];
        waveform->max.G=img_pattern_data[pattern_data->buffer_id][img_row][img_col][1];
        waveform->max.B=img_pattern_data[pattern_data->buffer_id][img_row][img_col][2];
        pixel=wf_pixel(waveform);
      }
      else
      {
        pixel.R=img_pattern_data[pattern_data->buffer_id][img_row][img_col][0];
        pixel.G=img_pattern_data[pattern_data->buffer_id][img_row][img_col][1];
        pixel.B=img_pattern_data[pattern_data->buffer_id][img_row][img_col][2];
      }
      frame_buffer_set_pixel(&control->frame_buffer,buffer_id,pixel.R,pixel.G,pixel.B,buff_row,buff_col);
    }
}