Write JPEG image to stream

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
paolom
Posts: 169
Joined: Tue, 2008-09-16, 15:02

Write JPEG image to stream

#1 Post by paolom »

Hi,
I want to convert a Dicom Image to JPEG stream. To make this I'm trying to redirect the stdout to a stringstrem buffer, but it doesnt' work.

This is the code:

Code: Select all

std::stringstream out;
std::streambuf * old = std::cout.rdbuf();
std::cout.rdbuf(out.rdbuf());
DiJPEGPlugin plugin;
plugin.setQuality(OFstatic_cast(unsigned int, opt_quality));
plugin.setSampling(opt_sampling);
int result = di->writePluginFormat(&plugin, stdout, frameNumber);
std::cout.rdbuf(old);
The result is true, but the size of stringstream is 0.
I'm working under Windows. I think that the stdout is not correctly redirect to my buffer. Is it possible?

J. Riesmeier
DCMTK Developer
Posts: 2503
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: Write JPEG image to stream

#2 Post by J. Riesmeier »

As far as I remember, the standard output stream on Windows does not support binary information very well (or is at least by default not opened in binary mode).

However, there is a define that can be enabled for this purpose. The following excerpt is from "config/docs/macro.txt":

Code: Select all

USE_BINARY_MODE_FOR_STDOUT_ON_WINDOWS
  Affected: dcmdata
  Type of modification: Activates experimental or rarely used feature
  Explanation: On Windows systems, the standard output (stdout) is opened in
    text mode by default.  Therefore, the binary output of tools like dcm2pnm
    to stdout does not work correctly (in contrast to Unix systems).  When
    this preprocessor macro is defined, the binary mode is enabled for stdout.
    However, this causes newlines in the textual output to be converted to LF
    only (instead of CR LF which would be the usual translation for Windows).
My personal opinion is: Don't open "stdout" in binary mode (on Windows).

paolom
Posts: 169
Joined: Tue, 2008-09-16, 15:02

Re: Write JPEG image to stream

#3 Post by paolom »

So is it possible to make a JPEG to a standard file only? Not in memory?

J. Riesmeier
DCMTK Developer
Posts: 2503
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: Write JPEG image to stream

#4 Post by J. Riesmeier »

I guess this would require you to write a corresponding DiJPEGPlugin::write() method.

When we developed these output plugins, there was no need to create JPEG files in memory. I still see no reason for this.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 1 guest