1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include <asm/types.h>
25
26#include "pwc.h"
27#include "pwc-uncompress.h"
28
29
30
31static LIST_HEAD(pwc_decompressor_list);
32
33
34
35
36
37const int pwc_decompressor_version = PWC_MAJOR;
38
39
40void pwc_register_decompressor(struct pwc_decompressor *pwcd)
41{
42 if (pwc_find_decompressor(pwcd->type) == NULL) {
43 Trace(TRACE_PWCX, "Adding decompressor for model %d.\n", pwcd->type);
44 list_add_tail(&pwcd->pwcd_list, &pwc_decompressor_list);
45 }
46}
47
48
49void pwc_unregister_decompressor(int type)
50{
51 struct pwc_decompressor *find;
52
53 find = pwc_find_decompressor(type);
54 if (find != NULL) {
55 Trace(TRACE_PWCX, "Removing decompressor for model %d.\n", type);
56 list_del(&find->pwcd_list);
57 }
58}
59
60
61struct pwc_decompressor *pwc_find_decompressor(int type)
62{
63 struct list_head *tmp;
64 struct pwc_decompressor *pwcd;
65
66 list_for_each(tmp, &pwc_decompressor_list) {
67 pwcd = list_entry(tmp, struct pwc_decompressor, pwcd_list);
68 if (pwcd->type == type)
69 return pwcd;
70 }
71 return NULL;
72}
73
74
75
76int pwc_decompress(struct pwc_device *pdev)
77{
78 struct pwc_frame_buf *fbuf;
79 int n, line, col, stride;
80 void *yuv, *image;
81 u16 *src;
82 u16 *dsty, *dstu, *dstv;
83
84
85 if (pdev == NULL)
86 return -EFAULT;
87#if defined(__KERNEL__) && defined(PWC_MAGIC)
88 if (pdev->magic != PWC_MAGIC) {
89 Err("pwc_decompress(): magic failed.\n");
90 return -EFAULT;
91 }
92#endif
93
94 fbuf = pdev->read_frame;
95 if (fbuf == NULL)
96 return -EFAULT;
97 image = pdev->image_ptr[pdev->fill_image];
98 if (!image)
99 return -EFAULT;
100
101 yuv = fbuf->data + pdev->frame_header_size;
102 if (pdev->vbandlength == 0) {
103
104
105
106
107
108
109
110
111
112 src = (u16 *)yuv;
113 n = pdev->view.x * pdev->view.y;
114
115
116 stride = pdev->view.x * pdev->offset.y + pdev->offset.x;
117 dsty = (u16 *)(image + stride);
118
119
120 stride = pdev->view.x * pdev->offset.y / 4 + pdev->offset.x / 2;
121 dstu = (u16 *)(image + n + stride);
122 dstv = (u16 *)(image + n + n / 4 + stride);
123
124
125 stride = (pdev->view.x - pdev->image.x) / 2;
126
127 for (line = 0; line < pdev->image.y; line++) {
128 for (col = 0; col < pdev->image.x; col += 4) {
129 *dsty++ = *src++;
130 *dsty++ = *src++;
131 if (line & 1)
132 *dstv++ = *src++;
133 else
134 *dstu++ = *src++;
135 }
136 dsty += stride;
137 if (line & 1)
138 dstv += (stride >> 1);
139 else
140 dstu += (stride >> 1);
141 }
142 }
143 else {
144
145
146
147 if (pdev->decompressor)
148 pdev->decompressor->decompress(
149 &pdev->image, &pdev->view, &pdev->offset,
150 yuv, image,
151 1,
152 pdev->decompress_data, pdev->vbandlength);
153 else
154 return -ENXIO;
155 }
156 return 0;
157}
158
159
160
161
162
163EXPORT_SYMBOL_NOVERS(pwc_decompressor_version);
164EXPORT_SYMBOL(pwc_register_decompressor);
165EXPORT_SYMBOL(pwc_unregister_decompressor);
166