-
Notifications
You must be signed in to change notification settings - Fork 6
/
gdcm_wrapper.cc
60 lines (54 loc) · 2.04 KB
/
gdcm_wrapper.cc
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
#include "gdcmImageReader.h"
#include "gdcmImage.h"
#include "wrapper.h"
using namespace std;
struct PixelDataInternal c_decode_frames(
char **i_buffer_ptr,
size_t *i_buffer_lens,
size_t i_buffer_len,
u_int32_t dims[3],
u_int32_t pi_type,
u_int32_t ts_type,
u_int16_t samples_per_pixel,
u_int16_t bits_allocated,
u_int16_t bits_stored,
u_int16_t high_bit,
u_int16_t pixel_representation)
{
// Create fragment
// We need a SmartPointer because of a GDCM bug
// https://sourceforge.net/p/gdcm/mailman/gdcm-developers/thread/CB8517FD.82C8%25mkazanov%40gmail.com/
gdcm::SmartPointer<gdcm::SequenceOfFragments> fragments = new gdcm::SequenceOfFragments();
for (size_t i_buffer_idx = 0; i_buffer_idx < i_buffer_len; ++i_buffer_idx)
{
gdcm::Fragment fragment = gdcm::Fragment();
fragment.SetByteValue(i_buffer_ptr[i_buffer_idx], gdcm::VL(i_buffer_lens[i_buffer_idx]));
fragments->AddFragment(fragment);
}
// Create encapsulating DataElement
gdcm::DataElement data_element = gdcm::DataElement(gdcm::Tag(0x7fe0, 0x0010));
data_element.SetValue(*fragments);
// TODO: Move this to a method
gdcm::Image image = gdcm::Image();
image.SetNumberOfDimensions(3);
image.SetDimensions(dims);
image.SetDataElement(data_element);
image.SetPhotometricInterpretation(gdcm::PhotometricInterpretation(gdcm::PhotometricInterpretation::PIType(pi_type)));
image.SetTransferSyntax(gdcm::TransferSyntax(gdcm::TransferSyntax::TSType(ts_type)));
image.SetPixelFormat(gdcm::PixelFormat(samples_per_pixel, bits_allocated, bits_stored, high_bit, pixel_representation));
struct PixelDataInternal outputStruct;
size_t length = image.GetBufferLength();
outputStruct.buffer = (char *)malloc(length);
if (!image.GetBuffer(outputStruct.buffer))
{
outputStruct.status = 1;
return outputStruct;
}
outputStruct.size = length;
outputStruct.status = 0;
return outputStruct;
}
void c_free_buffer(char *buffer_ptr)
{
free(buffer_ptr);
}