-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathLASreadItemCompressed_RGB12_v1.cs
97 lines (79 loc) · 2.6 KB
/
LASreadItemCompressed_RGB12_v1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//===============================================================================
//
// FILE: lasreaditemcompressed_rgb12_v1.cs
//
// CONTENTS:
//
// Implementation of LASreadItemCompressed for RGB12 items (version 1).
//
// PROGRAMMERS:
//
// [email protected] - http://rapidlasso.com
//
// COPYRIGHT:
//
// (c) 2005-2012, martin isenburg, rapidlasso - tools to catch reality
// (c) of the C# port 2014 by Shinta <[email protected]>
//
// This is free software; you can redistribute and/or modify it under the
// terms of the GNU Lesser General Licence as published by the Free Software
// Foundation. See the COPYING file for more information.
//
// This software is distributed WITHOUT ANY WARRANTY and without even the
// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// CHANGE HISTORY: omitted for easier Copy&Paste (pls see the original)
//
//===============================================================================
using System.Diagnostics;
namespace laszip.net
{
class LASreadItemCompressed_RGB12_v1 : LASreadItemCompressed
{
public LASreadItemCompressed_RGB12_v1(ArithmeticDecoder dec)
{
// set decoder
Debug.Assert(dec!=null);
this.dec=dec;
// create models and integer compressors
m_byte_used=dec.createSymbolModel(64);
ic_rgb=new IntegerCompressor(dec, 8, 6);
}
public override bool init(laszip_point item)
{
// init state
// init models and integer compressors
dec.initSymbolModel(m_byte_used);
ic_rgb.initDecompressor();
// init last item
r=item.rgb[0];
g=item.rgb[1];
b=item.rgb[2];
return true;
}
public override void read(laszip_point item)
{
uint sym=dec.decodeSymbol(m_byte_used);
ushort[] item16=item.rgb;
if((sym&(1<<0))!=0) item16[0]=(ushort)ic_rgb.decompress(r&255, 0);
else item16[0]=(ushort)(r&0xFF);
if((sym&(1<<1))!=0) item16[0]|=(ushort)(((ushort)ic_rgb.decompress(r>>8, 1))<<8);
else item16[0]|=(ushort)(r&0xFF00);
if((sym&(1<<2))!=0) item16[1]=(ushort)ic_rgb.decompress(g&255, 2);
else item16[1]=(ushort)(g&0xFF);
if((sym&(1<<3))!=0) item16[1]|=(ushort)(((ushort)ic_rgb.decompress(g>>8, 3))<<8);
else item16[1]|=(ushort)(g&0xFF00);
if((sym&(1<<4))!=0) item16[2]=(ushort)ic_rgb.decompress(b&255, 4);
else item16[2]=(ushort)(b&0xFF);
if((sym&(1<<5))!=0) item16[2]|=(ushort)(((ushort)ic_rgb.decompress(b>>8, 5))<<8);
else item16[2]|=(ushort)(b&0xFF00);
r=item16[0];
g=item16[1];
b=item16[2];
}
ArithmeticDecoder dec;
ushort r, g, b;
ArithmeticModel m_byte_used;
IntegerCompressor ic_rgb;
}
}