- BYTE arithmetic

From: Campbell, Robert D (SELEX) (UK Edinburgh) <"Campbell,>
Date: Thu, 22 Jun 2006 09:45:17 +0100

----boundary-LibPST-iamunique-801013197_-_-
Content-type: text/plain


Thanks to everyone who replied to my BTYE arithmetic question. Yes, I
should have read the Report! Actually I did have a quick look (I was in
a hurry) by searching for references to BYTE. The relevant text does not
mention BYTEs directly!


I guess that is one of the problems of working with a language that is
so complicated that the report takes 35 pages; it is impractically hard
to learn even after 10 years.


I was updating some data to be used as a Windows bitmap.

Problem: The BlackBox Ports.Color format is different to the Windows
32-bit bitmap
format, so every pixel had to be changed as follows:


PROCEDURE Shuffle (c : Ports.Color) : Ports.Color;
  TYPE
    IntArray = ARRAY SIZE (INTEGER) OF BYTE;
  VAR
    b : BYTE;
    a : IntArray;
  BEGIN
    a := SYSTEM.VAL (IntArray, c);
    b := a [0]; a [0] := a [2]; a [2] := b;
    RETURN SYSTEM.VAL (Ports.Color, a)
  END Shuffle;


I also wanted to 'invert' some colours, which is why I tried to negate
the relevant bytes. My second attempt is:

PROCEDURE Invert (c : Ports.Color) : Ports.Color;
  BEGIN
    RETURN SYSTEM.VAL (Ports.Color, SYSTEM.VAL (SET, c) / {0 .. 23})
  END Invert;


I can now simply (!) call the Windows bitmap function with arrays of
colour data by:

TYPE
  Pixel = POINTER TO ARRAY OF ARRAY OF Ports.Color;

  BitMap = POINTER TO RECORD
               bmiHeader : WinApi.BITMAPINFOHEADER;
               pixel : Pixel
             END;
...
    res := WinApi.StretchDIBits (hdc, xOff, yOff, wid, hgt,
                                0, 0, bitMap.bmiHeader.biWidth,
                                      bitMap.bmiHeader.biHeight,
                                SYSTEM.ADR (bitMap.pixel^),
                                SYSTEM.VAL (WinApi.PtrBITMAPINFO,
bitMap),
                                WinApi.DIB_RGB_COLORS, WinApi.SRCCOPY);


Maybe there are better ways of writing the Shuffle & Invert routines!

Thanks

Robert


PS - I know that for some readers English is not their first language,
so I shall explain that the 35 page comment is meant to be sarcastic,
and I am aware that some languages have an even larger reference manual.


********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************

--- BlackBox
--- send subject HELP or UNSUBSCRIBE to blackbox{([at]})nowhere.xy



----boundary-LibPST-iamunique-801013197_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"

e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzcyBBcmlhbDt9DQp7XGYxXGZtb2Rlcm4gQ291cmllciBOZXc7fQ0Ke1xmMlxmbmlsXGZjaGFy
c2V0MiBTeW1ib2w7fQ0Ke1xmM1xmbW9kZXJuXGZjaGFyc2V0MCBDb3VyaWVyIE5ldzt9fQ0Ke1xj
b2xvcnRibFxyZWQwXGdyZWVuMFxibHVlMDtccmVkMFxncmVlbjBcYmx1ZTI1NTt9DQpcdWMxXHBh
cmRccGxhaW5cZGVmdGFiMzYwIFxmMFxmczIwIFxwYXINClRoYW5rcyB0byBldmVyeW9uZSB3aG8g
cmVwbGllZCB0byBteSBCVFlFIGFyaXRobWV0aWMgcXVlc3Rpb24uIFllcywgSVxwYXINCnNob3Vs
ZCBoYXZlIHJlYWQgdGhlIFJlcG9ydCEgQWN0dWFsbHkgSSBkaWQgaGF2ZSBhIHF1aWNrIGxvb2sg
KEkgd2FzIGluXHBhcg0KYSBodXJyeSkgYnkgc2VhcmNoaW5nIGZvciByZWZlcmVuY2VzIHRvIEJZ
VEUuIFRoZSByZWxldmFudCB0ZXh0IGRvZXMgbm90XHBhcg0KbWVudGlvbiBCWVRFcyBkaXJlY3Rs
eSFccGFyDQpccGFyDQpccGFyDQpJIGd1ZXNzIHRoYXQgaXMgb25lIG9mIHRoZSBwcm9ibGVtcyBv
ZiB3b3JraW5nIHdpdGggYSBsYW5ndWFnZSB0aGF0IGlzXHB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5IHRoZSBzZW5k
ZXIuXHBhcg0KWW91IHNob3VsZCBub3QgY29weSBpdCBvciB1c2UgaXQgZm9yIGFueSBwdXJwb3Nl
IG5vciBkaXNjbG9zZSBvclxwYXINCmRpc3RyaWJ1dGUgaXRzIGNvbnRlbnRzIHRvIGFueSBvdGhl
ciBwZXJzb24uXHBhcg0KKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioq
KioqKioqKioqKioqKioqKioqKioqKioqKipccGFyDQpccGFyDQotLS0gQmxhY2tCb3hccGFyDQot
LS0gc2VuZCBzdWJqZWN0IEhFTFAgb3IgVU5TVUJTQ1JJQkUgdG8gYmxhY2tib3hAb2Jlcm9uLmNo
fX0AIEJFR0lODQogIA=


----boundary-LibPST-iamunique-801013197_-_---
Received on Thu Jun 22 2006 - 10:45:17 UTC

This archive was generated by hypermail 2.3.0 : Thu Sep 26 2013 - 06:27:50 UTC