Skip to content

Commit 72896bf

Browse files
committed
upgraded to vs 2013
fixed JPEG Decoder crash when run for long time
1 parent a8fa1c4 commit 72896bf

File tree

13 files changed

+287
-84
lines changed

13 files changed

+287
-84
lines changed

.nuget/NuGet.Config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<solution>
4+
<add key="disableSourceControlIntegration" value="true" />
5+
</solution>
6+
</configuration>

.nuget/NuGet.exe

1.59 MB
Binary file not shown.

.nuget/NuGet.targets

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>
5+
6+
<!-- Enable the restore command to run before builds -->
7+
<RestorePackages Condition=" '$(RestorePackages)' == '' ">false</RestorePackages>
8+
9+
<!-- Property that enables building a package from a project -->
10+
<BuildPackage Condition=" '$(BuildPackage)' == '' ">false</BuildPackage>
11+
12+
<!-- Determines if package restore consent is required to restore packages -->
13+
<RequireRestoreConsent Condition=" '$(RequireRestoreConsent)' != 'false' ">true</RequireRestoreConsent>
14+
15+
<!-- Download NuGet.exe if it does not already exist -->
16+
<DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">false</DownloadNuGetExe>
17+
</PropertyGroup>
18+
19+
<ItemGroup Condition=" '$(PackageSources)' == '' ">
20+
<!-- Package sources used to restore packages. By default, registered sources under %APPDATA%\NuGet\NuGet.Config will be used -->
21+
<!-- The official NuGet package source (https://www.nuget.org/api/v2/) will be excluded if package sources are specified and it does not appear in the list -->
22+
<!--
23+
<PackageSource Include="https://www.nuget.org/api/v2/" />
24+
<PackageSource Include="https://my-nuget-source/nuget/" />
25+
-->
26+
</ItemGroup>
27+
28+
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT'">
29+
<!-- Windows specific commands -->
30+
<NuGetToolsPath>$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))</NuGetToolsPath>
31+
</PropertyGroup>
32+
33+
<PropertyGroup Condition=" '$(OS)' != 'Windows_NT'">
34+
<!-- We need to launch nuget.exe with the mono command if we're not on windows -->
35+
<NuGetToolsPath>$(SolutionDir).nuget</NuGetToolsPath>
36+
</PropertyGroup>
37+
38+
<PropertyGroup>
39+
<PackagesProjectConfig Condition=" '$(OS)' == 'Windows_NT'">$(MSBuildProjectDirectory)\packages.$(MSBuildProjectName.Replace(' ', '_')).config</PackagesProjectConfig>
40+
<PackagesProjectConfig Condition=" '$(OS)' != 'Windows_NT'">$(MSBuildProjectDirectory)\packages.$(MSBuildProjectName).config</PackagesProjectConfig>
41+
</PropertyGroup>
42+
43+
<PropertyGroup>
44+
<PackagesConfig Condition="Exists('$(MSBuildProjectDirectory)\packages.config')">$(MSBuildProjectDirectory)\packages.config</PackagesConfig>
45+
<PackagesConfig Condition="Exists('$(PackagesProjectConfig)')">$(PackagesProjectConfig)</PackagesConfig>
46+
</PropertyGroup>
47+
48+
<PropertyGroup>
49+
<!-- NuGet command -->
50+
<NuGetExePath Condition=" '$(NuGetExePath)' == '' ">$(NuGetToolsPath)\NuGet.exe</NuGetExePath>
51+
<PackageSources Condition=" $(PackageSources) == '' ">@(PackageSource)</PackageSources>
52+
53+
<NuGetCommand Condition=" '$(OS)' == 'Windows_NT'">"$(NuGetExePath)"</NuGetCommand>
54+
<NuGetCommand Condition=" '$(OS)' != 'Windows_NT' ">mono --runtime=v4.0.30319 "$(NuGetExePath)"</NuGetCommand>
55+
56+
<PackageOutputDir Condition="$(PackageOutputDir) == ''">$(TargetDir.Trim('\\'))</PackageOutputDir>
57+
58+
<RequireConsentSwitch Condition=" $(RequireRestoreConsent) == 'true' ">-RequireConsent</RequireConsentSwitch>
59+
<NonInteractiveSwitch Condition=" '$(VisualStudioVersion)' != '' AND '$(OS)' == 'Windows_NT' ">-NonInteractive</NonInteractiveSwitch>
60+
61+
<PaddedSolutionDir Condition=" '$(OS)' == 'Windows_NT'">"$(SolutionDir) "</PaddedSolutionDir>
62+
<PaddedSolutionDir Condition=" '$(OS)' != 'Windows_NT' ">"$(SolutionDir)"</PaddedSolutionDir>
63+
64+
<!-- Commands -->
65+
<RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir $(PaddedSolutionDir)</RestoreCommand>
66+
<BuildCommand>$(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols</BuildCommand>
67+
68+
<!-- We need to ensure packages are restored prior to assembly resolve -->
69+
<BuildDependsOn Condition="$(RestorePackages) == 'true'">
70+
RestorePackages;
71+
$(BuildDependsOn);
72+
</BuildDependsOn>
73+
74+
<!-- Make the build depend on restore packages -->
75+
<BuildDependsOn Condition="$(BuildPackage) == 'true'">
76+
$(BuildDependsOn);
77+
BuildPackage;
78+
</BuildDependsOn>
79+
</PropertyGroup>
80+
81+
<Target Name="CheckPrerequisites">
82+
<!-- Raise an error if we're unable to locate nuget.exe -->
83+
<Error Condition="'$(DownloadNuGetExe)' != 'true' AND !Exists('$(NuGetExePath)')" Text="Unable to locate '$(NuGetExePath)'" />
84+
<!--
85+
Take advantage of MsBuild's build dependency tracking to make sure that we only ever download nuget.exe once.
86+
This effectively acts as a lock that makes sure that the download operation will only happen once and all
87+
parallel builds will have to wait for it to complete.
88+
-->
89+
<MsBuild Targets="_DownloadNuGet" Projects="$(MSBuildThisFileFullPath)" Properties="Configuration=NOT_IMPORTANT;DownloadNuGetExe=$(DownloadNuGetExe)" />
90+
</Target>
91+
92+
<Target Name="_DownloadNuGet">
93+
<DownloadNuGet OutputFilename="$(NuGetExePath)" Condition=" '$(DownloadNuGetExe)' == 'true' AND !Exists('$(NuGetExePath)')" />
94+
</Target>
95+
96+
<Target Name="RestorePackages" DependsOnTargets="CheckPrerequisites">
97+
<Exec Command="$(RestoreCommand)"
98+
Condition="'$(OS)' != 'Windows_NT' And Exists('$(PackagesConfig)')" />
99+
100+
<Exec Command="$(RestoreCommand)"
101+
LogStandardErrorAsError="true"
102+
Condition="'$(OS)' == 'Windows_NT' And Exists('$(PackagesConfig)')" />
103+
</Target>
104+
105+
<Target Name="BuildPackage" DependsOnTargets="CheckPrerequisites">
106+
<Exec Command="$(BuildCommand)"
107+
Condition=" '$(OS)' != 'Windows_NT' " />
108+
109+
<Exec Command="$(BuildCommand)"
110+
LogStandardErrorAsError="true"
111+
Condition=" '$(OS)' == 'Windows_NT' " />
112+
</Target>
113+
114+
<UsingTask TaskName="DownloadNuGet" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
115+
<ParameterGroup>
116+
<OutputFilename ParameterType="System.String" Required="true" />
117+
</ParameterGroup>
118+
<Task>
119+
<Reference Include="System.Core" />
120+
<Using Namespace="System" />
121+
<Using Namespace="System.IO" />
122+
<Using Namespace="System.Net" />
123+
<Using Namespace="Microsoft.Build.Framework" />
124+
<Using Namespace="Microsoft.Build.Utilities" />
125+
<Code Type="Fragment" Language="cs">
126+
<![CDATA[
127+
try {
128+
OutputFilename = Path.GetFullPath(OutputFilename);
129+
130+
Log.LogMessage("Downloading latest version of NuGet.exe...");
131+
WebClient webClient = new WebClient();
132+
webClient.DownloadFile("https://www.nuget.org/nuget.exe", OutputFilename);
133+
134+
return true;
135+
}
136+
catch (Exception ex) {
137+
Log.LogErrorFromException(ex);
138+
return false;
139+
}
140+
]]>
141+
</Code>
142+
</Task>
143+
</UsingTask>
144+
</Project>

ConsoleTest/ConsoleTest.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@
7373
<None Include="packages.config" />
7474
</ItemGroup>
7575
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
76+
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
77+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
78+
<PropertyGroup>
79+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
80+
</PropertyGroup>
81+
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
82+
</Target>
7683
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
7784
Other similar extension points exist, see Microsoft.Common.targets.
7885
<Target Name="BeforeBuild">

DICOM [Native]/Dicom.Imaging.Codec.Jpeg.i

Lines changed: 81 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -421,89 +421,98 @@ namespace IJGVERS {
421421

422422
void JPEGCODEC::Decode(DicomPixelData^ oldPixelData, DicomPixelData^ newPixelData, DicomJpegParams^ params, int frame) {
423423
PinnedByteArray^ jpegArray = gcnew PinnedByteArray(oldPixelData->GetFrame(frame)->Data);
424-
425-
jpeg_decompress_struct dinfo;
426-
memset(&dinfo, 0, sizeof(dinfo));
427-
428-
IJGVERS::SourceManagerStruct src;
429-
memset(&src, 0, sizeof(IJGVERS::SourceManagerStruct));
430-
src.pub.init_source = IJGVERS::initSource;
431-
src.pub.fill_input_buffer = IJGVERS::fillInputBuffer;
432-
src.pub.skip_input_data = IJGVERS::skipInputData;
433-
src.pub.resync_to_restart = jpeg_resync_to_restart;
434-
src.pub.term_source = IJGVERS::termSource;
435-
src.pub.bytes_in_buffer = 0;
436-
src.pub.next_input_byte = NULL;
437-
src.skip_bytes = 0;
438-
src.next_buffer = (unsigned char*)(void*)jpegArray->Pointer;
439-
src.next_buffer_size = (unsigned int*)jpegArray->ByteSize;
440-
441-
IJGVERS::ErrorStruct jerr;
442-
memset(&jerr, 0, sizeof(IJGVERS::ErrorStruct));
443-
dinfo.err = jpeg_std_error(&jerr.pub);
444-
jerr.pub.error_exit = IJGVERS::ErrorExit;
445-
jerr.pub.output_message = IJGVERS::OutputMessage;
424+
try{
425+
jpeg_decompress_struct dinfo;
426+
memset(&dinfo, 0, sizeof(dinfo));
427+
428+
IJGVERS::SourceManagerStruct src;
429+
memset(&src, 0, sizeof(IJGVERS::SourceManagerStruct));
430+
src.pub.init_source = IJGVERS::initSource;
431+
src.pub.fill_input_buffer = IJGVERS::fillInputBuffer;
432+
src.pub.skip_input_data = IJGVERS::skipInputData;
433+
src.pub.resync_to_restart = jpeg_resync_to_restart;
434+
src.pub.term_source = IJGVERS::termSource;
435+
src.pub.bytes_in_buffer = 0;
436+
src.pub.next_input_byte = NULL;
437+
src.skip_bytes = 0;
438+
src.next_buffer = (unsigned char*)(void*)jpegArray->Pointer;
439+
src.next_buffer_size = (unsigned int*)jpegArray->ByteSize;
440+
441+
IJGVERS::ErrorStruct jerr;
442+
memset(&jerr, 0, sizeof(IJGVERS::ErrorStruct));
443+
dinfo.err = jpeg_std_error(&jerr.pub);
444+
jerr.pub.error_exit = IJGVERS::ErrorExit;
445+
jerr.pub.output_message = IJGVERS::OutputMessage;
446446

447-
jpeg_create_decompress(&dinfo);
448-
dinfo.src = (jpeg_source_mgr*)&src.pub;
447+
jpeg_create_decompress(&dinfo);
448+
dinfo.src = (jpeg_source_mgr*)&src.pub;
449449

450-
if (jpeg_read_header(&dinfo, TRUE) == JPEG_SUSPENDED)
451-
throw gcnew DicomCodecException("Unable to decompress JPEG: Suspended");
450+
if (jpeg_read_header(&dinfo, TRUE) == JPEG_SUSPENDED)
451+
throw gcnew DicomCodecException("Unable to decompress JPEG: Suspended");
452+
453+
if (newPixelData->PhotometricInterpretation == PhotometricInterpretation::YbrFull422 || newPixelData->PhotometricInterpretation == PhotometricInterpretation::YbrPartial422)
454+
newPixelData->PhotometricInterpretation = PhotometricInterpretation::YbrFull;
455+
else
456+
newPixelData->PhotometricInterpretation = oldPixelData->PhotometricInterpretation;
457+
458+
if (params->ConvertColorspaceToRGB && (dinfo.out_color_space == JCS_YCbCr || dinfo.out_color_space == JCS_RGB)) {
459+
if (oldPixelData->PixelRepresentation == PixelRepresentation::Signed)
460+
throw gcnew DicomCodecException("JPEG codec unable to perform colorspace conversion on signed pixel data");
461+
//dinfo.jpeg_color_space = JCS_YCbCr;
462+
dinfo.out_color_space = JCS_RGB;
463+
newPixelData->PhotometricInterpretation = PhotometricInterpretation::Rgb;
464+
newPixelData->PlanarConfiguration = PlanarConfiguration::Interleaved;
465+
}
466+
else {
467+
dinfo.jpeg_color_space = JCS_UNKNOWN;
468+
dinfo.out_color_space = JCS_UNKNOWN;
469+
}
452470

453-
if (newPixelData->PhotometricInterpretation == PhotometricInterpretation::YbrFull422 || newPixelData->PhotometricInterpretation == PhotometricInterpretation::YbrPartial422)
454-
newPixelData->PhotometricInterpretation = PhotometricInterpretation::YbrFull;
455-
else
456-
newPixelData->PhotometricInterpretation = oldPixelData->PhotometricInterpretation;
457-
458-
if (params->ConvertColorspaceToRGB && (dinfo.out_color_space == JCS_YCbCr || dinfo.out_color_space == JCS_RGB)) {
459-
if (oldPixelData->PixelRepresentation == PixelRepresentation::Signed)
460-
throw gcnew DicomCodecException("JPEG codec unable to perform colorspace conversion on signed pixel data");
461-
//dinfo.jpeg_color_space = JCS_YCbCr;
462-
dinfo.out_color_space = JCS_RGB;
463-
newPixelData->PhotometricInterpretation = PhotometricInterpretation::Rgb;
464-
newPixelData->PlanarConfiguration = PlanarConfiguration::Interleaved;
465-
}
466-
else {
467-
dinfo.jpeg_color_space = JCS_UNKNOWN;
468-
dinfo.out_color_space = JCS_UNKNOWN;
469-
}
470-
471-
if (newPixelData->PhotometricInterpretation == PhotometricInterpretation::YbrFull)
472-
newPixelData->PlanarConfiguration = PlanarConfiguration::Planar;
471+
if (newPixelData->PhotometricInterpretation == PhotometricInterpretation::YbrFull)
472+
newPixelData->PlanarConfiguration = PlanarConfiguration::Planar;
473473

474-
jpeg_calc_output_dimensions(&dinfo);
475-
jpeg_start_decompress(&dinfo);
474+
jpeg_calc_output_dimensions(&dinfo);
475+
jpeg_start_decompress(&dinfo);
476476

477-
int rowSize = dinfo.output_width * dinfo.output_components * sizeof(JSAMPLE);
478-
int frameSize = rowSize * dinfo.output_height;
479-
if ((frameSize % 2) != 0)
480-
frameSize++;
477+
int rowSize = dinfo.output_width * dinfo.output_components * sizeof(JSAMPLE);
478+
int frameSize = rowSize * dinfo.output_height;
479+
if ((frameSize % 2) != 0)
480+
frameSize++;
481481

482-
PinnedByteArray^ frameArray = gcnew PinnedByteArray(frameSize);
483-
unsigned char* framePtr = (unsigned char*)(void*)frameArray->Pointer;
482+
PinnedByteArray^ frameArray = gcnew PinnedByteArray(frameSize);
483+
unsigned char* framePtr = (unsigned char*)(void*)frameArray->Pointer;
484484

485-
while (dinfo.output_scanline < dinfo.output_height) {
486-
int rows = jpeg_read_scanlines(&dinfo, (JSAMPARRAY)&framePtr, 1);
487-
framePtr += rows * rowSize;
488-
}
485+
while (dinfo.output_scanline < dinfo.output_height) {
486+
int rows = jpeg_read_scanlines(&dinfo, (JSAMPARRAY)&framePtr, 1);
487+
framePtr += rows * rowSize;
488+
}
489489

490-
jpeg_destroy_decompress(&dinfo);
490+
jpeg_destroy_decompress(&dinfo);
491491

492-
IByteBuffer^ buffer;
493-
if (frameArray->Count >= (1 * 1024 * 1024) || oldPixelData->NumberOfFrames > 1)
494-
buffer = gcnew TempFileBuffer(frameArray->Data);
495-
else
496-
buffer = gcnew MemoryByteBuffer(frameArray->Data);
497-
buffer = EvenLengthBuffer::Create(buffer);
498-
499-
if (newPixelData->PlanarConfiguration == PlanarConfiguration::Planar && newPixelData->SamplesPerPixel > 1) {
500-
if (oldPixelData->SamplesPerPixel != 3 || oldPixelData->BitsStored > 8)
501-
throw gcnew DicomCodecException("Planar reconfiguration only implemented for SamplesPerPixel=3 && BitsStores <= 8");
492+
IByteBuffer^ buffer;
493+
if (frameArray->Count >= (1 * 1024 * 1024) || oldPixelData->NumberOfFrames > 1)
494+
buffer = gcnew TempFileBuffer(frameArray->Data);
495+
else
496+
buffer = gcnew MemoryByteBuffer(frameArray->Data);
497+
buffer = EvenLengthBuffer::Create(buffer);
498+
499+
if (newPixelData->PlanarConfiguration == PlanarConfiguration::Planar && newPixelData->SamplesPerPixel > 1) {
500+
if (oldPixelData->SamplesPerPixel != 3 || oldPixelData->BitsStored > 8)
501+
throw gcnew DicomCodecException("Planar reconfiguration only implemented for SamplesPerPixel=3 && BitsStores <= 8");
502502

503-
buffer = PixelDataConverter::InterleavedToPlanar24(buffer);
504-
}
503+
buffer = PixelDataConverter::InterleavedToPlanar24(buffer);
504+
}
505505

506-
newPixelData->AddFrame(buffer);
506+
newPixelData->AddFrame(buffer);
507+
508+
delete frameArray;
509+
}
510+
finally{
511+
if(jpegArray != nullptr){
512+
delete jpegArray;
513+
jpegArray = nullptr;
514+
}
515+
}
507516
}
508517

509518
int JPEGCODEC::ScanHeaderForPrecision(DicomPixelData^ pixelData) {

DICOM [Native]/x64/DICOM [Native64].vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<UseDebugLibraries>false</UseDebugLibraries>
3131
<CLRSupport>true</CLRSupport>
3232
<CharacterSet>Unicode</CharacterSet>
33-
<PlatformToolset>v120</PlatformToolset>
33+
<PlatformToolset>v120_xp</PlatformToolset>
3434
</PropertyGroup>
3535
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
3636
<ImportGroup Label="ExtensionSettings">

DICOM [Native]/x86/DICOM [Native].vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<UseDebugLibraries>false</UseDebugLibraries>
3131
<CLRSupport>true</CLRSupport>
3232
<CharacterSet>Unicode</CharacterSet>
33-
<PlatformToolset>v120</PlatformToolset>
33+
<PlatformToolset>v120_xp</PlatformToolset>
3434
</PropertyGroup>
3535
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
3636
<ImportGroup Label="ExtensionSettings">

0 commit comments

Comments
 (0)