/src/gdal/frmts/pcidsk/sdk/segment/cpcidsklut.cpp
Line | Count | Source |
1 | | /****************************************************************************** |
2 | | * |
3 | | * Purpose: Implementation of the CPCIDSK_LUT class. |
4 | | * |
5 | | ****************************************************************************** |
6 | | * Copyright (c) 2015 |
7 | | * PCI Geomatics, 90 Allstate Parkway, Markham, Ontario, Canada. |
8 | | * |
9 | | * SPDX-License-Identifier: MIT |
10 | | ****************************************************************************/ |
11 | | |
12 | | #include "pcidsk_exception.h" |
13 | | #include "segment/cpcidsklut.h" |
14 | | #include <cassert> |
15 | | #include <cstring> |
16 | | |
17 | | using namespace PCIDSK; |
18 | | |
19 | 0 | PCIDSK_LUT::~PCIDSK_LUT() = default; |
20 | | |
21 | | /************************************************************************/ |
22 | | /* CPCIDSK_LUT() */ |
23 | | /************************************************************************/ |
24 | | |
25 | | CPCIDSK_LUT::CPCIDSK_LUT( PCIDSKFile *fileIn, int segmentIn, |
26 | | const char *segment_pointer ) |
27 | 0 | : CPCIDSKSegment( fileIn, segmentIn, segment_pointer ) |
28 | | |
29 | 0 | { |
30 | 0 | } Unexecuted instantiation: PCIDSK::CPCIDSK_LUT::CPCIDSK_LUT(PCIDSK::PCIDSKFile*, int, char const*) Unexecuted instantiation: PCIDSK::CPCIDSK_LUT::CPCIDSK_LUT(PCIDSK::PCIDSKFile*, int, char const*) |
31 | | |
32 | | /************************************************************************/ |
33 | | /* ~CPCIDSKGeoref() */ |
34 | | /************************************************************************/ |
35 | | |
36 | | CPCIDSK_LUT::~CPCIDSK_LUT() |
37 | | |
38 | 0 | { |
39 | 0 | } |
40 | | |
41 | | /************************************************************************/ |
42 | | /* ReadLUT() */ |
43 | | /************************************************************************/ |
44 | | |
45 | | void CPCIDSK_LUT::ReadLUT(std::vector<unsigned char>& lut) |
46 | | |
47 | 0 | { |
48 | 0 | PCIDSKBuffer seg_data; |
49 | |
|
50 | 0 | seg_data.SetSize(256*4); |
51 | |
|
52 | 0 | ReadFromFile( seg_data.buffer, 0, 256*4); |
53 | |
|
54 | 0 | lut.resize(256); |
55 | 0 | for( int i = 0; i < 256; i++ ) |
56 | 0 | { |
57 | 0 | lut[i] = (unsigned char) seg_data.GetInt(0+i*4, 4); |
58 | 0 | } |
59 | 0 | } |
60 | | |
61 | | /************************************************************************/ |
62 | | /* WriteLUT() */ |
63 | | /************************************************************************/ |
64 | | |
65 | | void CPCIDSK_LUT::WriteLUT(const std::vector<unsigned char>& lut) |
66 | | |
67 | 0 | { |
68 | 0 | if(lut.size() != 256) |
69 | 0 | { |
70 | 0 | throw PCIDSKException("LUT must contain 256 entries (%d given)", static_cast<int>(lut.size())); |
71 | 0 | } |
72 | | |
73 | 0 | PCIDSKBuffer seg_data; |
74 | |
|
75 | 0 | seg_data.SetSize(256*4); |
76 | |
|
77 | 0 | ReadFromFile( seg_data.buffer, 0, 256*4 ); |
78 | |
|
79 | 0 | int i; |
80 | 0 | for( i = 0; i < 256; i++ ) |
81 | 0 | { |
82 | 0 | seg_data.Put( (int) lut[i], i*4, 4); |
83 | 0 | } |
84 | |
|
85 | 0 | WriteToFile( seg_data.buffer, 0, 256*4 ); |
86 | 0 | } |