vil_nitf2: Written by Rob Radtke (rob@) and Harry Voorhees (hlv@) of Stellar Science Ltd. More...
#include <vil/vil_blocked_image_resource.h>
#include <vcl_vector.h>
#include <vcl_cassert.h>
#include <vil/vil_stream.h>
#include "vil_nitf2_image_subheader.h"
#include "vil_nitf2_header.h"
#include <vil/vil_file_format.h>
Go to the source code of this file.
Classes | |
class | vil_nitf2_file_format |
class | vil_nitf2_image |
Class for reading NITF 2.1 imagery files. More... | |
Functions | |
template<class T > | |
T | get_bits (const T *in_val, unsigned int i0, unsigned int ni) |
This function does a lot of work for. | |
template<class T > | |
T * | byte_align_data (T *in_data, unsigned int num_samples, unsigned int in_bits_per_sample, T *out_data) |
This function will byte align the data in in_data and store the result in out_data. | |
template<> | |
bool * | byte_align_data< bool > (bool *in_data, unsigned int num_samples, unsigned int in_bits_per_sample, bool *out_data) |
vil_nitf2: Written by Rob Radtke (rob@) and Harry Voorhees (hlv@) of Stellar Science Ltd.
Co. (stellarscience.com) for Air Force Research Laboratory, 2005.
Definition in file vil_nitf2_image.h.
T* byte_align_data | ( | T * | in_data, |
unsigned int | num_samples, | ||
unsigned int | in_bits_per_sample, | ||
T * | out_data | ||
) |
This function will byte align the data in in_data and store the result in out_data.
For example, let's say that you had in_data is of type unsigned char and contains the following data: 110010111001111010000110. In other words: in_data[0] = 203 (11001011) in_data[1] = 158 (10011110) in_data[2] = 134 (10000110) Let's further say you called this function like this: byte_align_data( in_data, 8, 3, out_data ). Then, when the function finished, out_data would look like this: out_data[0] = 6 (00000110) out_data[1] = 2 (00000010) out_data[2] = 7 (00000111) out_data[3] = 1 (00000001) out_data[4] = 7 (00000111) out_data[5] = 2 (00000010) out_data[6] = 0 (00000000) out_data[7] = 6 (00000110)
Basically, what the function did was group the bitstream into groups of three and then store all of the values into out_data. It had to zero pad all the values (on the MSB side) to get them into out_data. That's why out_data is bigger.
This function works with other unsigned types of data too. For example, let's say in_data was of type unsigned int and contained the following bits: 0100110010111000 0111101100000000 1111000011110000 (note that this bitstream is shown in big endian notation, that will not be the case if you are on a little endian machine -- this is just for illustration) in other words: in_data[0] = 19640 (0100110010111000) [shown in big endian for illustrative purposes only] in_data[1] = 31488 (0111101100000000) [shown in big endian for illustrative purposes only] in_data[2] = 61680 (1111000011110000) [shown in big endian for illustrative purposes only] Let's further say, you called this function like this byte_align_data( in_data, 4, 12, out_data ). Then out_data would be aligned along two byte (sixteen bit) boundaries and would look like this: out_data[0] = 1227 (0000010011001011) [shown in big endian for illustrative purposes only] out_data[1] = 2171 (0000100001111011) [shown in big endian for illustrative purposes only] out_data[2] = 15 (0000000000001111) [shown in big endian for illustrative purposes only] out_data[3] = 240 (0000000011110000) [shown in big endian for illustrative purposes only]
Because of the fact that this function uses bit shifting operators, and the behavior of the vcl_right shift operator is implementation specific when applied to a negative number, you should probably only use this function on unsigned data.
in_data,: | The input data. It must be at least (num_samples*in_bits_per_sample\8) bytes long. The values should have the endianness of your platform. |
num_samples,: | The number of actual samples in in_data. |
in_bits_per_sample,: | The bits per sample in in_data |
out_data,: | I'll store the output data here. It must be at least (num_samples*sizeof(T)) bytes long The values will have the endianness of your platform. |
Note that inBitsPerSampe must not be >= sizeof(T). If they were to be equal, then this function would have nothing to do (in_data is already byte aligned). If in_bits_per_sample were less than sizeof(T), then each element of out_data would be too small to store the corresponding elements in in_data.
Note that there is a specialization for the bool case which just casts it to an 8 bit quantity then calls this same function. This is because the logic in get_bits<> doesn't work for the bool case.
Definition at line 317 of file vil_nitf2_image.h.
bool* byte_align_data< bool > | ( | bool * | in_data, |
unsigned int | num_samples, | ||
unsigned int | in_bits_per_sample, | ||
bool * | out_data | ||
) |
Definition at line 788 of file vil_nitf2_image.cxx.
T get_bits | ( | const T * | in_val, |
unsigned int | i0, | ||
unsigned int | ni | ||
) |
This function does a lot of work for.
i0,: | Offset (in bits - not bytes) from in_val[0]. This will be the start of the bits extracted from in_val. |
ni,: | number of bits (starting from i0) that will be extracted from in_val. |
Definition at line 234 of file vil_nitf2_image.h.