Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'fbdev-for-6.3-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/deller/linux-fbdev

Pull fbdev fixes from Helge Deller:
"The majority of lines changed is due to a code style cleanup in the
pnmtologo helper program.

Arnd removed the omap1 osk driver and the SIS fb driver is now
orphaned.

Other than that it's the usual bunch of small fixes and cleanups, e.g.
prevent possible divide-by-zero in various fb drivers if the pixclock
is zero and various conversions to devm_platform*() and of_property*()
functions:

- Drop omap1 osk driver

- Various potential divide by zero pixclock fixes

- Add pixelclock and fb_check_var() to stifb

- Code style cleanups and indenting fixes"

* tag 'fbdev-for-6.3-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/deller/linux-fbdev:
fbdev: Use of_property_present() for testing DT property presence
fbdev: au1200fb: Fix potential divide by zero
fbdev: lxfb: Fix potential divide by zero
fbdev: intelfb: Fix potential divide by zero
fbdev: nvidia: Fix potential divide by zero
fbdev: stifb: Provide valid pixelclock and add fb_check_var() checks
fbdev: omapfb: remove omap1 osk driver
fbdev: xilinxfb: Use devm_platform_get_and_ioremap_resource()
fbdev: wm8505fb: Use devm_platform_ioremap_resource()
fbdev: pxa3xx-gcu: Use devm_platform_get_and_ioremap_resource()
fbdev: Use of_property_read_bool() for boolean properties
fbdev: clps711x-fb: Use devm_platform_get_and_ioremap_resource()
fbdev: tgafb: Fix potential divide by zero
MAINTAINERS: orphan SIS FRAMEBUFFER DRIVER
fbdev: omapfb: cleanup inconsistent indentation
drivers: video: logo: add SPDX comment, remove GPL notice in pnmtologo.c
drivers: video: logo: fix code style issues in pnmtologo.c

