re-compile dcmdjpeg.exe

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
zuoshulu
Posts: 7
Joined: Fri, 2009-06-12, 14:26

re-compile dcmdjpeg.exe

#1 Post by zuoshulu »

I am trying to re-compile dcmdjpeg.exe using dcmdjpeg.cxx. After compling, the executable binary file doesn't seem to work on the Jpeg compressed file that is generated by dcmcjpeg.exe.

However, the orignial dcmdpeg.exe in the executable binaries package from Home page works on the file I was testing.

DOS Command LOG
--------------------------------------
C:\68>dcmcjpeg test.ima t2.dcm

C:\68>dcmdjpeg t2.dcm t3.dcm

C:\68>DicomTest t2.dcm t3.dcm
Error: Illegal Call, perhaps wrong parameters: decompressing file: t2.dcm
---------------------------------------

Code: Select all

/*
 * CVS/RCS Log:
 * $Log: dcmdjpeg.cc,v $
 * Revision 1.13  2005/12/08 15:43:21  meichel
 * Changed include path schema for all DCMTK header files
 *
 * Revision 1.12  2005/12/02 09:41:40  joergr
 * Added new command line option that checks whether a given file starts with a
 * valid DICOM meta header.
 *
 * Revision 1.11  2005/11/30 14:10:43  onken
 * Added hint concerning --convert-never option when color conversion fails
 *
 * Revision 1.10  2005/11/07 17:10:21  meichel
 * All tools that both read and write a DICOM file now call loadAllDataIntoMemory()
 *   to make sure they do not destroy a file when output = input.
 *
 * Revision 1.9  2005/05/26 14:35:07  meichel
 * Added option --read-dataset to dcmdjpeg that allows to decompress JPEG
 *   compressed DICOM objects that have been stored as dataset without meta-header.
 *   Such a thing should not exist since the transfer syntax cannot be reliably
 *   determined without meta-header, but unfortunately it does.
 *
 * Revision 1.8  2004/01/16 14:28:01  joergr
 * Updated copyright header.
 *
 * Revision 1.7  2002/11/27 15:39:56  meichel
 * Adapted module dcmjpeg to use of new header file ofstdinc.h
 *
 * Revision 1.6  2002/11/26 08:44:41  meichel
 * Replaced all includes for "zlib.h" with <zlib.h>
 *   to avoid inclusion of zlib.h in the makefile dependencies.
 *
 * Revision 1.5  2002/09/23 18:14:07  joergr
 * Added new command line option "--version" which prints the name and version
 * number of external libraries used (incl. preparation for future support of
 * 'config.guess' host identifiers).
 *
 * Revision 1.4  2002/08/20 12:20:58  meichel
 * Adapted code to new loadFile and saveFile methods, thus removing direct
 *   use of the DICOM stream classes.
 *
 * Revision 1.3  2002/07/10 12:26:02  meichel
 * Fixed memory leak in command line applications
 *
 * Revision 1.2  2001/11/19 15:13:22  meichel
 * Introduced verbose mode in module dcmjpeg. If enabled, warning
 *   messages from the IJG library are printed on ofConsole, otherwise
 *   the library remains quiet.
 *
 * Revision 1.1  2001/11/13 15:56:10  meichel
 * Initial release of module dcmjpeg
 *
 *
 */



#include "dcmtk/config/osconfig.h"    /* make sure OS specific configuration is included first */

#define INCLUDE_CSTDLIB
#define INCLUDE_CSTDIO
#define INCLUDE_CSTRING
#include "dcmtk/ofstd/ofstdinc.h"

#ifdef HAVE_GUSI_H
#include <GUSI.h>
#endif

#include "dcmtk/dcmdata/dctk.h"
#include "dcmtk/dcmdata/dcdebug.h"
#include "dcmtk/dcmdata/cmdlnarg.h"
#include "dcmtk/ofstd/ofconapp.h"
#include "dcmtk/dcmdata/dcuid.h"       /* for dcmtk version name */
#include "dcmtk/dcmjpeg/djdecode.h"    /* for dcmjpeg decoders */
#include "dcmtk/dcmjpeg/dipijpeg.h"    /* for dcmimage JPEG plugin */

#include "dcmtk/dcmjpeg/djencode.h"  /* for dcmjpeg encoders */
#include "dcmtk/dcmjpeg/djrplol.h"   /* for DJ_RPLossless */
#include "dcmtk/dcmjpeg/djrploss.h"  /* for DJ_RPLossy */
//#include "dcmtk/dcmjpeg/dipijpeg.h"  /* for dcmimage JPEG plugin */
#include "dcmtk/dcmimage/diregist.h"  /* include to support color images */

#include "dcmtk/dcmdata/dcrledrg.h"  /* for DcmRLEDecoderRegistration */
#include "dcmtk/dcmdata/dcrleerg.h"  /* for DcmRLEEncoderRegistration */

#ifdef WITH_ZLIB
#include <zlib.h>      /* for zlibVersion() */
#endif

#define OFFIS_CONSOLE_APPLICATION "dcmdjpeg"

static char rcsid[] = "$dcmtk: " OFFIS_CONSOLE_APPLICATION " v"
  OFFIS_DCMTK_VERSION " " OFFIS_DCMTK_RELEASEDATE " $";

// ********************************************


#define SHORTCOL 4
#define LONGCOL 21

