support for raw 16-bit RGB565

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
User avatar
fmw42
Posts: 25664
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: support for raw 16-bit RGB565

Post by fmw42 » 2019-06-03T14:36:35-07:00

I have never seen anything about geometry accepting offset in bytes. Where did you see that? Offset is in pixels according to https://imagemagick.org/script/command- ... p#geometry

User avatar
magick
Site Admin
Posts: 11077
Joined: 2003-05-31T11:32:55-07:00

Re: support for raw 16-bit RGB565

Post by magick » 2019-06-03T17:07:53-07:00

We'll add a 565 coder within a day or two:

Code: Select all

magick -size 800x600 "RGB565:Loading Default.2rawdata" crest.png

snibgo
Posts: 12303
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: support for raw 16-bit RGB565

Post by snibgo » 2019-06-04T05:01:32-07:00

HoraK-FDF wrote:yes that with the And is clear but when shifted on all other languages I know on one side zeroes come in an this would make the And unnecessary so does ImageMagick rotate interanlly meaning the bits leaving on one side come in on the other?
"-evaluate LeftShift" and "-evaluate RightShift" implement the C operators "<<" and ">>". See http://www.gnu.org/software/gnu-c-manua ... t-Shifting . These shift, they do not rotate unless the top bit was 1 ("signed negative value"). So we generally need "-evaluate And" to mask the bits.

The evaluates can be simplified in a number of ways, such as:

Code: Select all

magick ^
  -size 800x600 -depth 16 ^
  "GRAY:Loading Default.2rawdata" ^
  ( -clone 0 -evaluate And 63488 ) ^
  ( -clone 0 -evaluate And 2016 -evaluate LeftShift 5 ) ^
  ( -clone 0 -evaluate And 31 -evaluate LeftShift 11 ) ^
  -delete 0 ^
  -combine ^
  f4.png
Note that 63488 is binary 11111000 00000000, and 2016 is binary 00000111 11100000.
snibgo's IM pages: im.snibgo.com

HoraK-FDF
Posts: 11
Joined: 2019-05-22T10:16:25-07:00
Authentication code: 1152

Re: support for raw 16-bit RGB565

Post by HoraK-FDF » 2019-06-04T14:38:33-07:00

fmw42 wrote:
2019-06-03T14:36:35-07:00
I have never seen anything about geometry accepting offset in bytes. Where did you see that? Offset is in pixels according to https://imagemagick.org/script/command- ... p#geometry
I've read about it on this pages:
https://www.imagemagick.org/discourse-s ... hp?t=20324
http://kirste.userpage.fu-berlin.de/che ... nvert.html
There where a few more but I did not find them again.
magick wrote:
2019-06-03T17:07:53-07:00
We'll add a 565 coder within a day or two:

Code: Select all

magick -size 800x600 "RGB565:Loading Default.2rawdata" crest.png
Thank you very much.
snibgo wrote:
2019-06-04T05:01:32-07:00
"-evaluate LeftShift" and "-evaluate RightShift" implement the C operators "<<" and ">>". See http://www.gnu.org/software/gnu-c-manua ... t-Shifting . These shift, they do not rotate unless the top bit was 1 ("signed negative value"). So we generally need "-evaluate And" to mask the bits.

The evaluates can be simplified in a number of ways, such as:

Code: Select all

magick ^
  -size 800x600 -depth 16 ^
  "GRAY:Loading Default.2rawdata" ^
  ( -clone 0 -evaluate And 63488 ) ^
  ( -clone 0 -evaluate And 2016 -evaluate LeftShift 5 ) ^
  ( -clone 0 -evaluate And 31 -evaluate LeftShift 11 ) ^
  -delete 0 ^
  -combine ^
  f4.png
Note that 63488 is binary 11111000 00000000, and 2016 is binary 00000111 11100000.
Thank you for the explanation and the simple version.

About that problem with the tailing 2400bytes could that be avoided with some kind of option/switch or does ImageMagick needs to be modifyed to do that?

snibgo
Posts: 12303
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: support for raw 16-bit RGB565

Post by snibgo » 2019-06-04T15:11:42-07:00

You can use head and tail for that:

Code: Select all

cat "Loading Default.frm16" |head -c -2400 |tail -c +37 |magick ^
  -size 800x600 -depth 16 GRAY:- ^
  ( -clone 0 -evaluate And 63488 ) ^
  ( -clone 0 -evaluate And 2016 -evaluate LeftShift 5 ) ^
  ( -clone 0 -evaluate And 31 -evaluate LeftShift 11 ) ^
  -delete 0 ^
  -combine ^
  f6.png
snibgo's IM pages: im.snibgo.com

HoraK-FDF
Posts: 11
Joined: 2019-05-22T10:16:25-07:00
Authentication code: 1152

Re: support for raw 16-bit RGB565

Post by HoraK-FDF » 2019-06-05T12:33:44-07:00

snibgo wrote:
2019-06-04T15:11:42-07:00
You can use head and tail for that:

Code: Select all

cat "Loading Default.frm16" |head -c -2400 |tail -c +37 |magick ^
  -size 800x600 -depth 16 GRAY:- ^
  ( -clone 0 -evaluate And 63488 ) ^
  ( -clone 0 -evaluate And 2016 -evaluate LeftShift 5 ) ^
  ( -clone 0 -evaluate And 31 -evaluate LeftShift 11 ) ^
  -delete 0 ^
  -combine ^
  f6.png
Thanks for the info, but shouldn't ImageMagick be able to do this by itself? Can I ask for this feature to be added maybe right here or should I make a new post?

snibgo
Posts: 12303
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: support for raw 16-bit RGB565

Post by snibgo » 2019-06-05T12:39:16-07:00

You can always ask, in this thread or in the "Developers" subforum.
snibgo's IM pages: im.snibgo.com

Post Reply