+398 -451
+1 -3
MAINTAINERS
··· 19150 19150 F: drivers/net/ethernet/sis/sis900.* 19151 19151 19152 19152 SIS FRAMEBUFFER DRIVER 19153 - M: Thomas Winischhofer <thomas@winischhofer.net> 19154 - S: Maintained 19155 - W: http://www.winischhofer.net/linuxsisvga.shtml 19153 + S: Orphan 19156 19154 F: Documentation/fb/sisfb.rst 19157 19155 F: drivers/video/fbdev/sis/ 19158 19156 F: include/video/sisfb.h
+1 -1
drivers/video/fbdev/amba-clcd.c
··· 854 854 board->caps = CLCD_CAP_ALL; 855 855 board->check = clcdfb_check; 856 856 board->decode = clcdfb_decode; 857 - if (of_find_property(node, "memory-region", NULL)) { 857 + if (of_property_present(node, "memory-region")) { 858 858 board->setup = clcdfb_of_vram_setup; 859 859 board->mmap = clcdfb_of_vram_mmap; 860 860 board->remove = clcdfb_of_vram_remove;
+3
drivers/video/fbdev/au1200fb.c
··· 1040 1040 u32 pixclock; 1041 1041 int screen_size, plane; 1042 1042 1043 + if (!var->pixclock) 1044 + return -EINVAL; 1045 + 1043 1046 plane = fbdev->plane; 1044 1047 1045 1048 /* Make sure that the mode respect all LCD controller and
+1 -1
drivers/video/fbdev/bw2.c
··· 306 306 if (!par->regs) 307 307 goto out_release_fb; 308 308 309 - if (!of_find_property(dp, "width", NULL)) { 309 + if (!of_property_present(dp, "width")) { 310 310 err = bw2_do_default_mode(par, info, &linebytes); 311 311 if (err) 312 312 goto out_unmap_regs;
+1 -1
drivers/video/fbdev/cg3.c
··· 393 393 394 394 cg3_blank(FB_BLANK_UNBLANK, info); 395 395 396 - if (!of_find_property(dp, "width", NULL)) { 396 + if (!of_property_present(dp, "width")) { 397 397 err = cg3_do_default_mode(par); 398 398 if (err) 399 399 goto out_unmap_screen;
+1 -2
drivers/video/fbdev/clps711x-fb.c
··· 238 238 info->fix.mmio_start = res->start; 239 239 info->fix.mmio_len = resource_size(res); 240 240 241 - res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 242 - info->screen_base = devm_ioremap_resource(dev, res); 241 + info->screen_base = devm_platform_get_and_ioremap_resource(pdev, 1, &res); 243 242 if (IS_ERR(info->screen_base)) { 244 243 ret = PTR_ERR(info->screen_base); 245 244 goto out_fb_release;
+3
drivers/video/fbdev/geode/lxfb_core.c
··· 235 235 236 236 static int lxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info) 237 237 { 238 + if (!var->pixclock) 239 + return -EINVAL; 240 + 238 241 if (var->xres > 1920 || var->yres > 1440) 239 242 return -EINVAL; 240 243
+3
drivers/video/fbdev/intelfb/intelfbdrv.c
··· 1222 1222 1223 1223 dinfo = GET_DINFO(info); 1224 1224 1225 + if (!var->pixclock) 1226 + return -EINVAL; 1227 + 1225 1228 /* update the pitch */ 1226 1229 if (intelfbhw_validate_mode(dinfo, var) != 0) 1227 1230 return -EINVAL;
+2
drivers/video/fbdev/nvidia/nvidia.c
··· 764 764 int pitch, err = 0; 765 765 766 766 NVTRACE_ENTER(); 767 + if (!var->pixclock) 768 + return -EINVAL; 767 769 768 770 var->transp.offset = 0; 769 771 var->transp.length = 0;
+2 -2
drivers/video/fbdev/offb.c
··· 549 549 int foreign_endian = 0; 550 550 551 551 #ifdef __BIG_ENDIAN 552 - if (of_get_property(dp, "little-endian", NULL)) 552 + if (of_property_read_bool(dp, "little-endian")) 553 553 foreign_endian = FBINFO_FOREIGN_ENDIAN; 554 554 #else 555 - if (of_get_property(dp, "big-endian", NULL)) 555 + if (of_property_read_bool(dp, "big-endian")) 556 556 foreign_endian = FBINFO_FOREIGN_ENDIAN; 557 557 #endif 558 558
-1
drivers/video/fbdev/omap/Makefile
··· 18 18 19 19 lcds-y$(CONFIG_MACH_AMS_DELTA) += lcd_ams_delta.o 20 20 lcds-y$(CONFIG_MACH_OMAP_PALMTE) += lcd_palmte.o 21 - lcds-y$(CONFIG_MACH_OMAP_OSK) += lcd_osk.o 22 21 23 22 lcds-y$(CONFIG_FB_OMAP_LCD_MIPID) += lcd_mipid.o 24 23
-86
drivers/video/fbdev/omap/lcd_osk.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-or-later 2 - /* 3 - * LCD panel support for the TI OMAP OSK board 4 - * 5 - * Copyright (C) 2004 Nokia Corporation 6 - * Author: Imre Deak <imre.deak@nokia.com> 7 - * Adapted for OSK by <dirk.behme@de.bosch.com> 8 - */ 9 - 10 - #include <linux/module.h> 11 - #include <linux/platform_device.h> 12 - #include <linux/gpio.h> 13 - 14 - #include <linux/soc/ti/omap1-io.h> 15 - #include <linux/soc/ti/omap1-mux.h> 16 - 17 - #include "omapfb.h" 18 - 19 - static int osk_panel_enable(struct lcd_panel *panel) 20 - { 21 - /* configure PWL pin */ 22 - omap_cfg_reg(PWL); 23 - 24 - /* Enable PWL unit */ 25 - omap_writeb(0x01, OMAP_PWL_CLK_ENABLE); 26 - 27 - /* Set PWL level */ 28 - omap_writeb(0xFF, OMAP_PWL_ENABLE); 29 - 30 - /* set GPIO2 high (lcd power enabled) */ 31 - gpio_set_value(2, 1); 32 - 33 - return 0; 34 - } 35 - 36 - static void osk_panel_disable(struct lcd_panel *panel) 37 - { 38 - /* Set PWL level to zero */ 39 - omap_writeb(0x00, OMAP_PWL_ENABLE); 40 - 41 - /* Disable PWL unit */ 42 - omap_writeb(0x00, OMAP_PWL_CLK_ENABLE); 43 - 44 - /* set GPIO2 low */ 45 - gpio_set_value(2, 0); 46 - } 47 - 48 - static struct lcd_panel osk_panel = { 49 - .name = "osk", 50 - .config = OMAP_LCDC_PANEL_TFT, 51 - 52 - .bpp = 16, 53 - .data_lines = 16, 54 - .x_res = 240, 55 - .y_res = 320, 56 - .pixel_clock = 12500, 57 - .hsw = 40, 58 - .hfp = 40, 59 - .hbp = 72, 60 - .vsw = 1, 61 - .vfp = 1, 62 - .vbp = 0, 63 - .pcd = 12, 64 - 65 - .enable = osk_panel_enable, 66 - .disable = osk_panel_disable, 67 - }; 68 - 69 - static int osk_panel_probe(struct platform_device *pdev) 70 - { 71 - omapfb_register_panel(&osk_panel); 72 - return 0; 73 - } 74 - 75 - static struct platform_driver osk_panel_driver = { 76 - .probe = osk_panel_probe, 77 - .driver = { 78 - .name = "lcd_osk", 79 - }, 80 - }; 81 - 82 - module_platform_driver(osk_panel_driver); 83 - 84 - MODULE_AUTHOR("Imre Deak"); 85 - MODULE_DESCRIPTION("LCD panel support for the TI OMAP OSK board"); 86 - MODULE_LICENSE("GPL");
+18 -12
drivers/video/fbdev/omap/omapfb_main.c
··· 544 544 var->yoffset = var->yres_virtual - var->yres; 545 545 546 546 if (plane->color_mode == OMAPFB_COLOR_RGB444) { 547 - var->red.offset = 8; var->red.length = 4; 548 - var->red.msb_right = 0; 549 - var->green.offset = 4; var->green.length = 4; 550 - var->green.msb_right = 0; 551 - var->blue.offset = 0; var->blue.length = 4; 552 - var->blue.msb_right = 0; 547 + var->red.offset = 8; 548 + var->red.length = 4; 549 + var->red.msb_right = 0; 550 + var->green.offset = 4; 551 + var->green.length = 4; 552 + var->green.msb_right = 0; 553 + var->blue.offset = 0; 554 + var->blue.length = 4; 555 + var->blue.msb_right = 0; 553 556 } else { 554 - var->red.offset = 11; var->red.length = 5; 555 - var->red.msb_right = 0; 556 - var->green.offset = 5; var->green.length = 6; 557 - var->green.msb_right = 0; 558 - var->blue.offset = 0; var->blue.length = 5; 559 - var->blue.msb_right = 0; 557 + var->red.offset = 11; 558 + var->red.length = 5; 559 + var->red.msb_right = 0; 560 + var->green.offset = 5; 561 + var->green.length = 6; 562 + var->green.msb_right = 0; 563 + var->blue.offset = 0; 564 + var->blue.length = 5; 565 + var->blue.msb_right = 0; 560 566 } 561 567 562 568 var->height = -1;
+1 -1
drivers/video/fbdev/omap2/omapfb/dss/omapdss-boot-init.c
··· 192 192 omapdss_walk_device(dss, true); 193 193 194 194 for_each_available_child_of_node(dss, child) { 195 - if (!of_find_property(child, "compatible", NULL)) 195 + if (!of_property_present(child, "compatible")) 196 196 continue; 197 197 198 198 omapdss_walk_device(child, true);
+1 -2
drivers/video/fbdev/pxa3xx-gcu.c
··· 599 599 priv->misc_dev.fops = &pxa3xx_gcu_miscdev_fops; 600 600 601 601 /* handle IO resources */ 602 - r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 603 - priv->mmio_base = devm_ioremap_resource(dev, r); 602 + priv->mmio_base = devm_platform_get_and_ioremap_resource(pdev, 0, &r); 604 603 if (IS_ERR(priv->mmio_base)) 605 604 return PTR_ERR(priv->mmio_base); 606 605
+2 -2
drivers/video/fbdev/sm501fb.c
··· 1737 1737 1738 1738 #if defined(CONFIG_OF) 1739 1739 #ifdef __BIG_ENDIAN 1740 - if (of_get_property(info->dev->parent->of_node, "little-endian", NULL)) 1740 + if (of_property_read_bool(info->dev->parent->of_node, "little-endian")) 1741 1741 fb->flags |= FBINFO_FOREIGN_ENDIAN; 1742 1742 #else 1743 - if (of_get_property(info->dev->parent->of_node, "big-endian", NULL)) 1743 + if (of_property_read_bool(info->dev->parent->of_node, "big-endian")) 1744 1744 fb->flags |= FBINFO_FOREIGN_ENDIAN; 1745 1745 #endif 1746 1746 #endif
+27
drivers/video/fbdev/stifb.c
··· 922 922 /* ------------------- driver specific functions --------------------------- */ 923 923 924 924 static int 925 + stifb_check_var(struct fb_var_screeninfo *var, struct fb_info *info) 926 + { 927 + struct stifb_info *fb = container_of(info, struct stifb_info, info); 928 + 929 + if (var->xres != fb->info.var.xres || 930 + var->yres != fb->info.var.yres || 931 + var->bits_per_pixel != fb->info.var.bits_per_pixel) 932 + return -EINVAL; 933 + 934 + var->xres_virtual = var->xres; 935 + var->yres_virtual = var->yres; 936 + var->xoffset = 0; 937 + var->yoffset = 0; 938 + var->grayscale = fb->info.var.grayscale; 939 + var->red.length = fb->info.var.red.length; 940 + var->green.length = fb->info.var.green.length; 941 + var->blue.length = fb->info.var.blue.length; 942 + 943 + return 0; 944 + } 945 + 946 + static int 925 947 stifb_setcolreg(u_int regno, u_int red, u_int green, 926 948 u_int blue, u_int transp, struct fb_info *info) 927 949 { ··· 1167 1145 1168 1146 static const struct fb_ops stifb_ops = { 1169 1147 .owner = THIS_MODULE, 1148 + .fb_check_var = stifb_check_var, 1170 1149 .fb_setcolreg = stifb_setcolreg, 1171 1150 .fb_blank = stifb_blank, 1172 1151 .fb_fillrect = stifb_fillrect, ··· 1187 1164 struct stifb_info *fb; 1188 1165 struct fb_info *info; 1189 1166 unsigned long sti_rom_address; 1167 + char modestr[32]; 1190 1168 char *dev_name; 1191 1169 int bpp, xres, yres; 1192 1170 ··· 1365 1341 info->screen_size = fix->smem_len; 1366 1342 info->flags = FBINFO_HWACCEL_COPYAREA | FBINFO_HWACCEL_FILLRECT; 1367 1343 info->pseudo_palette = &fb->pseudo_palette; 1344 + 1345 + scnprintf(modestr, sizeof(modestr), "%dx%d-%d", xres, yres, bpp); 1346 + fb_find_mode(&info->var, info, modestr, NULL, 0, NULL, bpp); 1368 1347 1369 1348 /* This has to be done !!! */ 1370 1349 if (fb_alloc_cmap(&info->cmap, NR_PALETTE, 0))
+1 -2
drivers/video/fbdev/tcx.c
··· 379 379 380 380 spin_lock_init(&par->lock); 381 381 382 - par->lowdepth = 383 - (of_find_property(dp, "tcx-8-bit", NULL) != NULL); 382 + par->lowdepth = of_property_read_bool(dp, "tcx-8-bit"); 384 383 385 384 sbusfb_fill_var(&info->var, dp, 8); 386 385 info->var.red.length = 8;
+3
drivers/video/fbdev/tgafb.c
··· 173 173 { 174 174 struct tga_par *par = (struct tga_par *)info->par; 175 175 176 + if (!var->pixclock) 177 + return -EINVAL; 178 + 176 179 if (par->tga_type == TGA_TYPE_8PLANE) { 177 180 if (var->bits_per_pixel != 8) 178 181 return -EINVAL;
+1 -3
drivers/video/fbdev/wm8505fb.c
··· 261 261 static int wm8505fb_probe(struct platform_device *pdev) 262 262 { 263 263 struct wm8505fb_info *fbi; 264 - struct resource *res; 265 264 struct display_timings *disp_timing; 266 265 void *addr; 267 266 int ret; ··· 298 299 addr = addr + sizeof(struct wm8505fb_info); 299 300 fbi->fb.pseudo_palette = addr; 300 301 301 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 302 - fbi->regbase = devm_ioremap_resource(&pdev->dev, res); 302 + fbi->regbase = devm_platform_ioremap_resource(pdev, 0); 303 303 if (IS_ERR(fbi->regbase)) 304 304 return PTR_ERR(fbi->regbase); 305 305
+2 -4
drivers/video/fbdev/xilinxfb.c
··· 273 273 if (drvdata->flags & BUS_ACCESS_FLAG) { 274 274 struct resource *res; 275 275 276 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 277 - drvdata->regs = devm_ioremap_resource(&pdev->dev, res); 276 + drvdata->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res); 278 277 if (IS_ERR(drvdata->regs)) 279 278 return PTR_ERR(drvdata->regs); 280 279 ··· 468 469 pdata.yvirt = prop[1]; 469 470 } 470 471 471 - if (of_find_property(pdev->dev.of_node, "rotate-display", NULL)) 472 - pdata.rotate_screen = 1; 472 + pdata.rotate_screen = of_property_read_bool(pdev->dev.of_node, "rotate-display"); 473 473 474 474 platform_set_drvdata(pdev, drvdata); 475 475 return xilinxfb_assign(pdev, drvdata, &pdata);
+324 -328
drivers/video/logo/pnmtologo.c
··· 1 - 1 + // SPDX-License-Identifier: GPL-2.0-only 2 2 /* 3 3 * Convert a logo in ASCII PNM format to C source suitable for inclusion in 4 4 * the Linux kernel 5 5 * 6 6 * (C) Copyright 2001-2003 by Geert Uytterhoeven <geert@linux-m68k.org> 7 - * 8 - * -------------------------------------------------------------------------- 9 - * 10 - * This file is subject to the terms and conditions of the GNU General Public 11 - * License. See the file COPYING in the main directory of the Linux 12 - * distribution for more details. 13 7 */ 14 8 15 9 #include <ctype.h> ··· 28 34 #define LINUX_LOGO_GRAY256 4 /* 256 levels grayscale */ 29 35 30 36 static const char *logo_types[LINUX_LOGO_GRAY256+1] = { 31 - [LINUX_LOGO_MONO] = "LINUX_LOGO_MONO", 32 - [LINUX_LOGO_VGA16] = "LINUX_LOGO_VGA16", 33 - [LINUX_LOGO_CLUT224] = "LINUX_LOGO_CLUT224", 34 - [LINUX_LOGO_GRAY256] = "LINUX_LOGO_GRAY256" 37 + [LINUX_LOGO_MONO] = "LINUX_LOGO_MONO", 38 + [LINUX_LOGO_VGA16] = "LINUX_LOGO_VGA16", 39 + [LINUX_LOGO_CLUT224] = "LINUX_LOGO_CLUT224", 40 + [LINUX_LOGO_GRAY256] = "LINUX_LOGO_GRAY256" 35 41 }; 36 42 37 43 #define MAX_LINUX_LOGO_COLORS 224 38 44 39 45 struct color { 40 - unsigned char red; 41 - unsigned char green; 42 - unsigned char blue; 46 + unsigned char red; 47 + unsigned char green; 48 + unsigned char blue; 43 49 }; 44 50 45 51 static const struct color clut_vga16[16] = { 46 - { 0x00, 0x00, 0x00 }, 47 - { 0x00, 0x00, 0xaa }, 48 - { 0x00, 0xaa, 0x00 }, 49 - { 0x00, 0xaa, 0xaa }, 50 - { 0xaa, 0x00, 0x00 }, 51 - { 0xaa, 0x00, 0xaa }, 52 - { 0xaa, 0x55, 0x00 }, 53 - { 0xaa, 0xaa, 0xaa }, 54 - { 0x55, 0x55, 0x55 }, 55 - { 0x55, 0x55, 0xff }, 56 - { 0x55, 0xff, 0x55 }, 57 - { 0x55, 0xff, 0xff }, 58 - { 0xff, 0x55, 0x55 }, 59 - { 0xff, 0x55, 0xff }, 60 - { 0xff, 0xff, 0x55 }, 61 - { 0xff, 0xff, 0xff }, 52 + { 0x00, 0x00, 0x00 }, 53 + { 0x00, 0x00, 0xaa }, 54 + { 0x00, 0xaa, 0x00 }, 55 + { 0x00, 0xaa, 0xaa }, 56 + { 0xaa, 0x00, 0x00 }, 57 + { 0xaa, 0x00, 0xaa }, 58 + { 0xaa, 0x55, 0x00 }, 59 + { 0xaa, 0xaa, 0xaa }, 60 + { 0x55, 0x55, 0x55 }, 61 + { 0x55, 0x55, 0xff }, 62 + { 0x55, 0xff, 0x55 }, 63 + { 0x55, 0xff, 0xff }, 64 + { 0xff, 0x55, 0x55 }, 65 + { 0xff, 0x55, 0xff }, 66 + { 0xff, 0xff, 0x55 }, 67 + { 0xff, 0xff, 0xff }, 62 68 }; 63 69 64 70 ··· 71 77 static int is_plain_pbm = 0; 72 78 73 79 static void die(const char *fmt, ...) 74 - __attribute__ ((noreturn)) __attribute ((format (printf, 1, 2))); 75 - static void usage(void) __attribute ((noreturn)); 80 + __attribute__((noreturn)) __attribute((format (printf, 1, 2))); 81 + static void usage(void) __attribute((noreturn)); 76 82 77 83 78 84 static unsigned int get_number(FILE *fp) 79 85 { 80 - int c, val; 86 + int c, val; 81 87 82 - /* Skip leading whitespace */ 83 - do { 84 - c = fgetc(fp); 85 - if (c == EOF) 86 - die("%s: end of file\n", filename); 87 - if (c == '#') { 88 - /* Ignore comments 'till end of line */ 89 - do { 88 + /* Skip leading whitespace */ 89 + do { 90 90 c = fgetc(fp); 91 91 if (c == EOF) 92 - die("%s: end of file\n", filename); 93 - } while (c != '\n'); 94 - } 95 - } while (isspace(c)); 92 + die("%s: end of file\n", filename); 93 + if (c == '#') { 94 + /* Ignore comments 'till end of line */ 95 + do { 96 + c = fgetc(fp); 97 + if (c == EOF) 98 + die("%s: end of file\n", filename); 99 + } while (c != '\n'); 100 + } 101 + } while (isspace(c)); 96 102 97 - /* Parse decimal number */ 98 - val = 0; 99 - while (isdigit(c)) { 100 - val = 10*val+c-'0'; 101 - /* some PBM are 'broken'; GiMP for example exports a PBM without space 102 - * between the digits. This is Ok cause we know a PBM can only have a '1' 103 - * or a '0' for the digit. */ 104 - if (is_plain_pbm) 105 - break; 106 - c = fgetc(fp); 107 - if (c == EOF) 108 - die("%s: end of file\n", filename); 109 - } 110 - return val; 103 + /* Parse decimal number */ 104 + val = 0; 105 + while (isdigit(c)) { 106 + val = 10*val+c-'0'; 107 + /* some PBM are 'broken'; GiMP for example exports a PBM without space 108 + * between the digits. This is Ok cause we know a PBM can only have a '1' 109 + * or a '0' for the digit. 110 + */ 111 + if (is_plain_pbm) 112 + break; 113 + c = fgetc(fp); 114 + if (c == EOF) 115 + die("%s: end of file\n", filename); 116 + } 117 + return val; 111 118 } 112 119 113 120 static unsigned int get_number255(FILE *fp, unsigned int maxval) 114 121 { 115 - unsigned int val = get_number(fp); 116 - return (255*val+maxval/2)/maxval; 122 + unsigned int val = get_number(fp); 123 + 124 + return (255*val+maxval/2)/maxval; 117 125 } 118 126 119 127 static void read_image(void) 120 128 { 121 - FILE *fp; 122 - unsigned int i, j; 123 - int magic; 124 - unsigned int maxval; 129 + FILE *fp; 130 + unsigned int i, j; 131 + int magic; 132 + unsigned int maxval; 125 133 126 - /* open image file */ 127 - fp = fopen(filename, "r"); 128 - if (!fp) 129 - die("Cannot open file %s: %s\n", filename, strerror(errno)); 134 + /* open image file */ 135 + fp = fopen(filename, "r"); 136 + if (!fp) 137 + die("Cannot open file %s: %s\n", filename, strerror(errno)); 130 138 131 - /* check file type and read file header */ 132 - magic = fgetc(fp); 133 - if (magic != 'P') 134 - die("%s is not a PNM file\n", filename); 135 - magic = fgetc(fp); 136 - switch (magic) { 139 + /* check file type and read file header */ 140 + magic = fgetc(fp); 141 + if (magic != 'P') 142 + die("%s is not a PNM file\n", filename); 143 + magic = fgetc(fp); 144 + switch (magic) { 137 145 case '1': 138 146 case '2': 139 147 case '3': 140 - /* Plain PBM/PGM/PPM */ 141 - break; 148 + /* Plain PBM/PGM/PPM */ 149 + break; 142 150 143 151 case '4': 144 152 case '5': 145 153 case '6': 146 - /* Binary PBM/PGM/PPM */ 147 - die("%s: Binary PNM is not supported\n" 154 + /* Binary PBM/PGM/PPM */ 155 + die("%s: Binary PNM is not supported\n" 148 156 "Use pnmnoraw(1) to convert it to ASCII PNM\n", filename); 149 157 150 158 default: 151 - die("%s is not a PNM file\n", filename); 152 - } 153 - logo_width = get_number(fp); 154 - logo_height = get_number(fp); 159 + die("%s is not a PNM file\n", filename); 160 + } 161 + logo_width = get_number(fp); 162 + logo_height = get_number(fp); 155 163 156 - /* allocate image data */ 157 - logo_data = (struct color **)malloc(logo_height*sizeof(struct color *)); 158 - if (!logo_data) 159 - die("%s\n", strerror(errno)); 160 - for (i = 0; i < logo_height; i++) { 161 - logo_data[i] = malloc(logo_width*sizeof(struct color)); 164 + /* allocate image data */ 165 + logo_data = (struct color **)malloc(logo_height*sizeof(struct color *)); 166 + if (!logo_data) 167 + die("%s\n", strerror(errno)); 168 + for (i = 0; i < logo_height; i++) { 169 + logo_data[i] = malloc(logo_width*sizeof(struct color)); 162 170 if (!logo_data[i]) 163 - die("%s\n", strerror(errno)); 164 - } 171 + die("%s\n", strerror(errno)); 172 + } 165 173 166 - /* read image data */ 167 - switch (magic) { 174 + /* read image data */ 175 + switch (magic) { 168 176 case '1': 169 - /* Plain PBM */ 170 - is_plain_pbm = 1; 171 - for (i = 0; i < logo_height; i++) 172 - for (j = 0; j < logo_width; j++) 173 - logo_data[i][j].red = logo_data[i][j].green = 174 - logo_data[i][j].blue = 255*(1-get_number(fp)); 175 - break; 177 + /* Plain PBM */ 178 + is_plain_pbm = 1; 179 + for (i = 0; i < logo_height; i++) 180 + for (j = 0; j < logo_width; j++) 181 + logo_data[i][j].red = logo_data[i][j].green = 182 + logo_data[i][j].blue = 255*(1-get_number(fp)); 183 + break; 176 184 177 185 case '2': 178 - /* Plain PGM */ 179 - maxval = get_number(fp); 180 - for (i = 0; i < logo_height; i++) 181 - for (j = 0; j < logo_width; j++) 182 - logo_data[i][j].red = logo_data[i][j].green = 183 - logo_data[i][j].blue = get_number255(fp, maxval); 184 - break; 186 + /* Plain PGM */ 187 + maxval = get_number(fp); 188 + for (i = 0; i < logo_height; i++) 189 + for (j = 0; j < logo_width; j++) 190 + logo_data[i][j].red = logo_data[i][j].green = 191 + logo_data[i][j].blue = get_number255(fp, maxval); 192 + break; 185 193 186 194 case '3': 187 - /* Plain PPM */ 188 - maxval = get_number(fp); 189 - for (i = 0; i < logo_height; i++) 190 - for (j = 0; j < logo_width; j++) { 191 - logo_data[i][j].red = get_number255(fp, maxval); 192 - logo_data[i][j].green = get_number255(fp, maxval); 193 - logo_data[i][j].blue = get_number255(fp, maxval); 194 - } 195 - break; 196 - } 195 + /* Plain PPM */ 196 + maxval = get_number(fp); 197 + for (i = 0; i < logo_height; i++) 198 + for (j = 0; j < logo_width; j++) { 199 + logo_data[i][j].red = get_number255(fp, maxval); 200 + logo_data[i][j].green = get_number255(fp, maxval); 201 + logo_data[i][j].blue = get_number255(fp, maxval); 202 + } 203 + break; 204 + } 197 205 198 - /* close file */ 199 - fclose(fp); 206 + /* close file */ 207 + fclose(fp); 200 208 } 201 209 202 210 static inline int is_black(struct color c) 203 211 { 204 - return c.red == 0 && c.green == 0 && c.blue == 0; 212 + return c.red == 0 && c.green == 0 && c.blue == 0; 205 213 } 206 214 207 215 static inline int is_white(struct color c) 208 216 { 209 - return c.red == 255 && c.green == 255 && c.blue == 255; 217 + return c.red == 255 && c.green == 255 && c.blue == 255; 210 218 } 211 219 212 220 static inline int is_gray(struct color c) 213 221 { 214 - return c.red == c.green && c.red == c.blue; 222 + return c.red == c.green && c.red == c.blue; 215 223 } 216 224 217 225 static inline int is_equal(struct color c1, struct color c2) 218 226 { 219 - return c1.red == c2.red && c1.green == c2.green && c1.blue == c2.blue; 227 + return c1.red == c2.red && c1.green == c2.green && c1.blue == c2.blue; 220 228 } 221 229 222 230 static void write_header(void) 223 231 { 224 - /* open logo file */ 225 - if (outputname) { 226 - out = fopen(outputname, "w"); 227 - if (!out) 228 - die("Cannot create file %s: %s\n", outputname, strerror(errno)); 229 - } else { 230 - out = stdout; 231 - } 232 + /* open logo file */ 233 + if (outputname) { 234 + out = fopen(outputname, "w"); 235 + if (!out) 236 + die("Cannot create file %s: %s\n", outputname, strerror(errno)); 237 + } else { 238 + out = stdout; 239 + } 232 240 233 - fputs("/*\n", out); 234 - fputs(" * DO NOT EDIT THIS FILE!\n", out); 235 - fputs(" *\n", out); 236 - fprintf(out, " * It was automatically generated from %s\n", filename); 237 - fputs(" *\n", out); 238 - fprintf(out, " * Linux logo %s\n", logoname); 239 - fputs(" */\n\n", out); 240 - fputs("#include <linux/linux_logo.h>\n\n", out); 241 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n", 242 - logoname); 241 + fputs("/*\n", out); 242 + fputs(" * DO NOT EDIT THIS FILE!\n", out); 243 + fputs(" *\n", out); 244 + fprintf(out, " * It was automatically generated from %s\n", filename); 245 + fputs(" *\n", out); 246 + fprintf(out, " * Linux logo %s\n", logoname); 247 + fputs(" */\n\n", out); 248 + fputs("#include <linux/linux_logo.h>\n\n", out); 249 + fprintf(out, "static unsigned char %s_data[] __initdata = {\n", 250 + logoname); 243 251 } 244 252 245 253 static void write_footer(void) 246 254 { 247 - fputs("\n};\n\n", out); 248 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname); 249 - fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]); 250 - fprintf(out, "\t.width\t\t= %d,\n", logo_width); 251 - fprintf(out, "\t.height\t\t= %d,\n", logo_height); 252 - if (logo_type == LINUX_LOGO_CLUT224) { 253 - fprintf(out, "\t.clutsize\t= %d,\n", logo_clutsize); 254 - fprintf(out, "\t.clut\t\t= %s_clut,\n", logoname); 255 - } 256 - fprintf(out, "\t.data\t\t= %s_data\n", logoname); 257 - fputs("};\n\n", out); 255 + fputs("\n};\n\n", out); 256 + fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname); 257 + fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]); 258 + fprintf(out, "\t.width\t\t= %d,\n", logo_width); 259 + fprintf(out, "\t.height\t\t= %d,\n", logo_height); 260 + if (logo_type == LINUX_LOGO_CLUT224) { 261 + fprintf(out, "\t.clutsize\t= %d,\n", logo_clutsize); 262 + fprintf(out, "\t.clut\t\t= %s_clut,\n", logoname); 263 + } 264 + fprintf(out, "\t.data\t\t= %s_data\n", logoname); 265 + fputs("};\n\n", out); 258 266 259 - /* close logo file */ 260 - if (outputname) 261 - fclose(out); 267 + /* close logo file */ 268 + if (outputname) 269 + fclose(out); 262 270 } 263 271 264 272 static int write_hex_cnt; 265 273 266 274 static void write_hex(unsigned char byte) 267 275 { 268 - if (write_hex_cnt % 12) 269 - fprintf(out, ", 0x%02x", byte); 270 - else if (write_hex_cnt) 271 - fprintf(out, ",\n\t0x%02x", byte); 272 - else 273 - fprintf(out, "\t0x%02x", byte); 274 - write_hex_cnt++; 276 + if (write_hex_cnt % 12) 277 + fprintf(out, ", 0x%02x", byte); 278 + else if (write_hex_cnt) 279 + fprintf(out, ",\n\t0x%02x", byte); 280 + else 281 + fprintf(out, "\t0x%02x", byte); 282 + write_hex_cnt++; 275 283 } 276 284 277 285 static void write_logo_mono(void) 278 286 { 279 - unsigned int i, j; 280 - unsigned char val, bit; 287 + unsigned int i, j; 288 + unsigned char val, bit; 281 289 282 - /* validate image */ 283 - for (i = 0; i < logo_height; i++) 284 - for (j = 0; j < logo_width; j++) 285 - if (!is_black(logo_data[i][j]) && !is_white(logo_data[i][j])) 286 - die("Image must be monochrome\n"); 290 + /* validate image */ 291 + for (i = 0; i < logo_height; i++) 292 + for (j = 0; j < logo_width; j++) 293 + if (!is_black(logo_data[i][j]) && !is_white(logo_data[i][j])) 294 + die("Image must be monochrome\n"); 287 295 288 - /* write file header */ 289 - write_header(); 296 + /* write file header */ 297 + write_header(); 290 298 291 - /* write logo data */ 292 - for (i = 0; i < logo_height; i++) { 293 - for (j = 0; j < logo_width;) { 294 - for (val = 0, bit = 0x80; bit && j < logo_width; j++, bit >>= 1) 295 - if (logo_data[i][j].red) 296 - val |= bit; 297 - write_hex(val); 299 + /* write logo data */ 300 + for (i = 0; i < logo_height; i++) { 301 + for (j = 0; j < logo_width;) { 302 + for (val = 0, bit = 0x80; bit && j < logo_width; j++, bit >>= 1) 303 + if (logo_data[i][j].red) 304 + val |= bit; 305 + write_hex(val); 306 + } 298 307 } 299 - } 300 308 301 - /* write logo structure and file footer */ 302 - write_footer(); 309 + /* write logo structure and file footer */ 310 + write_footer(); 303 311 } 304 312 305 313 static void write_logo_vga16(void) 306 314 { 307 - unsigned int i, j, k; 308 - unsigned char val; 315 + unsigned int i, j, k; 316 + unsigned char val; 309 317 310 - /* validate image */ 311 - for (i = 0; i < logo_height; i++) 312 - for (j = 0; j < logo_width; j++) { 313 - for (k = 0; k < 16; k++) 314 - if (is_equal(logo_data[i][j], clut_vga16[k])) 315 - break; 316 - if (k == 16) 317 - die("Image must use the 16 console colors only\n" 318 - "Use ppmquant(1) -map clut_vga16.ppm to reduce the number " 319 - "of colors\n"); 320 - } 318 + /* validate image */ 319 + for (i = 0; i < logo_height; i++) 320 + for (j = 0; j < logo_width; j++) { 321 + for (k = 0; k < 16; k++) 322 + if (is_equal(logo_data[i][j], clut_vga16[k])) 323 + break; 324 + if (k == 16) 325 + die("Image must use the 16 console colors only\n" 326 + "Use ppmquant(1) -map clut_vga16.ppm to reduce the number " 327 + "of colors\n"); 328 + } 321 329 322 - /* write file header */ 323 - write_header(); 330 + /* write file header */ 331 + write_header(); 324 332 325 - /* write logo data */ 326 - for (i = 0; i < logo_height; i++) 327 - for (j = 0; j < logo_width; j++) { 328 - for (k = 0; k < 16; k++) 329 - if (is_equal(logo_data[i][j], clut_vga16[k])) 330 - break; 331 - val = k<<4; 332 - if (++j < logo_width) { 333 - for (k = 0; k < 16; k++) 334 - if (is_equal(logo_data[i][j], clut_vga16[k])) 335 - break; 336 - val |= k; 337 - } 338 - write_hex(val); 339 - } 333 + /* write logo data */ 334 + for (i = 0; i < logo_height; i++) 335 + for (j = 0; j < logo_width; j++) { 336 + for (k = 0; k < 16; k++) 337 + if (is_equal(logo_data[i][j], clut_vga16[k])) 338 + break; 339 + val = k<<4; 340 + if (++j < logo_width) { 341 + for (k = 0; k < 16; k++) 342 + if (is_equal(logo_data[i][j], clut_vga16[k])) 343 + break; 344 + val |= k; 345 + } 346 + write_hex(val); 347 + } 340 348 341 - /* write logo structure and file footer */ 342 - write_footer(); 349 + /* write logo structure and file footer */ 350 + write_footer(); 343 351 } 344 352 345 353 static void write_logo_clut224(void) 346 354 { 347 - unsigned int i, j, k; 355 + unsigned int i, j, k; 348 356 349 - /* validate image */ 350 - for (i = 0; i < logo_height; i++) 351 - for (j = 0; j < logo_width; j++) { 352 - for (k = 0; k < logo_clutsize; k++) 353 - if (is_equal(logo_data[i][j], logo_clut[k])) 354 - break; 355 - if (k == logo_clutsize) { 356 - if (logo_clutsize == MAX_LINUX_LOGO_COLORS) 357 - die("Image has more than %d colors\n" 358 - "Use ppmquant(1) to reduce the number of colors\n", 359 - MAX_LINUX_LOGO_COLORS); 360 - logo_clut[logo_clutsize++] = logo_data[i][j]; 361 - } 357 + /* validate image */ 358 + for (i = 0; i < logo_height; i++) 359 + for (j = 0; j < logo_width; j++) { 360 + for (k = 0; k < logo_clutsize; k++) 361 + if (is_equal(logo_data[i][j], logo_clut[k])) 362 + break; 363 + if (k == logo_clutsize) { 364 + if (logo_clutsize == MAX_LINUX_LOGO_COLORS) 365 + die("Image has more than %d colors\n" 366 + "Use ppmquant(1) to reduce the number of colors\n", 367 + MAX_LINUX_LOGO_COLORS); 368 + logo_clut[logo_clutsize++] = logo_data[i][j]; 369 + } 370 + } 371 + 372 + /* write file header */ 373 + write_header(); 374 + 375 + /* write logo data */ 376 + for (i = 0; i < logo_height; i++) 377 + for (j = 0; j < logo_width; j++) { 378 + for (k = 0; k < logo_clutsize; k++) 379 + if (is_equal(logo_data[i][j], logo_clut[k])) 380 + break; 381 + write_hex(k+32); 382 + } 383 + fputs("\n};\n\n", out); 384 + 385 + /* write logo clut */ 386 + fprintf(out, "static unsigned char %s_clut[] __initdata = {\n", 387 + logoname); 388 + write_hex_cnt = 0; 389 + for (i = 0; i < logo_clutsize; i++) { 390 + write_hex(logo_clut[i].red); 391 + write_hex(logo_clut[i].green); 392 + write_hex(logo_clut[i].blue); 362 393 } 363 394 364 - /* write file header */ 365 - write_header(); 366 - 367 - /* write logo data */ 368 - for (i = 0; i < logo_height; i++) 369 - for (j = 0; j < logo_width; j++) { 370 - for (k = 0; k < logo_clutsize; k++) 371 - if (is_equal(logo_data[i][j], logo_clut[k])) 372 - break; 373 - write_hex(k+32); 374 - } 375 - fputs("\n};\n\n", out); 376 - 377 - /* write logo clut */ 378 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n", 379 - logoname); 380 - write_hex_cnt = 0; 381 - for (i = 0; i < logo_clutsize; i++) { 382 - write_hex(logo_clut[i].red); 383 - write_hex(logo_clut[i].green); 384 - write_hex(logo_clut[i].blue); 385 - } 386 - 387 - /* write logo structure and file footer */ 388 - write_footer(); 395 + /* write logo structure and file footer */ 396 + write_footer(); 389 397 } 390 398 391 399 static void write_logo_gray256(void) 392 400 { 393 - unsigned int i, j; 401 + unsigned int i, j; 394 402 395 - /* validate image */ 396 - for (i = 0; i < logo_height; i++) 397 - for (j = 0; j < logo_width; j++) 398 - if (!is_gray(logo_data[i][j])) 399 - die("Image must be grayscale\n"); 403 + /* validate image */ 404 + for (i = 0; i < logo_height; i++) 405 + for (j = 0; j < logo_width; j++) 406 + if (!is_gray(logo_data[i][j])) 407 + die("Image must be grayscale\n"); 400 408 401 - /* write file header */ 402 - write_header(); 409 + /* write file header */ 410 + write_header(); 403 411 404 - /* write logo data */ 405 - for (i = 0; i < logo_height; i++) 406 - for (j = 0; j < logo_width; j++) 407 - write_hex(logo_data[i][j].red); 412 + /* write logo data */ 413 + for (i = 0; i < logo_height; i++) 414 + for (j = 0; j < logo_width; j++) 415 + write_hex(logo_data[i][j].red); 408 416 409 - /* write logo structure and file footer */ 410 - write_footer(); 417 + /* write logo structure and file footer */ 418 + write_footer(); 411 419 } 412 420 413 421 static void die(const char *fmt, ...) 414 422 { 415 - va_list ap; 423 + va_list ap; 416 424 417 - va_start(ap, fmt); 418 - vfprintf(stderr, fmt, ap); 419 - va_end(ap); 425 + va_start(ap, fmt); 426 + vfprintf(stderr, fmt, ap); 427 + va_end(ap); 420 428 421 - exit(1); 429 + exit(1); 422 430 } 423 431 424 432 static void usage(void) 425 433 { 426 - die("\n" 434 + die("\n" 427 435 "Usage: %s [options] <filename>\n" 428 436 "\n" 429 437 "Valid options:\n" 430 - " -h : display this usage information\n" 431 - " -n <name> : specify logo name (default: linux_logo)\n" 432 - " -o <output> : output to file <output> instead of stdout\n" 433 - " -t <type> : specify logo type, one of\n" 434 - " mono : monochrome black/white\n" 435 - " vga16 : 16 colors VGA text palette\n" 436 - " clut224 : 224 colors (default)\n" 437 - " gray256 : 256 levels grayscale\n" 438 + " -h : display this usage information\n" 439 + " -n <name> : specify logo name (default: linux_logo)\n" 440 + " -o <output> : output to file <output> instead of stdout\n" 441 + " -t <type> : specify logo type, one of\n" 442 + " mono : monochrome black/white\n" 443 + " vga16 : 16 colors VGA text palette\n" 444 + " clut224 : 224 colors (default)\n" 445 + " gray256 : 256 levels grayscale\n" 438 446 "\n", programname); 439 447 } 440 448 441 449 int main(int argc, char *argv[]) 442 450 { 443 - int opt; 451 + int opt; 444 452 445 - programname = argv[0]; 453 + programname = argv[0]; 446 454 447 - opterr = 0; 448 - while (1) { 449 - opt = getopt(argc, argv, "hn:o:t:"); 450 - if (opt == -1) 451 - break; 455 + opterr = 0; 456 + while (1) { 457 + opt = getopt(argc, argv, "hn:o:t:"); 458 + if (opt == -1) 459 + break; 452 460 453 - switch (opt) { 454 - case 'h': 455 - usage(); 456 - break; 461 + switch (opt) { 462 + case 'h': 463 + usage(); 464 + break; 457 465 458 - case 'n': 459 - logoname = optarg; 460 - break; 466 + case 'n': 467 + logoname = optarg; 468 + break; 461 469 462 - case 'o': 463 - outputname = optarg; 464 - break; 470 + case 'o': 471 + outputname = optarg; 472 + break; 465 473 466 - case 't': 467 - if (!strcmp(optarg, "mono")) 468 - logo_type = LINUX_LOGO_MONO; 469 - else if (!strcmp(optarg, "vga16")) 470 - logo_type = LINUX_LOGO_VGA16; 471 - else if (!strcmp(optarg, "clut224")) 472 - logo_type = LINUX_LOGO_CLUT224; 473 - else if (!strcmp(optarg, "gray256")) 474 - logo_type = LINUX_LOGO_GRAY256; 475 - else 476 - usage(); 477 - break; 474 + case 't': 475 + if (!strcmp(optarg, "mono")) 476 + logo_type = LINUX_LOGO_MONO; 477 + else if (!strcmp(optarg, "vga16")) 478 + logo_type = LINUX_LOGO_VGA16; 479 + else if (!strcmp(optarg, "clut224")) 480 + logo_type = LINUX_LOGO_CLUT224; 481 + else if (!strcmp(optarg, "gray256")) 482 + logo_type = LINUX_LOGO_GRAY256; 483 + else 484 + usage(); 485 + break; 478 486 479 - default: 480 - usage(); 481 - break; 487 + default: 488 + usage(); 489 + break; 490 + } 482 491 } 483 - } 484 - if (optind != argc-1) 485 - usage(); 492 + if (optind != argc-1) 493 + usage(); 486 494 487 - filename = argv[optind]; 495 + filename = argv[optind]; 488 496 489 - read_image(); 490 - switch (logo_type) { 497 + read_image(); 498 + switch (logo_type) { 491 499 case LINUX_LOGO_MONO: 492 - write_logo_mono(); 493 - break; 500 + write_logo_mono(); 501 + break; 494 502 495 503 case LINUX_LOGO_VGA16: 496 - write_logo_vga16(); 497 - break; 504 + write_logo_vga16(); 505 + break; 498 506 499 507 case LINUX_LOGO_CLUT224: 500 - write_logo_clut224(); 501 - break; 508 + write_logo_clut224(); 509 + break; 502 510 503 511 case LINUX_LOGO_GRAY256: 504 - write_logo_gray256(); 505 - break; 506 - } 507 - exit(0); 512 + write_logo_gray256(); 513 + break; 514 + } 515 + exit(0); 508 516 }