comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: read 12 bit array
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: read 12 bit array [message #75564] Sat, 02 April 2011 11:55 Go to previous message
Wout De Nolf is currently offline  Wout De Nolf
Messages: 194
Registered: October 2008
Senior Member
On Thu, 31 Mar 2011 08:00:38 -0700 (PDT), alx
<lecacheux.alain@wanadoo.fr> wrote:

> Read it as [3,N] byte array b, if the file contains an array of 2*N 12
> bits words.
> Then transform the result to an integer (16 bits) array by b = fix(b,
> 0, 3, N)
> Finally concatenate the first and last bytes of each triple with
> corresponding half parts of the middle byte, that is :
> [ b[0,*] or (ishft(b[1,*] and '0F'x,8), ishft(b[2,*],4) or
> ishft((b[1,*] and 'F0'x), -4) ]
> You should get your 12 bits array packed in a 16-bits array of same
> size.
> alx.

Thanks. I came up with something like this.

; 8bit array with "bigedian" endianness
arr=bindgen(48)
nbytes=n_elements(arr)
nadd=nbytes mod 6
if nadd ne 0 then arr=[arr,bytarr(nadd)]

; convert to 16bit array (endianness of machine)
arr=fix(arr,0,3,nbytes/6)
SWAP_ENDIAN_INPLACE, arr, SWAP_IF_BIG_ENDIAN=~bigendian,
SWAP_IF_LITTLE_ENDIAN=bigendian

; convert to 12bit array
; Each tripple of 16bit numbers: [4 4 4][4 \ 4 4][4 4 \ 4][4 4 4]
arr=[ishft(arr[0,*],-4),$
ishft(arr[0,*] and '000F'x,8) or ishft(arr[1,*] and fix('FF00'x),-8),$
ishft(arr[1,*] and '00FF'x,4) or ishft(arr[2,*] andfix('F000'x),-12),$
arr[2,*] and '0FFF'x]
arr=arr[0:n_elements(arr)-1-nadd*8/12]
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: hardware renderer
Next Topic: Bringing widgets to the front

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 13:31:16 PDT 2025

Total time taken to generate the page: 0.00395 seconds