Mercurial > mplayer.hg
changeset 33215:4c7b564719e0
Simplify colormap generation code, avoid some mallocs and add frees
for one error case.
author | reimar |
---|---|
date | Fri, 22 Apr 2011 16:53:01 +0000 |
parents | 4de1d029ab8f |
children | 5f00ed06579d |
files | libvo/vo_fbdev2.c |
diffstat | 1 files changed, 8 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/libvo/vo_fbdev2.c Fri Apr 22 16:45:09 2011 +0000 +++ b/libvo/vo_fbdev2.c Fri Apr 22 16:53:01 2011 +0000 @@ -124,39 +124,23 @@ /* Make our palette the length of the deepest color */ cols = FFMAX3(rcols, gcols, bcols); - red = malloc(cols * sizeof(red[0])); + red = malloc(3 * cols * sizeof(red[0])); if(!red) { mp_msg(MSGT_VO, MSGL_ERR, "[fbdev2] Can't allocate red palette with %d entries.\n", cols); return NULL; } - for(i=0; i< rcols; i++) - red[i] = (65535/(rcols-1)) * i; - - green = malloc(cols * sizeof(green[0])); - if(!green) { - mp_msg(MSGT_VO, MSGL_ERR, "[fbdev2] Can't allocate green palette with %d entries.\n", cols); - free(red); - return NULL; - } - for(i=0; i< gcols; i++) + green = red + cols; + blue = green + cols; + for (i = 0; i < cols; i++) { + red[i] = (65535/(rcols-1)) * i; green[i] = (65535/(gcols-1)) * i; - - blue = malloc(cols * sizeof(blue[0])); - if(!blue) { - mp_msg(MSGT_VO, MSGL_ERR, "[fbdev2] Can't allocate blue palette with %d entries.\n", cols); - free(red); - free(green); - return NULL; + blue[i] = (65535/(bcols-1)) * i; } - for(i=0; i< bcols; i++) - blue[i] = (65535/(bcols-1)) * i; cmap = malloc(sizeof(struct fb_cmap)); if(!cmap) { mp_msg(MSGT_VO, MSGL_ERR, "[fbdev2] Can't allocate color map\n"); free(red); - free(green); - free(blue); return NULL; } cmap->start = 0; @@ -278,12 +262,12 @@ return 1; if (ioctl(fb_dev_fd, FBIOPUTCMAP, cmap)) { mp_msg(MSGT_VO, MSGL_ERR, "[fbdev2] can't put cmap: %s\n", strerror(errno)); + free(cmap->red); + free(cmap); return 1; } fb_cmap_changed = 1; free(cmap->red); - free(cmap->green); - free(cmap->blue); free(cmap); break; default: