Frame Buffer analysis-fbcmap. c

Source: Internet
Author: User

91 int fb_alloc_cmap (struct fb_cmap * cmap, int Len, int Transp)
92 {
93 int size = Len * sizeof (2010 );
94
95 If (cmap-> Len! = Len ){
96 fb_dealloc_cmap (cmap );
97 If (! Len)
98 return 0;
99 If (! (Cmap-> Red = kmalloc (size, gfp_atomic )))
100 goto failure;
101 if (! (Cmap-> Green = kmalloc (size, gfp_atomic )))
102 goto failure;
103 If (! (Cmap-> Blue = kmalloc (size, gfp_atomic )))
104 goto failure;
105 if (Transp ){
106 If (! (Cmap-> Transp = kmalloc (size, gfp_atomic )))
107 goto failure;
108} else
109 cmap-> Transp = NULL;
110}
111 cmap-> Start = 0;
112 cmap-> Len = Len;
113 fb_copy_cmap (fb_default_cmap (LEN), cmap );
114 return 0;
115
116 fail:
117 fb_dealloc_cmap (cmap );
118 return-enomem;
119}

Assign a colormap. Len is the number of the color component.

113 use the default colormap to initialize the color component

149 int fb_copy_cmap (const struct fb_cmap * From, struct fb_cmap *)
150 {
151 int tooff = 0, fromoff = 0;
152 int size;
153
154 If (to-> Start> from-> start)
155 fromoff = to-> Start-from-> start;
156 else
157 tooff = from-> start-to-> start;
158 size = to-> len-tooff;
159 If (size> (INT) (from-> len-fromoff ))
160 size = from-> len-fromoff;
161 If (size <= 0)
162 return-einval;
163 size * = sizeof (2010 );
164
165 memcpy (to-> Red + tooff, from-> Red + fromoff, size );
166 memcpy (to-> green + tooff, from-> green + fromoff, size );
167 memcpy (to-> blue + tooff, from-> blue + fromoff, size );
168 If (from-> Transp & to-> Transp)
169 memcpy (to-> Transp + tooff, from-> Transp + fromoff, size );
170 return 0;
171}
Copy colormap @ from to @

249 int fb_set_user_cmap (struct fb_cmap_user * cmap, struct fb_info * info)
250 {
251 int RC, size = cmap-> Len * sizeof );
252 struct fb_cmap umap;
253
254 memset (& umap, 0, sizeof (struct fb_cmap ));
255 rc = fb_alloc_cmap (& umap, cmap-> Len, cmap-> Transp! = NULL );
256 If (RC)
257 return RC;
258 If (copy_from_user (umap. Red, cmap-> Red, size) |
259 copy_from_user (umap. Green, cmap-> green, size) |
260 copy_from_user (umap. Blue, cmap-> blue, size) |
261 (cmap-> Transp & copy_from_user (umap. transp, cmap-> transp, size ))){
262 rc =-efault;
263 goto out;
264}
265 umap. Start = cmap-> start;
266 If (! Lock_fb_info (Info )){
267 rc =-enodev;
268 goto out;
269}
270 if (cmap-> Start <0 | (! Info-> fbops-> fb_setcolreg &&
271! Info-> fbops-> fb_setcmap )){
272 rc =-einval;
273 goto out1;
274}
275 rc = fb_set_cmap (& umap, Info );
276 out1:
277 unlock_fb_info (Info );
278 out:
279 fb_dealloc_cmap (& umap );
280 return RC;
281}
Copy the fb_cmap_user-type cmap content to fb_cmap, and then call fb_set_cmap.

294 const struct fb_cmap * fb_default_cmap (INT Len)
295 {
296 if (LEN <= 2)
297 return & defa_2_2_colors;
298 if (LEN <= 4)
299 return & default_4_colors;
300 if (LEN <= 8)
301 return & default_8_colors;
302 return & default_16_colors;
303}

Return the default cmap according to Len

313 void fb_invert_cmaps (void)
314 {
315 u_int I;
316
317 for (I = 0; I <array_size (red2); I ++ ){
318 red2 [I] = ~ Red2 [I];
319 green2 [I] = ~ Green2 [I];
320 blue2 [I] = ~ Blue2 [I];
321}
322 for (I = 0; I <array_size (red4); I ++ ){
323 red4 [I] = ~ Red4 [I];
324 green4 [I] = ~ Green4 [I];
325 blue4 [I] = ~ Blue4 [I];
326}
327 for (I = 0; I <array_size (red8); I ++ ){
328 red8 [I] = ~ Red8 [I];
329 green8 [I] = ~ Green8 [I];
330 blue8 [I] = ~ Blue8 [I];
331}
332 for (I = 0; I <array_size (red16); I ++ ){
333 red16 [I] = ~ Red16 [I];
334 green16 [I] = ~ Green16 [I];
335 blue16 [I] = ~ Blue16 [I];
336}
337}
Color components of invert cmap

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.