Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/rasops add another convenience function:



details:   https://anonhg.NetBSD.org/src/rev/ce3e7731ed67
branches:  trunk
changeset: 778890:ce3e7731ed67
user:      macallan <macallan%NetBSD.org@localhost>
date:      Thu Apr 19 06:57:39 2012 +0000

description:
add another convenience function:
rasops_get_cmap() which returns either the ANSI map or an R3G3B2 map,
depending on the rasops_info handed to it so drivers don't have to
duplicate this particular code snippet

diffstat:

 sys/dev/rasops/rasops.c |  48 ++++++++++++++++++++++++++++++++++++++++++++++--
 sys/dev/rasops/rasops.h |   4 +++-
 2 files changed, 49 insertions(+), 3 deletions(-)

diffs (84 lines):

diff -r b5eb97148b73 -r ce3e7731ed67 sys/dev/rasops/rasops.c
--- a/sys/dev/rasops/rasops.c   Wed Apr 18 22:44:43 2012 +0000
+++ b/sys/dev/rasops/rasops.c   Thu Apr 19 06:57:39 2012 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: rasops.c,v 1.70 2012/01/11 15:52:32 macallan Exp $    */
+/*      $NetBSD: rasops.c,v 1.71 2012/04/19 06:57:39 macallan Exp $    */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rasops.c,v 1.70 2012/01/11 15:52:32 macallan Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rasops.c,v 1.71 2012/04/19 06:57:39 macallan Exp $");
 
 #include "opt_rasops.h"
 #include "rasops_glue.h"
@@ -1759,3 +1759,47 @@
                }
        }
 }
+
+/*
+ * Return a colour map appropriate for the given struct rasops_info in the
+ * same form used by rasops_cmap[]
+ * For now this is either a copy of rasops_cmap[] or an R3G3B2 map, it should
+ * probably be a linear ( or gamma corrected? ) ramp for higher depths.
+ */
+ 
+int
+rasops_get_cmap(struct rasops_info *ri, uint8_t *palette, size_t bytes)
+{
+       if ((ri->ri_depth == 8 ) && ((ri->ri_flg & RI_8BIT_IS_RGB) > 0)) {
+               /* generate an R3G3B2 palette */
+               int i, idx = 0;
+               uint8_t tmp;
+
+               if (bytes < 768)
+                       return EINVAL;
+               for (i = 0; i < 256; i++) {
+                       tmp = i & 0xe0;
+                       /*
+                        * replicate bits so 0xe0 maps to a red value of 0xff
+                        * in order to make white look actually white
+                        */
+                       tmp |= (tmp >> 3) | (tmp >> 6);
+                       palette[idx] = tmp;
+                       idx++;
+
+                       tmp = (i & 0x1c) << 3;
+                       tmp |= (tmp >> 3) | (tmp >> 6);
+                       palette[idx] = tmp;
+                       idx++;
+
+                       tmp = (i & 0x03) << 6;
+                       tmp |= tmp >> 2;
+                       tmp |= tmp >> 4;
+                       palette[idx] = tmp;
+                       idx++;
+               }
+       } else {
+               memcpy(palette, rasops_cmap, MIN(bytes, sizeof(rasops_cmap)));
+       }
+       return 0;
+}
diff -r b5eb97148b73 -r ce3e7731ed67 sys/dev/rasops/rasops.h
--- a/sys/dev/rasops/rasops.h   Wed Apr 18 22:44:43 2012 +0000
+++ b/sys/dev/rasops/rasops.h   Thu Apr 19 06:57:39 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rasops.h,v 1.30 2012/01/11 15:52:32 macallan Exp $ */
+/*     $NetBSD: rasops.h,v 1.31 2012/04/19 06:57:39 macallan Exp $ */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -176,6 +176,8 @@
 void   rasops_eraserows(void *, int, int, long);
 void   rasops_erasecols(void *, int, int, int, long);
 void   rasops_copycols(void *, int, int, int, int);
+int    rasops_get_cmap(struct rasops_info *, uint8_t *, size_t);
+
 
 extern const u_char    rasops_isgray[16];
 extern const u_char    rasops_cmap[256*3];



Home | Main Index | Thread Index | Old Index