int main(int argc, char *argv[])
{

#ifdef HAVE_GUSI_H
  GUSISetup(GUSIwithSIOUXSockets);
  GUSISetup(GUSIwithInternetSockets);
#endif

  SetDebugLevel(( 0 ));

  const char *opt_ifname = NULL;
  const char *opt_ofname = NULL;

  int opt_debugMode = 0;
  OFBool opt_verbose = OFFalse;
  OFBool opt_oDataset = OFFalse;
  E_FileReadMode opt_readMode = ERM_autoDetect;
  E_TransferSyntax opt_oxfer = EXS_LittleEndianExplicit;
  E_GrpLenEncoding opt_oglenc = EGL_recalcGL;
  E_EncodingType opt_oenctype = EET_ExplicitLength;
  E_PaddingEncoding opt_opadenc = EPD_noChange;
  OFCmdUnsignedInt opt_filepad = 0;
  OFCmdUnsignedInt opt_itempad = 0;
  E_TransferSyntax opt_ixfer = EXS_Unknown;

  // JPEG parameters
  E_DecompressionColorSpaceConversion opt_decompCSconversion = EDC_photometricInterpretation;
  E_UIDCreation opt_uidcreation = EUC_default;
  E_PlanarConfiguration opt_planarconfig = EPC_default;

  OFConsoleApplication app(OFFIS_CONSOLE_APPLICATION , "Decode JPEG-compressed DICOM file", rcsid);
  OFCommandLine cmd;
  cmd.setOptionColumns(LONGCOL, SHORTCOL);
  cmd.setParamColumn(LONGCOL + SHORTCOL + 4);

  cmd.addParam("dcmfile-in",  "DICOM input filename to be converted");
  cmd.addParam("dcmfile-out", "DICOM output filename");

  cmd.addGroup("general options:", LONGCOL, SHORTCOL + 2);
   cmd.addOption("--help",                      "-h",        "print this help text and exit");
   cmd.addOption("--version",                                "print version information and exit", OFTrue /* exclusive */);
   cmd.addOption("--verbose",                   "-v",        "verbose mode, print processing details");
   cmd.addOption("--debug",                     "-d",        "debug mode, print debug information");

   cmd.addGroup("input options:");
    cmd.addSubGroup("input file format:");
     cmd.addOption("--read-file",              "+f",        "read file format or data set (default)");
     cmd.addOption("--read-file-only",         "+fo",       "read file format only");
     cmd.addOption("--read-dataset",           "-f",        "read data set without file meta information");

  cmd.addGroup("processing options:");
    cmd.addSubGroup("color space conversion options:");
      cmd.addOption("--conv-photometric",       "+cp",       "convert if YCbCr photom. interpr. (default)");
      cmd.addOption("--conv-lossy",             "+cl",       "convert YCbCr to RGB if lossy JPEG");
      cmd.addOption("--conv-always",            "+ca",       "always convert YCbCr to RGB");
      cmd.addOption("--conv-never",             "+cn",       "never convert color space");

    cmd.addSubGroup("planar configuration options:");
      cmd.addOption("--planar-auto",            "+pa",       "automatically determine planar configuration\nfrom SOP class and color space (default)");
      cmd.addOption("--color-by-pixel",         "+px",       "always store color-by-pixel");
      cmd.addOption("--color-by-plane",         "+pl",       "always store color-by-plane");

    cmd.addSubGroup("SOP Instance UID options:");
     cmd.addOption("--uid-default",        "+ud",     "keep same SOP Instance UID (default)");
     cmd.addOption("--uid-always",         "+ua",     "always assign new UID");

  cmd.addGroup("output options:");
    cmd.addSubGroup("output file format:");
      cmd.addOption("--write-file",             "+F",        "write file format (default)");
      cmd.addOption("--write-dataset",          "-F",        "write data set without file meta information");
    cmd.addSubGroup("output transfer syntax:");
      cmd.addOption("--write-xfer-little",      "+te",       "write with explicit VR little endian (default)");
      cmd.addOption("--write-xfer-big",         "+tb",       "write with explicit VR big endian TS");
      cmd.addOption("--write-xfer-implicit",    "+ti",       "write with implicit VR little endian TS");
    cmd.addSubGroup("post-1993 value representations:");
      cmd.addOption("--enable-new-vr",          "+u",        "enable support for new VRs (UN/UT) (default)");
      cmd.addOption("--disable-new-vr",         "-u",        "disable support for new VRs, convert to OB");
    cmd.addSubGroup("group length encoding:");
      cmd.addOption("--group-length-recalc",    "+g=",       "recalculate group lengths if present (default)");
      cmd.addOption("--group-length-create",    "+g",        "always write with group length elements");
      cmd.addOption("--group-length-remove",    "-g",        "always write without group length elements");
    cmd.addSubGroup("length encoding in sequences and items:");
      cmd.addOption("--length-explicit",        "+e",        "write with explicit lengths (default)");
      cmd.addOption("--length-undefined",       "-e",        "write with undefined lengths");
    cmd.addSubGroup("data set trailing padding (not with --write-dataset):");
      cmd.addOption("--padding-retain",         "-p=",       "do not change padding\n(default if not --write-dataset)");
      cmd.addOption("--padding-off",            "-p",        "no padding (implicit if --write-dataset)");
      cmd.addOption("--padding-create",         "+p",    2,  "[f]ile-pad [i]tem-pad: integer",
                                                             "align file on multiple of f bytes\nand items on multiple of i bytes");

    /* evaluate command line */
    prepareCmdLineArgs(argc, argv, OFFIS_CONSOLE_APPLICATION);
    if (app.parseCommandLine(cmd, argc, argv, OFCommandLine::ExpandWildcards))
    {
      /* check exclusive options first */

      if (cmd.getParamCount() == 0)
      {
          if (cmd.findOption("--version"))
          {
              app.printHeader(OFTrue /*print host identifier*/);          // uses ofConsole.lockCerr()
              CERR << endl << "External libraries used:" << endl;
#ifdef WITH_ZLIB
              CERR << "- ZLIB, Version " << zlibVersion() << endl;
#endif
              CERR << "- " << DiJPEGPlugin::getLibraryVersionString() << endl;
              return 0;
          }
      }

      /* command line parameters */

      cmd.getParam(1, opt_ifname);
      cmd.getParam(2, opt_ofname);

      /* options */

      if (cmd.findOption("--verbose")) opt_verbose = OFTrue;
      if (cmd.findOption("--debug")) opt_debugMode = 5;

      cmd.beginOptionBlock();
      if (cmd.findOption("--planar-auto")) opt_planarconfig = EPC_default;
      if (cmd.findOption("--color-by-pixel")) opt_planarconfig = EPC_colorByPixel;
      if (cmd.findOption("--color-by-plane")) opt_planarconfig = EPC_colorByPlane;
      cmd.endOptionBlock();

      cmd.beginOptionBlock();
      if (cmd.findOption("--conv-photometric"))  opt_decompCSconversion = EDC_photometricInterpretation;
      if (cmd.findOption("--conv-lossy"))        opt_decompCSconversion = EDC_lossyOnly;
      if (cmd.findOption("--conv-always"))       opt_decompCSconversion = EDC_always;
      if (cmd.findOption("--conv-never"))        opt_decompCSconversion = EDC_never;
      cmd.endOptionBlock();

      cmd.beginOptionBlock();
      if (cmd.findOption("--uid-default")) opt_uidcreation = EUC_default;
      if (cmd.findOption("--uid-always")) opt_uidcreation = EUC_always;
      cmd.endOptionBlock();

      cmd.beginOptionBlock();
      if (cmd.findOption("--read-file"))
      {
        opt_readMode = ERM_autoDetect;
        opt_ixfer = EXS_Unknown;
      }
      if (cmd.findOption("--read-file-only"))
      {
        opt_readMode = ERM_fileOnly;
        opt_ixfer = EXS_Unknown;
      }
      if (cmd.findOption("--read-dataset"))
      {
        opt_readMode = ERM_dataset;

        // we don't know the real transfer syntax of the dataset, but this does
        // not matter. As long as the content of encapsulated pixel sequences is
        // some kind of JPEG bitstream supported by the underlying library, the
        // decompression will work. So we simply choose one of the lossless
        // transfer syntaxes, because these support all bit depths up to 16.
        opt_ixfer = EXS_JPEGProcess14TransferSyntax;
      }
      cmd.endOptionBlock();

      cmd.beginOptionBlock();
      if (cmd.findOption("--write-file")) opt_oDataset = OFFalse;
      if (cmd.findOption("--write-dataset")) opt_oDataset = OFTrue;
      cmd.endOptionBlock();

      cmd.beginOptionBlock();
      if (cmd.findOption("--write-xfer-little")) opt_oxfer = EXS_LittleEndianExplicit;
      if (cmd.findOption("--write-xfer-big")) opt_oxfer = EXS_BigEndianExplicit;
      if (cmd.findOption("--write-xfer-implicit")) opt_oxfer = EXS_LittleEndianImplicit;
      cmd.endOptionBlock();

      cmd.beginOptionBlock();
      if (cmd.findOption("--enable-new-vr"))
      {
        dcmEnableUnknownVRGeneration.set(OFTrue);
        dcmEnableUnlimitedTextVRGeneration.set(OFTrue);
      }
      if (cmd.findOption("--disable-new-vr"))
      {
        dcmEnableUnknownVRGeneration.set(OFFalse);
        dcmEnableUnlimitedTextVRGeneration.set(OFFalse);
      }
      cmd.endOptionBlock();

      cmd.beginOptionBlock();
      if (cmd.findOption("--group-length-recalc")) opt_oglenc = EGL_recalcGL;
      if (cmd.findOption("--group-length-create")) opt_oglenc = EGL_withGL;
      if (cmd.findOption("--group-length-remove")) opt_oglenc = EGL_withoutGL;
      cmd.endOptionBlock();

      cmd.beginOptionBlock();
      if (cmd.findOption("--length-explicit")) opt_oenctype = EET_ExplicitLength;
      if (cmd.findOption("--length-undefined")) opt_oenctype = EET_UndefinedLength;
      cmd.endOptionBlock();

      cmd.beginOptionBlock();
      if (cmd.findOption("--padding-retain"))
      {
        if (opt_oDataset) app.printError("--padding-retain not allowed with --write-dataset");
        opt_opadenc = EPD_noChange;
      }
      if (cmd.findOption("--padding-off")) opt_opadenc = EPD_withoutPadding;
      if (cmd.findOption("--padding-create"))
      {
          if (opt_oDataset) app.printError("--padding-create not allowed with --write-dataset");
          app.checkValue(cmd.getValueAndCheckMin(opt_filepad, 0));
          app.checkValue(cmd.getValueAndCheckMin(opt_itempad, 0));
          opt_opadenc = EPD_withPadding;
      }
      cmd.endOptionBlock();

    }

    SetDebugLevel((opt_debugMode));

    // register global decompression codecs
    DJDecoderRegistration::registerCodecs(
      opt_decompCSconversion,
      opt_uidcreation,
      opt_planarconfig,
      opt_verbose);

    /* make sure data dictionary is loaded */
    if (!dcmDataDict.isDictionaryLoaded())
    {
        CERR << "Warning: no data dictionary loaded, "
             << "check environment variable: "
             << DCM_DICT_ENVIRONMENT_VARIABLE << endl;
    }

    // open inputfile
    if ((opt_ifname == NULL) || (strlen(opt_ifname) == 0))
    {
        CERR << "Error: invalid filename: <empty string>" << endl;
        return 1;
    }

    OFCondition error = EC_Normal;

    DcmFileFormat fileformat;

    if (opt_verbose)
        COUT << "reading input file " << opt_ifname << endl;

    error = fileformat.loadFile(opt_ifname, opt_ixfer, EGL_noChange, DCM_MaxReadLength, opt_readMode);
    if (error.bad())
    {
        CERR << "Error: "
             << error.text()
             << ": reading file: " <<  opt_ifname << endl;
        return 1;
    }

    DcmDataset *dataset = fileformat.getDataset();

    if (opt_verbose)
        COUT << "decompressing file" << endl;

    DcmXfer opt_oxferSyn(opt_oxfer);

    error = dataset->chooseRepresentation(opt_oxfer, NULL);
    if (error.bad())
    {
        CERR << "Error: "
             << error.text()
             << ": decompressing file: " <<  opt_ifname << endl;
       if (error == EJ_UnsupportedColorConversion)
           CERR << "Try --conv-never to disable color space conversion" << endl;
        return 1;
    }

    if (! dataset->canWriteXfer(opt_oxfer))
    {
        CERR << "Error: no conversion to transfer syntax " << opt_oxferSyn.getXferName()
             << " possible" << endl;
        return 1;
    }

    if (opt_verbose)
        COUT << "creating output file " << opt_ofname << endl;

    fileformat.loadAllDataIntoMemory();
	
	// My code
	const Uint16 *pixelData = NULL;
	unsigned long count = 0;

	if (dataset->findAndGetUint16Array(DCM_PixelData, pixelData, &count).good())
	{
		/* do something useful with the pixel data */

		int PixelPerFrame = 640*480*1.5;
		int num2hide = 32000;
		int currentPixel = 0;
		while(currentPixel<count) {
			memset((void*)(pixelData+currentPixel),0,32000*sizeof(Uint16));
			currentPixel = currentPixel + PixelPerFrame;
		}
		cout << count << endl;
		const unsigned long count2 = count;
		dataset->putAndInsertUint16Array(DCM_PixelData, pixelData, count2);

	}
    
	// end of My code
    error = fileformat.saveFile(opt_ofname, opt_oxfer, opt_oenctype, opt_oglenc,
              opt_opadenc, (Uint32) opt_filepad, (Uint32) opt_itempad, opt_oDataset);
    if (error != EC_Normal)
    {
        CERR << "Error: "
             << error.text()
             << ": writing file: " <<  opt_ofname << endl;
        return 1;
    }

    if (opt_verbose)
        COUT << "conversion successful" << endl;

    // deregister global decompression codecs
    DJDecoderRegistration::cleanup();

    return 0;
}
My system is VISTA64 + VC2008, DCMTK3.5.4.

