From a9c88e1f2c1099788f9af124f44f660bc602054e Mon Sep 17 00:00:00 2001 From: neil Date: Thu, 29 Jan 2015 03:51:53 +0000 Subject: [PATCH] - Added support for standard 32-bit images. - Use bit replication for 16-bit images to give a fuller range of colours (so e.g. pure white is possible). - Removed unreachable code. git-svn-id: https://svn.aros.org/svn/aros/trunk/AROS@49969 fb15a70f-31f2-0310-bbcc-cdcc74a49acc --- workbench/classes/datatypes/bmp/bmp.conf | 2 +- workbench/classes/datatypes/bmp/bmpclass.c | 44 ++++++++++++++++++++++-------- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/workbench/classes/datatypes/bmp/bmp.conf b/workbench/classes/datatypes/bmp/bmp.conf index acf83ea7da..8f1740914d 100644 --- a/workbench/classes/datatypes/bmp/bmp.conf +++ b/workbench/classes/datatypes/bmp/bmp.conf @@ -1,6 +1,6 @@ ##begin config basename BMP -version 41.4 +version 41.5 superclass PICTUREDTCLASS ##end config ##begin cdef diff --git a/workbench/classes/datatypes/bmp/bmpclass.c b/workbench/classes/datatypes/bmp/bmpclass.c index f63665dc34..c09cf99faa 100644 --- a/workbench/classes/datatypes/bmp/bmpclass.c +++ b/workbench/classes/datatypes/bmp/bmpclass.c @@ -314,13 +314,10 @@ static BOOL LoadBMP(struct IClass *cl, Object *o) alignbytes = alignwidth; break; case 16: - alignbytes = ((biBitCount * biWidth + 31) / 32) * 4; - alignwidth = alignbytes / 2; - pixelfmt = PBPAFMT_RGB; - break; case 24: + case 32: alignbytes = ((biBitCount * biWidth + 31) / 32) * 4; - alignwidth = alignbytes / 3; + alignwidth = alignbytes / (biBitCount / 8); pixelfmt = PBPAFMT_RGB; break; default: @@ -398,7 +395,7 @@ static BOOL LoadBMP(struct IClass *cl, Object *o) UWORD pixel; bmphandle->linebufpos = bmphandle->linebuf; - if (biBitCount == 24) + if (biBitCount == 32) { if ( (bmphandle->filebufbytes -= alignbytes) < 0 && !LoadBMP_FillBuf(bmphandle, alignbytes) ) { @@ -412,6 +409,25 @@ static BOOL LoadBMP(struct IClass *cl, Object *o) b = *p++; g = *p++; r = *p++; + p++; + *(bmphandle->linebufpos)++ = r; + *(bmphandle->linebufpos)++ = g; + *(bmphandle->linebufpos)++ = b; + } + bmphandle->filebufpos += alignbytes; + } + else if (biBitCount == 24) + { + if ( (bmphandle->filebufbytes -= alignbytes) < 0 && !LoadBMP_FillBuf(bmphandle, alignbytes) ) + { + D(bug("bmp.datatype/LoadBMP() --- early end of bitmap data, x %ld y %ld\n", x, y)); + cont = 0; + } + for (x=0, p = bmphandle->filebufpos; xlinebufpos)++ = r; *(bmphandle->linebufpos)++ = g; *(bmphandle->linebufpos)++ = b; @@ -423,8 +439,6 @@ static BOOL LoadBMP(struct IClass *cl, Object *o) if ( (bmphandle->filebufbytes -= alignbytes) < 0 && !LoadBMP_FillBuf(bmphandle, alignbytes) ) { D(bug("bmp.datatype/LoadBMP() --- early end of bitmap data, x %ld y %ld\n", x, y)); - //BMP_Exit(bmphandle, ERROR_OBJECT_WRONG_TYPE); - //return FALSE; cont = 0; } for (x=0, p = bmphandle->filebufpos; xlinebufpos)++ = (pixel & 0x7c00) >> 7; *(bmphandle->linebufpos)++ = (pixel & 0x03e0) >> 2; - *(bmphandle->linebufpos)++ = (pixel & 0x1f) << 3; + *(bmphandle->linebufpos)++ = (pixel & 0x001f) << 3; } bmphandle->filebufpos += alignbytes; + + /* Use bit replication to give a fuller range of colours + (so e.g. pure white is possible) */ + bmphandle->linebufpos = bmphandle->linebuf; + for (x = 0; x < alignwidth * 3; x++) + { + *(bmphandle->linebufpos) |= *bmphandle->linebufpos >> 5; + bmphandle->linebufpos++; + } } else { @@ -466,9 +489,6 @@ static BOOL LoadBMP(struct IClass *cl, Object *o) case 8: *(bmphandle->linebufpos)++ = byte; break; - case 24: - *(bmphandle->linebufpos)++ = byte; - break; } } } -- 2.11.4.GIT