int main(int, char *[])
{
char * buffer = new char[ 256 * 256 *3 ];
char * p = buffer;
for(int row = 0; row < 256; ++row)
{
for(int col = 0; col < 256; ++col)
{
*p++ = 255;
*p++ = 0;
*p++ = 0;
}
}
const char mystr[] = "RGB";
uint16_t row1 = 256;
uint16_t col1 = 256;
std::ofstream of;
of.open( "output.dcm", std::ios::out | std::ios::binary );
delete [] buffer;
std::cout << "Not able to write";
return 0;
}
else
std::cout<<"\nabletoread";
std::cerr << "unable to write image information" << std::endl;
delete [] buffer;
return 1;
}
std::vector<unsigned int> extent =
unsigned short xmax = extent[0];
unsigned short ymax = extent[1];
unsigned short theChunkSize = 1;
unsigned short ychunk = extent[1]/theChunkSize;
unsigned short zmax = extent[2];
std::cout << xmax << ymax << zmax;
if (xmax == 0 || ymax == 0)
{
std::cerr << "Image has no size, unable to write zero-sized image." << std::endl;
return 0;
}
int z, y, nexty;
unsigned long prevLen = 0;
for (z = 0; z < zmax; ++z){
for (y = 0; y < ymax; y += ychunk){
nexty = y + ychunk;
if (nexty > ymax) nexty = ymax;
std::cout << "\n" <<len;
char* finalBuffer = new char[len];
memcpy(finalBuffer, &(buffer[prevLen]), len);
std::cout << "\nable to write";
if (!theStreamWriter.
Write(finalBuffer, len)){
std::cerr << "writing failure:" << "output.dcm" << " at y = " << y << " and z= " << z << std::endl;
delete [] buffer;
delete [] finalBuffer;
return 1;
}
delete [] finalBuffer;
prevLen += len;
}
}
delete buffer;
uint16_t firstTag1 = 0xfffe;
uint16_t secondTag1 = 0xe0dd;
uint32_t thirdTag1 = 0x00000000;
const int theBufferSize1 = 2*sizeof(uint16_t)+sizeof(uint32_t);
char* tmpBuffer2 = new char[theBufferSize1];
memcpy(&(tmpBuffer2[0]), &firstTag1, sizeof(uint16_t));
memcpy(&(tmpBuffer2[sizeof(uint16_t)]), &secondTag1, sizeof(uint16_t));
memcpy(&(tmpBuffer2[2*sizeof(uint16_t)]), &thirdTag1, sizeof(uint32_t));
assert( of && !of.eof() && of.good() );
of.write(tmpBuffer2, theBufferSize1);
of.flush();
assert( of );
return 0;
}