GDCM 3.0.24
CreateARGBImage.cxx
/*=========================================================================
Program: GDCM (Grassroots DICOM). A DICOM library
Copyright (c) 2006-2011 Mathieu Malaterre
All rights reserved.
See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/*
* http://www.w3.org/Graphics/PNG/inline-alpha.html
* alphatest.png: PNG image data, 380 x 287, 8-bit/color RGBA, non-interlaced
*
* $ convert alphatest.png alphatest.rgba
*/
#include "gdcmSystem.h"
#include <iostream>
#include <fstream>
int main(int argc, char *argv[])
{
if( argc < 3 )
{
std::cerr << argv[0] << " input.rgba output.dcm" << std::endl;
return 1;
}
const char *filename = argv[1];
const char *outfilename = argv[2];
size_t len = gdcm::System::FileSize(filename);
std::ifstream is(filename, std::ios::binary);
char * buf = new char[len];
is.read(buf, len);
gdcm::Image &image = writer.GetImage();
unsigned int dims[3] = {};
dims[0] = 380;
dims[1] = 287;
image.SetDimensions( dims );
image.SetPixelFormat( pf );
gdcm::DataElement pixeldata( gdcm::Tag(0x7fe0,0x0010) );
pixeldata.SetByteValue( buf, (uint32_t)len );
image.SetDataElement( pixeldata );
writer.SetFileName( outfilename );
if( !writer.Write() )
{
return 1;
}
delete[] buf;
return 0;
}
void SetNumberOfDimensions(unsigned int dim)
void SetDimensions(const unsigned int dims[3])
void SetDataElement(DataElement const &de)
Definition gdcmBitmap.h:76
void SetTransferSyntax(TransferSyntax const &ts)
Transfer syntax.
Definition gdcmBitmap.h:69
void SetPhotometricInterpretation(PhotometricInterpretation const &pi)
void SetPixelFormat(PixelFormat const &pf)
Definition gdcmBitmap.h:115
Class to represent a Data Element either Implicit or Explicit.
Definition gdcmDataElement.h:59
void SetByteValue(const char *array, VL length)
Definition gdcmDataElement.h:126
ImageWriter.
Definition gdcmImageWriter.h:33
bool Write() override
Write.
const Image & GetImage() const override
Definition gdcmImageWriter.h:41
Image.
Definition gdcmImage.h:47
Class to represent an PhotometricInterpretation.
Definition gdcmPhotometricInterpretation.h:29
@ ARGB
Definition gdcmPhotometricInterpretation.h:38
PixelFormat.
Definition gdcmPixelFormat.h:46
void SetSamplesPerPixel(unsigned short spp)
Definition gdcmPixelFormat.h:92
@ UINT8
Definition gdcmPixelFormat.h:52
static size_t FileSize(const char *filename)
Class to represent a DICOM Data Element (Attribute) Tag (Group, Element).
Definition gdcmTag.h:39
@ ExplicitVRLittleEndian
Definition gdcmTransferSyntax.h:64
void SetFileName(const char *filename_native)
Set the filename of DICOM file to write: