comparison Plugins/Samples/GdcmDecoder/GdcmDecoderCache.cpp @ 1837:fbc5522023aa

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 27 Nov 2015 17:56:16 +0100
parents 2faa2abbf311
children 859224214616
comparison
equal deleted inserted replaced
1836:2faa2abbf311 1837:fbc5522023aa
58 return result; 58 return result;
59 } 59 }
60 } 60 }
61 61
62 62
63 OrthancPluginImage* GdcmDecoderCache::Decode(OrthancPluginContext* context, 63 OrthancImageWrapper* GdcmDecoderCache::Decode(OrthancPluginContext* context,
64 const void* dicom, 64 const void* dicom,
65 const uint32_t size, 65 const uint32_t size,
66 uint32_t frameIndex) 66 uint32_t frameIndex)
67 { 67 {
68 std::string md5 = ComputeMd5(context, dicom, size); 68 std::string md5 = ComputeMd5(context, dicom, size);
69 69
70 // First check whether the previously decoded image is the same 70 // First check whether the previously decoded image is the same
71 // as this one 71 // as this one
75 if (decoder_.get() != NULL && 75 if (decoder_.get() != NULL &&
76 size_ == size && 76 size_ == size &&
77 md5_ == md5) 77 md5_ == md5)
78 { 78 {
79 // This is the same image: Reuse the previous decoding 79 // This is the same image: Reuse the previous decoding
80 return decoder_->Decode(context, frameIndex); 80 return new OrthancImageWrapper(context, *decoder_, frameIndex);
81 } 81 }
82 } 82 }
83 83
84 // This is not the same image 84 // This is not the same image
85 std::auto_ptr<GdcmImageDecoder> decoder(new GdcmImageDecoder(dicom, size)); 85 std::auto_ptr<GdcmImageDecoder> decoder(new GdcmImageDecoder(dicom, size));
86 OrthancImageWrapper image(context, *decoder, frameIndex); 86 std::auto_ptr<OrthancImageWrapper> image(new OrthancImageWrapper(context, *decoder, frameIndex));
87 87
88 { 88 {
89 // Cache the newly created decoder for further use 89 // Cache the newly created decoder for further use
90 boost::mutex::scoped_lock lock(mutex_); 90 boost::mutex::scoped_lock lock(mutex_);
91 decoder_ = decoder; 91 decoder_ = decoder;
92 size_ = size; 92 size_ = size;
93 md5_ = md5; 93 md5_ = md5;
94 } 94 }
95 95
96 return image.Release(); 96 return image.release();
97 } 97 }
98 } 98 }