initial commit
[goodguy/history.git] / cinelerra-5.0 / quicktime / graphics.c
1 #include "graphics.h"
2
3 #include <string.h>
4 #include <stdlib.h>
5
6 /* Graphics acceleration routines */
7
8 void quicktime_init_yuv(quicktime_yuv_t *yuv_table)
9 {
10         int i;
11         for(i = 0; i < 256; i++)
12         {
13 /* compression */
14                 yuv_table->rtoy_tab[i] = (long)( 0.2990 * 65536 * i);
15                 yuv_table->rtou_tab[i] = (long)(-0.1687 * 65536 * i);
16                 yuv_table->rtov_tab[i] = (long)( 0.5000 * 65536 * i);
17
18                 yuv_table->gtoy_tab[i] = (long)( 0.5870 * 65536 * i);
19                 yuv_table->gtou_tab[i] = (long)(-0.3320 * 65536 * i);
20                 yuv_table->gtov_tab[i] = (long)(-0.4187 * 65536 * i);
21
22                 yuv_table->btoy_tab[i] = (long)( 0.1140 * 65536 * i);
23                 yuv_table->btou_tab[i] = (long)( 0.5000 * 65536 * i);
24                 yuv_table->btov_tab[i] = (long)(-0.0813 * 65536 * i);
25         }
26
27         yuv_table->vtor = &(yuv_table->vtor_tab[128]);
28         yuv_table->vtog = &(yuv_table->vtog_tab[128]);
29         yuv_table->utog = &(yuv_table->utog_tab[128]);
30         yuv_table->utob = &(yuv_table->utob_tab[128]);
31         for(i = -128; i < 128; i++)
32         {
33 /* decompression */
34                 yuv_table->vtor[i] = (long)( 1.4020 * 65536 * i);
35                 yuv_table->vtog[i] = (long)(-0.7141 * 65536 * i);
36
37                 yuv_table->utog[i] = (long)(-0.3441 * 65536 * i);
38                 yuv_table->utob[i] = (long)( 1.7720 * 65536 * i);
39         }
40 }
41
42 void quicktime_delete_yuv(quicktime_yuv_t *yuv_table)
43 {
44 }
45
46
47 quicktime_scaletable_t* quicktime_new_scaletable(int input_w, int input_h, int output_w, int output_h)
48 {
49         quicktime_scaletable_t *result = (quicktime_scaletable_t*)malloc(sizeof(quicktime_scaletable_t));
50         float i;
51         float scalex = (float)input_w / output_w, scaley = (float)input_h / output_h;
52
53         result->input_x = (int*)malloc(sizeof(int) * output_w);
54         result->input_y = (int*)malloc(sizeof(int) * output_h);
55
56         for(i = 0; i < output_w; i++)
57         {
58                 result->input_x[(int)i] = (int)(scalex * i);
59         }
60
61         for(i = 0; i < output_h; i++)
62         {
63                 result->input_y[(int)i] = (int)(scaley * i);
64         }
65
66         result->in_w = input_w;
67         result->in_h = input_h;
68         result->out_w = output_w;
69         result->out_h = output_h;
70         return result;
71 }
72
73 void quicktime_delete_scaletable(quicktime_scaletable_t *scaletable)
74 {
75         free(scaletable->input_x);
76         free(scaletable->input_y);
77         free(scaletable);
78 }
79
80 /* Return 1 if dimensions are different from scaletable */
81 int quicktime_compare_scaletable(quicktime_scaletable_t *scaletable, 
82         int in_w, 
83         int in_h, 
84         int out_w, 
85         int out_h)
86 {
87         if(scaletable->in_w != in_w ||
88                 scaletable->in_h != in_h ||
89                 scaletable->out_w != out_w ||
90                 scaletable->out_h != out_h)
91                 return 1;
92         else
93                 return 0;
94 }
95
96 /* Return 1 if the scaletable is 1:1 */
97 int quicktime_identity_scaletable(quicktime_scaletable_t *scaletable)
98 {
99         if(scaletable->in_w == scaletable->out_w &&
100                 scaletable->in_h == scaletable->out_h)
101                 return 1;
102         else
103                 return 0;
104 }