Addional Depandenices:
------------------------------------
"C:\home\code\Library\dcmtk_crt_lib_vc2005\lib\debug\zlib_d.lib"
"C:\VC2008 Professional Edition\VC2008\PlatformSDK\Lib\NetAPI32.Lib"
"C:\VC2008 Professional Edition\VC2008\PlatformSDK\Lib\WSock32.Lib"
"C:\home\code\Library\dcmtk_crt_lib_vc2005\lib\debug\dcmdata.lib"
"C:\home\code\Library\dcmtk_crt_lib_vc2005\lib\debug\ofstd.lib"
"C:\home\code\Library\dcmtk_crt_lib_vc2005\lib\debug\dcmnet.lib"
"C:\home\code\Library\dcmtk_crt_lib_vc2005\lib\debug\dcmimage.lib"
"C:\home\code\Library\dcmtk_crt_lib_vc2005\lib\debug\dcmimgle.lib"
"C:\home\code\Library\dcmtk_crt_lib_vc2005\lib\debug\dcmjpeg.lib"
"C:\home\code\Library\dcmtk_crt_lib_vc2005\lib\debug\ijg8.lib"
"C:\home\code\Library\dcmtk_crt_lib_vc2005\lib\debug\ijg12.lib"
"C:\home\code\Library\dcmtk_crt_lib_vc2005\lib\debug\ijg16.lib"
------------------------------------------------------

Addional Include Directories
----------------------
C:\home\code\Library\dcmtk_crt_lib_vc2005\include
-----------------------------------

I have sucessfully compiled dcmcjpeg.cxx. dcmdrle.cxx, dcmcrle.cxx, can everyone tells what went wrong here? :?:

zuoshulu
Posts: 7
Joined: Fri, 2009-06-12, 14:26

#2 Post by zuoshulu »

Here is the compiler output
------ Build started: Project: dicomTest, Configuration: Debug Win32 ------
Compiling...
main.cpp
Linking...
LINK : C:\Users\GameWell\Documents\Visual Studio 2008\Projects\dicomTest\Debug\dicomTest.exe not found or not built by the last incremental link; performing full link
Creating library C:\Users\GameWell\Documents\Visual Studio 2008\Projects\dicomTest\Debug\dicomTest.lib and object C:\Users\GameWell\Documents\Visual Studio 2008\Projects\dicomTest\Debug\dicomTest.exp
MSVCRTD.lib(cinitexe.obj) : warning LNK4098: defaultlib 'libcmtd.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
Embedding manifest...
Build log was saved at "file://c:\Users\GameWell\Documents\Visual Studio 2008\Projects\dicomTest\dicomTest\Debug\BuildLog.htm"
dicomTest - 0 error(s), 1 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

