mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH] bmp support: Use unaligned accessors
Date: Tue, 23 Jun 2015 16:55:24 +0200	[thread overview]
Message-ID: <1435071324-1872-1-git-send-email-s.hauer@pengutronix.de> (raw)

Some fields in the bmp header are unaligned. Use unaligned accessor
functions to acces them.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 lib/gui/bmp.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/lib/gui/bmp.c b/lib/gui/bmp.c
index 6943a1c..d457c01 100644
--- a/lib/gui/bmp.c
+++ b/lib/gui/bmp.c
@@ -7,6 +7,7 @@
 #include <gui/graphic_utils.h>
 #include <init.h>
 #include <gui/image_renderer.h>
+#include <asm/unaligned.h>
 
 struct image *bmp_open(char *inbuf, int insize)
 {
@@ -19,9 +20,9 @@ struct image *bmp_open(char *inbuf, int insize)
 	}
 
 	img->data = inbuf;
-	img->height = le32_to_cpu(bmp->header.height);
-	img->width = le32_to_cpu(bmp->header.width);
-	img->bits_per_pixel = le16_to_cpu(bmp->header.bit_count);
+	img->height = get_unaligned_le32(&bmp->header.height);
+	img->width = get_unaligned_le32(&bmp->header.width);
+	img->bits_per_pixel = get_unaligned_le16(&bmp->header.bit_count);
 
 	pr_debug("bmp: %d x %d  x %d data@0x%p\n", img->width, img->height,
 		 img->bits_per_pixel, img->data);
@@ -76,7 +77,7 @@ static int bmp_renderer(struct screen *sc, struct surface *s, struct image *img)
 
 		for (y = 0; y < height; y++) {
 			image = (char *)bmp +
-					le32_to_cpu(bmp->header.data_offset);
+					get_unaligned_le32(&bmp->header.data_offset);
 			image += (img->height - y - 1) * img->width * (bits_per_pixel >> 3);
 			adr = buf + (y + starty) * sc->info.line_length +
 					startx * (sc->info.bits_per_pixel >> 3);
@@ -98,7 +99,7 @@ static int bmp_renderer(struct screen *sc, struct surface *s, struct image *img)
 
 		for (y = 0; y < height; y++) {
 			image = (char *)bmp +
-					le32_to_cpu(bmp->header.data_offset);
+					get_unaligned_le32(&bmp->header.data_offset);
 			image += (img->height - y - 1) * img->width * (bits_per_pixel >> 3);
 			adr = buf + (y + starty) * sc->info.line_length +
 					startx * (sc->info.bits_per_pixel >> 3);
-- 
2.1.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

                 reply	other threads:[~2015-06-23 14:55 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1435071324-1872-1-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox