GDCM 3.2.1

CreateCMYKImage.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.cmyk
*/
#include "gdcmImageReader.h"
#include "gdcmSequenceOfFragments.h"
#include "gdcmSystem.h"
#include "gdcmImageWriter.h"
#include <iostream>
#include <fstream>
int main(int argc, char *argv[])
{
if( argc < 3 )
{
std::cerr << argv[0] << " input.cmyk 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::ImageWriter writer;
gdcm::Image &image = writer.GetImage();
image.SetNumberOfDimensions( 2 );
unsigned int dims[3] = {};
dims[0] = 380;
dims[1] = 287;
image.SetDimensions( dims );
gdcm::PixelFormat pf = gdcm::PixelFormat::UINT8;
pf.SetSamplesPerPixel( 4 );
image.SetPixelFormat( pf );
gdcm::PhotometricInterpretation pi = gdcm::PhotometricInterpretation::CMYK;
image.SetPhotometricInterpretation( pi );
image.SetTransferSyntax( gdcm::TransferSyntax::ExplicitVRLittleEndian );
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;
}
gdcm::Bitmap::SetNumberOfDimensions
void SetNumberOfDimensions(unsigned int dim)
gdcm::Bitmap::SetDimensions
void SetDimensions(const unsigned int dims[3])
gdcm::Bitmap::SetDataElement
void SetDataElement(DataElement const &de)
Definition gdcmBitmap.h:76
gdcm::Bitmap::SetTransferSyntax
void SetTransferSyntax(TransferSyntax const &ts)
Transfer syntax.
Definition gdcmBitmap.h:69
gdcm::Bitmap::SetPhotometricInterpretation
void SetPhotometricInterpretation(PhotometricInterpretation const &pi)
gdcm::Bitmap::SetPixelFormat
void SetPixelFormat(PixelFormat const &pf)
Definition gdcmBitmap.h:115
gdcm::DataElement
Class to represent a Data Element either Implicit or Explicit.
Definition gdcmDataElement.h:59
gdcm::DataElement::SetByteValue
void SetByteValue(const char *array, VL length)
Definition gdcmDataElement.h:126
gdcm::ImageWriter
ImageWriter.
Definition gdcmImageWriter.h:33
gdcm::ImageWriter::Write
bool Write() override
Write.
gdcm::ImageWriter::GetImage
const Image & GetImage() const override
Definition gdcmImageWriter.h:41
gdcm::Image
Image.
Definition gdcmImage.h:47
gdcm::PhotometricInterpretation
Class to represent an PhotometricInterpretation.
Definition gdcmPhotometricInterpretation.h:29
gdcm::PhotometricInterpretation::CMYK
@ CMYK
Definition gdcmPhotometricInterpretation.h:39
gdcm::PixelFormat
PixelFormat.
Definition gdcmPixelFormat.h:46
gdcm::PixelFormat::SetSamplesPerPixel
void SetSamplesPerPixel(unsigned short spp)
Definition gdcmPixelFormat.h:92
gdcm::PixelFormat::UINT8
@ UINT8
Definition gdcmPixelFormat.h:52
gdcm::System::FileSize
static size_t FileSize(const char *filename)
gdcm::Tag
Class to represent a DICOM Data Element (Attribute) Tag (Group, Element).
Definition gdcmTag.h:39
gdcm::TransferSyntax::ExplicitVRLittleEndian
@ ExplicitVRLittleEndian
Definition gdcmTransferSyntax.h:64
gdcm::Writer::SetFileName
void SetFileName(const char *filename_native)
Set the filename of DICOM file to write:
gdcmImageReader.h
gdcmImageWriter.h
gdcmSequenceOfFragments.h
gdcmSystem.h