Marco Eichelberg
OFFIS DICOM Team
OFFIS DICOM Team
Posts: 1444
Joined: Tue, 2004-11-02, 17:22
Location: Oldenburg, Germany
Contact:

#3 Post by Marco Eichelberg »

Seems that you have a code generation options problem. All code within a Win32 binary needs to be compiled with the same code generation options (/MT, /MD and their debug counterparts), otherwise you will see warning LNK4098 and funny things happen when the code tries to use the standard library.

zuoshulu
Posts: 7
Joined: Fri, 2009-06-12, 14:26

#4 Post by zuoshulu »

I tired to compile on Winxp+SP3 VC2005, I got the following error
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: class std::basic_ostream<char,struct std::char_traits<char> > & __thiscall std::basic_ostream<char,struct std::char_traits<char> >::operator<<(class std::basic_ostream<char,struct std::char_traits<char> > & (__cdecl*)(class std::basic_ostream<char,struct std::char_traits<char> > &))" (??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@P6AAAV01@AAV01@@Z@Z) already defined in main.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::endl(class std::basic_ostream<char,struct std::char_traits<char> > &)" (?endl@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@1@AAV21@@Z) already defined in main.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: void __thiscall std::basic_ios<char,struct std::char_traits<char> >::setstate(int,bool)" (?setstate@?$basic_ios@DU?$char_traits@D@std@@@std@@QAEXH_N@Z) already defined in main.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: int __thiscall std::ios_base::width(int)" (?width@ios_base@std@@QAEHH@Z) already defined in main.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: int __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::sputn(char const *,int)" (?sputn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEHPBDH@Z) already defined in main.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: static bool __cdecl std::char_traits<char>::eq_int_type(int const &,int const &)" (?eq_int_type@?$char_traits@D@std@@SA_NABH0@Z) already defined in main.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: static int __cdecl std::char_traits<char>::eof(void)" (?eof@?$char_traits@D@std@@SAHXZ) already defined in main.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: int __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::sputc(char)" (?sputc@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEHD@Z) already defined in main.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: class std::basic_streambuf<char,struct std::char_traits<char> > * __thiscall std::basic_ios<char,struct std::char_traits<char> >::rdbuf(void)const " (?rdbuf@?$basic_ios@DU?$char_traits@D@std@@@std@@QBEPAV?$basic_streambuf@DU?$char_traits@D@std@@@2@XZ) already defined in main.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: char __thiscall std::basic_ios<char,struct std::char_traits<char> >::fill(void)const " (?fill@?$basic_ios@DU?$char_traits@D@std@@@std@@QBEDXZ) already defined in main.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: int __thiscall std::ios_base::flags(void)const " (?flags@ios_base@std@@QBEHXZ) already defined in main.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: int __thiscall std::ios_base::width(void)const " (?width@ios_base@std@@QBEHXZ) already defined in main.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: static unsigned int __cdecl std::char_traits<char>::length(char const *)" (?length@?$char_traits@D@std@@SAIPBD@Z) already defined in main.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: class std::basic_ostream<char,struct std::char_traits<char> > & __thiscall std::basic_ostream<char,struct std::char_traits<char> >::flush(void)" (?flush@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV12@XZ) already defined in main.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: class std::basic_ostream<char,struct std::char_traits<char> > * __thiscall std::basic_ios<char,struct std::char_traits<char> >::tie(void)const " (?tie@?$basic_ios@DU?$char_traits@D@std@@@std@@QBEPAV?$basic_ostream@DU?$char_traits@D@std@@@2@XZ) already defined in main.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: bool __thiscall std::ios_base::good(void)const " (?good@ios_base@std@@QBE_NXZ) already defined in main.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: void __thiscall std::basic_ostream<char,struct std::char_traits<char> >::_Osfx(void)" (?_Osfx@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEXXZ) already defined in main.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "bool __cdecl std::uncaught_exception(void)" (?uncaught_exception@std@@YA_NXZ) already defined in libcpmt.lib(uncaught.obj)
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: void __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::_Lock(void)" (?_Lock@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEXXZ) already defined in main.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: void __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::_Unlock(void)" (?_Unlock@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEXXZ) already defined in main.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)" (??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ) already defined in main.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: char const * __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::c_str(void)const " (?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEPBDXZ) already defined in main.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: class std::basic_ostream<char,struct std::char_traits<char> > & __thiscall std::basic_ostream<char,struct std::char_traits<char> >::operator<<(unsigned long)" (??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@K@Z) already defined in main.obj
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: __wassert already defined in LIBCMT.lib(wassert.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _isalpha already defined in LIBCMT.lib(_ctype.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _sprintf already defined in LIBCMT.lib(sprintf.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _isspace already defined in LIBCMT.lib(_ctype.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _fclose already defined in LIBCMT.lib(fclose.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _fwrite already defined in LIBCMT.lib(fwrite.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _fopen already defined in LIBCMT.lib(fopen.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: __errno already defined in LIBCMT.lib(dosmap.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _ftell already defined in LIBCMT.lib(ftell.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _fseek already defined in LIBCMT.lib(fseek.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _strncmp already defined in LIBCMT.lib(strncmp.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _free already defined in LIBCMT.lib(free.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _malloc already defined in LIBCMT.lib(malloc.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _strchr already defined in LIBCMT.lib(strchr.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _getenv already defined in LIBCMT.lib(getenv.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _isupper already defined in LIBCMT.lib(_ctype.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _isdigit already defined in LIBCMT.lib(_ctype.obj)
MSVCRTD.lib(ti_inst.obj) : error LNK2005: "private: __thiscall type_info::type_info(class type_info const &)" (??0type_info@@AAE@ABV0@@Z) already defined in LIBCMT.lib(typinfo.obj)
MSVCRTD.lib(ti_inst.obj) : error LNK2005: "private: class type_info & __thiscall type_info::operator=(class type_info const &)" (??4type_info@@AAEAAV0@ABV0@@Z) already defined in LIBCMT.lib(typinfo.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: __access already defined in LIBCMT.lib(access.obj)
LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library
C:\Documents and Settings\luzo0000.US008\My Documents\Visual Studio 2005\Projects\dicomAnno\Debug\dicomAnno.exe : fatal error LNK1169: one or more multiply defined symbols found
If I use /force in Project Property Pages -> Linker -> Command Line I will be able to compile. Instead I get some warming
------ Build started: Project: dicomAnno, Configuration: Debug Win32 ------
Linking...
msvcprtd.lib(MSVCP80D.dll) : warning LNK4006: "public: class std::basic_ostream<char,struct std::char_traits<char> > & __thiscall std::basic_ostream<char,struct std::char_traits<char> >::operator<<(class std::basic_ostream<char,struct std::char_traits<char> > & (__cdecl*)(class std::basic_ostream<char,struct std::char_traits<char> > &))" (??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@P6AAAV01@AAV01@@Z@Z) already defined in main.obj; second definition ignored
msvcprtd.lib(MSVCP80D.dll) : warning LNK4006: "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::endl(class std::basic_ostream<char,struct std::char_traits<char> > &)" (?endl@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@1@AAV21@@Z) already defined in main.obj; second definition ignored
msvcprtd.lib(MSVCP80D.dll) : warning LNK4006: "public: void __thiscall std::basic_ios<char,struct std::char_traits<char> >::setstate(int,bool)" (?setstate@?$basic_ios@DU?$char_traits@D@std@@@std@@QAEXH_N@Z) already defined in main.obj; second definition ignored
msvcprtd.lib(MSVCP80D.dll) : warning LNK4006: "public: int __thiscall std::ios_base::width(int)" (?width@ios_base@std@@QAEHH@Z) already defined in main.obj; second definition ignored
msvcprtd.lib(MSVCP80D.dll) : warning LNK4006: "public: int __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::sputn(char const *,int)" (?sputn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEHPBDH@Z) already defined in main.obj; second definition ignored
msvcprtd.lib(MSVCP80D.dll) : warning LNK4006: "public: static bool __cdecl std::char_traits<char>::eq_int_type(int const &,int const &)" (?eq_int_type@?$char_traits@D@std@@SA_NABH0@Z) already defined in main.obj; second definition ignored
msvcprtd.lib(MSVCP80D.dll) : warning LNK4006: "public: static int __cdecl std::char_traits<char>::eof(void)" (?eof@?$char_traits@D@std@@SAHXZ) already defined in main.obj; second definition ignored
msvcprtd.lib(MSVCP80D.dll) : warning LNK4006: "public: int __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::sputc(char)" (?sputc@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEHD@Z) already defined in main.obj; second definition ignored
msvcprtd.lib(MSVCP80D.dll) : warning LNK4006: "public: class std::basic_streambuf<char,struct std::char_traits<char> > * __thiscall std::basic_ios<char,struct std::char_traits<char> >::rdbuf(void)const " (?rdbuf@?$basic_ios@DU?$char_traits@D@std@@@std@@QBEPAV?$basic_streambuf@DU?$char_traits@D@std@@@2@XZ) already defined in main.obj; second definition ignored
msvcprtd.lib(MSVCP80D.dll) : warning LNK4006: "public: char __thiscall std::basic_ios<char,struct std::char_traits<char> >::fill(void)const " (?fill@?$basic_ios@DU?$char_traits@D@std@@@std@@QBEDXZ) already defined in main.obj; second definition ignored
msvcprtd.lib(MSVCP80D.dll) : warning LNK4006: "public: int __thiscall std::ios_base::flags(void)const " (?flags@ios_base@std@@QBEHXZ) already defined in main.obj; second definition ignored
msvcprtd.lib(MSVCP80D.dll) : warning LNK4006: "public: int __thiscall std::ios_base::width(void)const " (?width@ios_base@std@@QBEHXZ) already defined in main.obj; second definition ignored
msvcprtd.lib(MSVCP80D.dll) : warning LNK4006: "public: static unsigned int __cdecl std::char_traits<char>::length(char const *)" (?length@?$char_traits@D@std@@SAIPBD@Z) already defined in main.obj; second definition ignored
msvcprtd.lib(MSVCP80D.dll) : warning LNK4006: "public: class std::basic_ostream<char,struct std::char_traits<char> > & __thiscall std::basic_ostream<char,struct std::char_traits<char> >::flush(void)" (?flush@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV12@XZ) already defined in main.obj; second definition ignored
msvcprtd.lib(MSVCP80D.dll) : warning LNK4006: "public: class std::basic_ostream<char,struct std::char_traits<char> > * __thiscall std::basic_ios<char,struct std::char_traits<char> >::tie(void)const " (?tie@?$basic_ios@DU?$char_traits@D@std@@@std@@QBEPAV?$basic_ostream@DU?$char_traits@D@std@@@2@XZ) already defined in main.obj; second definition ignored
msvcprtd.lib(MSVCP80D.dll) : warning LNK4006: "public: bool __thiscall std::ios_base::good(void)const " (?good@ios_base@std@@QBE_NXZ) already defined in main.obj; second definition ignored
msvcprtd.lib(MSVCP80D.dll) : warning LNK4006: "public: void __thiscall std::basic_ostream<char,struct std::char_traits<char> >::_Osfx(void)" (?_Osfx@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEXXZ) already defined in main.obj; second definition ignored
msvcprtd.lib(MSVCP80D.dll) : warning LNK4006: "bool __cdecl std::uncaught_exception(void)" (?uncaught_exception@std@@YA_NXZ) already defined in libcpmt.lib(uncaught.obj); second definition ignored
msvcprtd.lib(MSVCP80D.dll) : warning LNK4006: "public: void __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::_Lock(void)" (?_Lock@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEXXZ) already defined in main.obj; second definition ignored
msvcprtd.lib(MSVCP80D.dll) : warning LNK4006: "public: void __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::_Unlock(void)" (?_Unlock@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEXXZ) already defined in main.obj; second definition ignored
msvcprtd.lib(MSVCP80D.dll) : warning LNK4006: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)" (??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ) already defined in main.obj; second definition ignored
msvcprtd.lib(MSVCP80D.dll) : warning LNK4006: "public: char const * __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::c_str(void)const " (?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEPBDXZ) already defined in main.obj; second definition ignored
msvcprtd.lib(MSVCP80D.dll) : warning LNK4006: "public: class std::basic_ostream<char,struct std::char_traits<char> > & __thiscall std::basic_ostream<char,struct std::char_traits<char> >::operator<<(unsigned long)" (??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@K@Z) already defined in main.obj; second definition ignored
MSVCRTD.lib(MSVCR80D.dll) : warning LNK4006: __wassert already defined in LIBCMT.lib(wassert.obj); second definition ignored
MSVCRTD.lib(MSVCR80D.dll) : warning LNK4006: _isalpha already defined in LIBCMT.lib(_ctype.obj); second definition ignored
MSVCRTD.lib(MSVCR80D.dll) : warning LNK4006: _sprintf already defined in LIBCMT.lib(sprintf.obj); second definition ignored
MSVCRTD.lib(MSVCR80D.dll) : warning LNK4006: _isspace already defined in LIBCMT.lib(_ctype.obj); second definition ignored
MSVCRTD.lib(MSVCR80D.dll) : warning LNK4006: _fclose already defined in LIBCMT.lib(fclose.obj); second definition ignored
MSVCRTD.lib(MSVCR80D.dll) : warning LNK4006: _fwrite already defined in LIBCMT.lib(fwrite.obj); second definition ignored
MSVCRTD.lib(MSVCR80D.dll) : warning LNK4006: _fopen already defined in LIBCMT.lib(fopen.obj); second definition ignored
MSVCRTD.lib(MSVCR80D.dll) : warning LNK4006: __errno already defined in LIBCMT.lib(dosmap.obj); second definition ignored
MSVCRTD.lib(MSVCR80D.dll) : warning LNK4006: _ftell already defined in LIBCMT.lib(ftell.obj); second definition ignored
MSVCRTD.lib(MSVCR80D.dll) : warning LNK4006: _fseek already defined in LIBCMT.lib(fseek.obj); second definition ignored
MSVCRTD.lib(MSVCR80D.dll) : warning LNK4006: _strncmp already defined in LIBCMT.lib(strncmp.obj); second definition ignored
MSVCRTD.lib(MSVCR80D.dll) : warning LNK4006: _free already defined in LIBCMT.lib(free.obj); second definition ignored
MSVCRTD.lib(MSVCR80D.dll) : warning LNK4006: _malloc already defined in LIBCMT.lib(malloc.obj); second definition ignored
MSVCRTD.lib(MSVCR80D.dll) : warning LNK4006: _strchr already defined in LIBCMT.lib(strchr.obj); second definition ignored
MSVCRTD.lib(MSVCR80D.dll) : warning LNK4006: _getenv already defined in LIBCMT.lib(getenv.obj); second definition ignored
MSVCRTD.lib(MSVCR80D.dll) : warning LNK4006: _isupper already defined in LIBCMT.lib(_ctype.obj); second definition ignored
MSVCRTD.lib(MSVCR80D.dll) : warning LNK4006: _isdigit already defined in LIBCMT.lib(_ctype.obj); second definition ignored
MSVCRTD.lib(ti_inst.obj) : warning LNK4006: "private: __thiscall type_info::type_info(class type_info const &)" (??0type_info@@AAE@ABV0@@Z) already defined in LIBCMT.lib(typinfo.obj); second definition ignored
MSVCRTD.lib(ti_inst.obj) : warning LNK4006: "private: class type_info & __thiscall type_info::operator=(class type_info const &)" (??4type_info@@AAEAAV0@ABV0@@Z) already defined in LIBCMT.lib(typinfo.obj); second definition ignored
MSVCRTD.lib(MSVCR80D.dll) : warning LNK4006: __access already defined in LIBCMT.lib(access.obj); second definition ignored
LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library
C:\Documents and Settings\luzo0000.US008\My Documents\Visual Studio 2005\Projects\dicomAnno\Debug\dicomAnno.exe : warning LNK4088: image being generated due to /FORCE option; image may not run
Embedding manifest...
Build log was saved at "file://c:\Documents and Settings\luzo0000.US008\My Documents\Visual Studio 2005\Projects\dicomAnno\dicomAnno\Debug\BuildLog.htm"
dicomAnno - 0 error(s), 45 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
I tried Code Generation-> Runtime Library
Multi-threaded(/MT)
Multi-threaded DLL(/MD)
....

none of them work. can you please tell me what is the correct setting?

Marco Eichelberg
OFFIS DICOM Team
OFFIS DICOM Team
Posts: 1444
Joined: Tue, 2004-11-02, 17:22
Location: Oldenburg, Germany
Contact:

#5 Post by Marco Eichelberg »

See FAQ #26 and then check the code generation settings with which you compiled DCMTK. Usually this is /MT for Release builds and /MTd for Debug, but some newer versions of CMake seem to override this default when generating Visual Studio project files.

zuoshulu
Posts: 7
Joined: Fri, 2009-06-12, 14:26

#6 Post by zuoshulu »

I sucessfully compile dcmdjpeg.exe using the CMaker's project setting, thank you very much.

Now I tried to modify it as followes:

1. decompress JPEG baseline dicom file
2. modify the pixel data
3. compress the pixel data back to JPEG
4. save the file

I went through step 1-2 but my code stuck in step 3, I followed the encode/decode topic http://support.dcmtk.org/docs/mod_dcmjpeg.html

why the code below doesn't work?

Code: Select all

#include "dcmtk/config/osconfig.h"    /* make sure OS specific configuration is included first */

#define INCLUDE_CSTDLIB
#define INCLUDE_CSTDIO
#define INCLUDE_CSTRING
#include "dcmtk/ofstd/ofstdinc.h"

#ifdef HAVE_GUSI_H
#include <GUSI.h>
#endif

#include "dcmtk/dcmdata/dctk.h"
#include "dcmtk/dcmdata/dcdebug.h"
#include "dcmtk/dcmdata/cmdlnarg.h"
#include "dcmtk/ofstd/ofconapp.h"
#include "dcmtk/dcmdata/dcuid.h"       /* for dcmtk version name */
#include "dcmtk/dcmjpeg/djdecode.h"    /* for dcmjpeg decoders */
#include "dcmtk/dcmjpeg/dipijpeg.h"    /* for dcmimage JPEG plugin */

#include "dcmtk/dcmjpeg/djencode.h"  /* for dcmjpeg encoders */
#include "dcmtk/dcmjpeg/djrplol.h"   /* for DJ_RPLossless */
#include "dcmtk/dcmjpeg/djrploss.h"  /* for DJ_RPLossy */
//#include "dcmtk/dcmjpeg/dipijpeg.h"  /* for dcmimage JPEG plugin */
#include "dcmtk/dcmimage/diregist.h"  /* include to support color images */

#include "dcmtk/dcmdata/dcrledrg.h"  /* for DcmRLEDecoderRegistration */
#include "dcmtk/dcmdata/dcrleerg.h"  /* for DcmRLEEncoderRegistration */

#ifdef WITH_ZLIB
#include <zlib.h>      /* for zlibVersion() */
#endif

#define OFFIS_CONSOLE_APPLICATION "dcmdjpeg"

static char rcsid[] = "$dcmtk: " OFFIS_CONSOLE_APPLICATION " v"
  OFFIS_DCMTK_VERSION " " OFFIS_DCMTK_RELEASEDATE " $";

// ********************************************


#define SHORTCOL 4
#define LONGCOL 21

int main(int argc, char *argv[])
{

#ifdef HAVE_GUSI_H
  GUSISetup(GUSIwithSIOUXSockets);
  GUSISetup(GUSIwithInternetSockets);
#endif

  SetDebugLevel(( 0 ));

  const char *opt_ifname = NULL;
  const char *opt_ofname = NULL;

  int opt_debugMode = 0;
  OFBool opt_verbose = OFFalse;
  OFBool opt_oDataset = OFFalse;
  E_FileReadMode opt_readMode = ERM_autoDetect;
  E_TransferSyntax opt_oxfer = EXS_LittleEndianExplicit;
  E_GrpLenEncoding opt_oglenc = EGL_recalcGL;
  E_EncodingType opt_oenctype = EET_ExplicitLength;
  E_PaddingEncoding opt_opadenc = EPD_noChange;
  OFCmdUnsignedInt opt_filepad = 0;
  OFCmdUnsignedInt opt_itempad = 0;
  E_TransferSyntax opt_ixfer = EXS_Unknown;

  // JPEG parameters
  E_DecompressionColorSpaceConversion opt_decompCSconversion = EDC_photometricInterpretation;
  E_UIDCreation opt_uidcreation = EUC_default;
  E_PlanarConfiguration opt_planarconfig = EPC_default;

  OFConsoleApplication app(OFFIS_CONSOLE_APPLICATION , "Decode JPEG-compressed DICOM file", rcsid);
  OFCommandLine cmd;
  cmd.setOptionColumns(LONGCOL, SHORTCOL);
  cmd.setParamColumn(LONGCOL + SHORTCOL + 4);

  cmd.addParam("dcmfile-in",  "DICOM input filename to be converted");
  cmd.addParam("dcmfile-out", "DICOM output filename");

  cmd.addGroup("general options:", LONGCOL, SHORTCOL + 2);
   cmd.addOption("--help",                      "-h",        "print this help text and exit");
   cmd.addOption("--version",                                "print version information and exit", OFTrue /* exclusive */);
   cmd.addOption("--verbose",                   "-v",        "verbose mode, print processing details");
   cmd.addOption("--debug",                     "-d",        "debug mode, print debug information");

   cmd.addGroup("input options:");
    cmd.addSubGroup("input file format:");
     cmd.addOption("--read-file",              "+f",        "read file format or data set (default)");
     cmd.addOption("--read-file-only",         "+fo",       "read file format only");
     cmd.addOption("--read-dataset",           "-f",        "read data set without file meta information");

  cmd.addGroup("processing options:");
    cmd.addSubGroup("color space conversion options:");
      cmd.addOption("--conv-photometric",       "+cp",       "convert if YCbCr photom. interpr. (default)");
      cmd.addOption("--conv-lossy",             "+cl",       "convert YCbCr to RGB if lossy JPEG");
      cmd.addOption("--conv-always",            "+ca",       "always convert YCbCr to RGB");
      cmd.addOption("--conv-never",             "+cn",       "never convert color space");

    cmd.addSubGroup("planar configuration options:");
      cmd.addOption("--planar-auto",            "+pa",       "automatically determine planar configuration\nfrom SOP class and color space (default)");
      cmd.addOption("--color-by-pixel",         "+px",       "always store color-by-pixel");
      cmd.addOption("--color-by-plane",         "+pl",       "always store color-by-plane");

    cmd.addSubGroup("SOP Instance UID options:");
     cmd.addOption("--uid-default",        "+ud",     "keep same SOP Instance UID (default)");
     cmd.addOption("--uid-always",         "+ua",     "always assign new UID");

  cmd.addGroup("output options:");
    cmd.addSubGroup("output file format:");
      cmd.addOption("--write-file",             "+F",        "write file format (default)");
      cmd.addOption("--write-dataset",          "-F",        "write data set without file meta information");
    cmd.addSubGroup("output transfer syntax:");
      cmd.addOption("--write-xfer-little",      "+te",       "write with explicit VR little endian (default)");
      cmd.addOption("--write-xfer-big",         "+tb",       "write with explicit VR big endian TS");
      cmd.addOption("--write-xfer-implicit",    "+ti",       "write with implicit VR little endian TS");
    cmd.addSubGroup("post-1993 value representations:");
      cmd.addOption("--enable-new-vr",          "+u",        "enable support for new VRs (UN/UT) (default)");
      cmd.addOption("--disable-new-vr",         "-u",        "disable support for new VRs, convert to OB");
    cmd.addSubGroup("group length encoding:");
      cmd.addOption("--group-length-recalc",    "+g=",       "recalculate group lengths if present (default)");
      cmd.addOption("--group-length-create",    "+g",        "always write with group length elements");
      cmd.addOption("--group-length-remove",    "-g",        "always write without group length elements");
    cmd.addSubGroup("length encoding in sequences and items:");
      cmd.addOption("--length-explicit",        "+e",        "write with explicit lengths (default)");
      cmd.addOption("--length-undefined",       "-e",        "write with undefined lengths");
    cmd.addSubGroup("data set trailing padding (not with --write-dataset):");
      cmd.addOption("--padding-retain",         "-p=",       "do not change padding\n(default if not --write-dataset)");
      cmd.addOption("--padding-off",            "-p",        "no padding (implicit if --write-dataset)");
      cmd.addOption("--padding-create",         "+p",    2,  "[f]ile-pad [i]tem-pad: integer",
                                                             "align file on multiple of f bytes\nand items on multiple of i bytes");

    /* evaluate command line */
    prepareCmdLineArgs(argc, argv, OFFIS_CONSOLE_APPLICATION);
    if (app.parseCommandLine(cmd, argc, argv, OFCommandLine::ExpandWildcards))
    {
      /* check exclusive options first */

      if (cmd.getParamCount() == 0)
      {
          if (cmd.findOption("--version"))
          {
              app.printHeader(OFTrue /*print host identifier*/);          // uses ofConsole.lockCerr()
              CERR << endl << "External libraries used:" << endl;
#ifdef WITH_ZLIB
              CERR << "- ZLIB, Version " << zlibVersion() << endl;
#endif
              CERR << "- " << DiJPEGPlugin::getLibraryVersionString() << endl;
              return 0;
          }
      }

      /* command line parameters */

      cmd.getParam(1, opt_ifname);
      cmd.getParam(2, opt_ofname);

      /* options */

      if (cmd.findOption("--verbose")) opt_verbose = OFTrue;
      if (cmd.findOption("--debug")) opt_debugMode = 5;

      cmd.beginOptionBlock();
      if (cmd.findOption("--planar-auto")) opt_planarconfig = EPC_default;
      if (cmd.findOption("--color-by-pixel")) opt_planarconfig = EPC_colorByPixel;
      if (cmd.findOption("--color-by-plane")) opt_planarconfig = EPC_colorByPlane;
      cmd.endOptionBlock();

      cmd.beginOptionBlock();
      if (cmd.findOption("--conv-photometric"))  opt_decompCSconversion = EDC_photometricInterpretation;
      if (cmd.findOption("--conv-lossy"))        opt_decompCSconversion = EDC_lossyOnly;
      if (cmd.findOption("--conv-always"))       opt_decompCSconversion = EDC_always;
      if (cmd.findOption("--conv-never"))        opt_decompCSconversion = EDC_never;
      cmd.endOptionBlock();

      cmd.beginOptionBlock();
      if (cmd.findOption("--uid-default")) opt_uidcreation = EUC_default;
      if (cmd.findOption("--uid-always")) opt_uidcreation = EUC_always;
      cmd.endOptionBlock();

      cmd.beginOptionBlock();
      if (cmd.findOption("--read-file"))
      {
        opt_readMode = ERM_autoDetect;
        opt_ixfer = EXS_Unknown;
      }
      if (cmd.findOption("--read-file-only"))
      {
        opt_readMode = ERM_fileOnly;
        opt_ixfer = EXS_Unknown;
      }
      if (cmd.findOption("--read-dataset"))
      {
        opt_readMode = ERM_dataset;

        // we don't know the real transfer syntax of the dataset, but this does
        // not matter. As long as the content of encapsulated pixel sequences is
        // some kind of JPEG bitstream supported by the underlying library, the
        // decompression will work. So we simply choose one of the lossless
        // transfer syntaxes, because these support all bit depths up to 16.
        opt_ixfer = EXS_JPEGProcess14TransferSyntax;
      }
      cmd.endOptionBlock();

      cmd.beginOptionBlock();
      if (cmd.findOption("--write-file")) opt_oDataset = OFFalse;
      if (cmd.findOption("--write-dataset")) opt_oDataset = OFTrue;
      cmd.endOptionBlock();

      cmd.beginOptionBlock();
      if (cmd.findOption("--write-xfer-little")) opt_oxfer = EXS_LittleEndianExplicit;
      if (cmd.findOption("--write-xfer-big")) opt_oxfer = EXS_BigEndianExplicit;
      if (cmd.findOption("--write-xfer-implicit")) opt_oxfer = EXS_LittleEndianImplicit;
      cmd.endOptionBlock();

      cmd.beginOptionBlock();
      if (cmd.findOption("--enable-new-vr"))
      {
        dcmEnableUnknownVRGeneration.set(OFTrue);
        dcmEnableUnlimitedTextVRGeneration.set(OFTrue);
      }
      if (cmd.findOption("--disable-new-vr"))
      {
        dcmEnableUnknownVRGeneration.set(OFFalse);
        dcmEnableUnlimitedTextVRGeneration.set(OFFalse);
      }
      cmd.endOptionBlock();

      cmd.beginOptionBlock();
      if (cmd.findOption("--group-length-recalc")) opt_oglenc = EGL_recalcGL;
      if (cmd.findOption("--group-length-create")) opt_oglenc = EGL_withGL;
      if (cmd.findOption("--group-length-remove")) opt_oglenc = EGL_withoutGL;
      cmd.endOptionBlock();

      cmd.beginOptionBlock();
      if (cmd.findOption("--length-explicit")) opt_oenctype = EET_ExplicitLength;
      if (cmd.findOption("--length-undefined")) opt_oenctype = EET_UndefinedLength;
      cmd.endOptionBlock();

      cmd.beginOptionBlock();
      if (cmd.findOption("--padding-retain"))
      {
        if (opt_oDataset) app.printError("--padding-retain not allowed with --write-dataset");
        opt_opadenc = EPD_noChange;
      }
      if (cmd.findOption("--padding-off")) opt_opadenc = EPD_withoutPadding;
      if (cmd.findOption("--padding-create"))
      {
          if (opt_oDataset) app.printError("--padding-create not allowed with --write-dataset");
          app.checkValue(cmd.getValueAndCheckMin(opt_filepad, 0));
          app.checkValue(cmd.getValueAndCheckMin(opt_itempad, 0));
          opt_opadenc = EPD_withPadding;
      }
      cmd.endOptionBlock();

    }

    SetDebugLevel((opt_debugMode));

    // register global decompression codecs
    DJDecoderRegistration::registerCodecs(
      opt_decompCSconversion,
      opt_uidcreation,
      opt_planarconfig,
      opt_verbose);

    /* make sure data dictionary is loaded */
    if (!dcmDataDict.isDictionaryLoaded())
    {
        CERR << "Warning: no data dictionary loaded, "
             << "check environment variable: "
             << DCM_DICT_ENVIRONMENT_VARIABLE << endl;
    }

    // open inputfile
    if ((opt_ifname == NULL) || (strlen(opt_ifname) == 0))
    {
        CERR << "Error: invalid filename: <empty string>" << endl;
        return 1;
    }

    OFCondition error = EC_Normal;

    DcmFileFormat fileformat;

    if (opt_verbose)
        COUT << "reading input file " << opt_ifname << endl;

    error = fileformat.loadFile(opt_ifname, opt_ixfer, EGL_noChange, DCM_MaxReadLength, opt_readMode);
    if (error.bad())
    {
        CERR << "Error: "
             << error.text()
             << ": reading file: " <<  opt_ifname << endl;
        return 1;
    }

    DcmDataset *dataset = fileformat.getDataset();

    if (opt_verbose)
        COUT << "decompressing file" << endl;

    DcmXfer opt_oxferSyn(opt_oxfer);

    error = dataset->chooseRepresentation(opt_oxfer, NULL);
    if (error.bad())
    {
        CERR << "Error: "
             << error.text()
             << ": decompressing file: " <<  opt_ifname << endl;
       if (error == EJ_UnsupportedColorConversion)
           CERR << "Try --conv-never to disable color space conversion" << endl;
        return 1;
    }

    if (! dataset->canWriteXfer(opt_oxfer))
    {
        CERR << "Error: no conversion to transfer syntax " << opt_oxferSyn.getXferName()
             << " possible" << endl;
        return 1;
    }

    if (opt_verbose)
        COUT << "creating output file " << opt_ofname << endl;

	fileformat.loadAllDataIntoMemory();

	const Uint16 *pixelData = NULL;
	unsigned long count = 0;

	if (dataset->findAndGetUint16Array(DCM_PixelData, pixelData, &count).good())
	{
		/* do something useful with the pixel data */

		int PixelPerFrame = 640*480*1.5;
		int num2hide = 32000;
		int currentPixel = 0;
		while(currentPixel<count) {
			memset((void*)(pixelData+currentPixel),0,32000*sizeof(Uint16));
			currentPixel = currentPixel + PixelPerFrame;
		}
		cout << count << endl;
		const unsigned long count2 = count;
		dataset->putAndInsertUint16Array(DCM_PixelData, pixelData, count2);
		

	}
    
	DcmItem *metaInfo = fileformat.getMetaInfo();
	DJ_RPLossless params; // codec parameters, we use the defaults

	// this causes the lossless JPEG version of the dataset to be created
	dataset->chooseRepresentation(EXS_JPEGProcess14SV1TransferSyntax, &params);

	// check if everything went well
	if (dataset->canWriteXfer(EXS_JPEGProcess14SV1TransferSyntax))
	{
		// force the meta-header UIDs to be re-generated when storing the file 
		// since the UIDs in the data set may have changed 
		delete metaInfo->remove(DCM_MediaStorageSOPClassUID);
		delete metaInfo->remove(DCM_MediaStorageSOPInstanceUID);

		// store in lossless JPEG format
		fileformat.saveFile(opt_ofname, EXS_JPEGProcess14SV1TransferSyntax);
	}

    //error = fileformat.saveFile(opt_ofname, EXS_JPEGProcess14SV1TransferSyntax, opt_oenctype, opt_oglenc,
    //          opt_opadenc, (Uint32) opt_filepad, (Uint32) opt_itempad, opt_oDataset);
    if (error != EC_Normal)
    {
        CERR << "Error: "
             << error.text()
             << ": writing file: " <<  opt_ofname << endl;
        return 1;
    }

    if (opt_verbose)
        COUT << "conversion successful" << endl;

    // deregister global decompression codecs
    DJDecoderRegistration::cleanup();
	DJEncoderRegistration::cleanup();

    return 0;
}

Michael Onken
DCMTK Developer
Posts: 2049
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:

#7 Post by Michael Onken »

Hi,

I did not check your code thoroughly (we cannot compile and debug your code!), but I miss the registering of the JPEG compressor. Look into dcmcjpeg which compresses DICOM files, it calls

Code: Select all

   // register global compression codecs
    DJEncoderRegistration::registerCodecs(
      opt_compCSconversion,
      opt_uidcreation,
      opt_verbose,
      opt_huffmanOptimize,
      (int) opt_smoothing,
      opt_compressedBits,
      (Uint32) opt_fragmentSize,
      opt_createOffsetTable,
      opt_sampleFactors,
      opt_useYBR422,
      opt_secondarycapture,
      opt_windowType,
      opt_windowParameter,
      opt_windowCenter,
      opt_windowWidth,
      opt_roiLeft,
      opt_roiTop,
      opt_roiWidth,
      opt_roiHeight,
      opt_usePixelValues,
      opt_useModalityRescale,
      opt_acceptWrongPaletteTags,
      opt_acrNemaCompatibility,
      opt_trueLossless);
Regards,
Michael

zuoshulu
Posts: 7
Joined: Fri, 2009-06-12, 14:26

#8 Post by zuoshulu »

wow, it works now, thank you, I am wondering if dcmcjpeg.exe 's JPEG BaseLine compress parameter is +eb.

I tried EXS_JPEGProcess1TransferSyntax for JPEG BaseLine compression in my code, but the output is not the same(quality and file size) as dcmcjpeg +eb, what is the correct parameter in the code?

Michael Onken
DCMTK Developer
Posts: 2049
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:

#9 Post by Michael Onken »

Hi,
I tried EXS_JPEGProcess1TransferSyntax for JPEG BaseLine compression in my code, but the output is not the same(quality and file size) as dcmcjpeg +eb, what is the correct parameter in the code?
Hm, you should easily be able to see that from the code: Play around with the codec parameters -- just look at dcmcjpeg's command line parameters and how they are handled in dcmcjpeg's source code for controlling the codec.

Regards,
Michael

Post Reply

Who is online

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