Mercurial > hg > orthanc
comparison OrthancServer/OrthancRestApi/OrthancRestResources.cpp @ 1824:b530c3dfe2a6
refactoring image decoding
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 25 Nov 2015 14:14:32 +0100 |
parents | 2dbf25006f88 |
children | ac5b0b4e2434 |
comparison
equal
deleted
inserted
replaced
1823:0ef4e6e66b56 | 1824:b530c3dfe2a6 |
---|---|
37 #include "../../Core/HttpServer/HttpContentNegociation.h" | 37 #include "../../Core/HttpServer/HttpContentNegociation.h" |
38 #include "../ServerToolbox.h" | 38 #include "../ServerToolbox.h" |
39 #include "../FromDcmtkBridge.h" | 39 #include "../FromDcmtkBridge.h" |
40 #include "../ServerContext.h" | 40 #include "../ServerContext.h" |
41 #include "../SliceOrdering.h" | 41 #include "../SliceOrdering.h" |
42 #include "../Internals/DicomImageDecoder.h" | |
42 | 43 |
43 | 44 |
44 namespace Orthanc | 45 namespace Orthanc |
45 { | 46 { |
46 // List all the patients, studies, series or instances ---------------------- | 47 // List all the patients, studies, series or instances ---------------------- |
263 namespace | 264 namespace |
264 { | 265 { |
265 class ImageToEncode | 266 class ImageToEncode |
266 { | 267 { |
267 private: | 268 private: |
269 IDicomImageDecoder& decoder_; | |
268 std::string format_; | 270 std::string format_; |
269 std::string encoded_; | 271 std::string encoded_; |
270 ParsedDicomFile& dicom_; | 272 ParsedDicomFile& dicom_; |
271 unsigned int frame_; | 273 unsigned int frame_; |
272 ImageExtractionMode mode_; | 274 ImageExtractionMode mode_; |
273 | 275 |
274 public: | 276 public: |
275 ImageToEncode(ParsedDicomFile& dicom, | 277 ImageToEncode(IDicomImageDecoder& decoder, |
278 ParsedDicomFile& dicom, | |
276 unsigned int frame, | 279 unsigned int frame, |
277 ImageExtractionMode mode) : | 280 ImageExtractionMode mode) : |
281 decoder_(decoder), | |
278 dicom_(dicom), | 282 dicom_(dicom), |
279 frame_(frame), | 283 frame_(frame), |
280 mode_(mode) | 284 mode_(mode) |
281 { | 285 { |
282 } | 286 } |
308 | 312 |
309 void Answer(RestApiOutput& output) | 313 void Answer(RestApiOutput& output) |
310 { | 314 { |
311 output.AnswerBuffer(encoded_, format_); | 315 output.AnswerBuffer(encoded_, format_); |
312 } | 316 } |
317 | |
318 IDicomImageDecoder& GetDecoder() const | |
319 { | |
320 return decoder_; | |
321 } | |
313 }; | 322 }; |
314 | 323 |
315 class EncodePng : public HttpContentNegociation::IHandler | 324 class EncodePng : public HttpContentNegociation::IHandler |
316 { | 325 { |
317 private: | 326 private: |
325 virtual void Handle(const std::string& type, | 334 virtual void Handle(const std::string& type, |
326 const std::string& subtype) | 335 const std::string& subtype) |
327 { | 336 { |
328 assert(type == "image"); | 337 assert(type == "image"); |
329 assert(subtype == "png"); | 338 assert(subtype == "png"); |
330 image_.GetDicom().ExtractPngImage(image_.GetTarget(), image_.GetFrame(), image_.GetMode()); | 339 image_.GetDicom().ExtractPngImage(image_.GetTarget(), image_.GetDecoder(), |
340 image_.GetFrame(), image_.GetMode()); | |
331 image_.SetFormat("image/png"); | 341 image_.SetFormat("image/png"); |
332 } | 342 } |
333 }; | 343 }; |
334 | 344 |
335 class EncodeJpeg : public HttpContentNegociation::IHandler | 345 class EncodeJpeg : public HttpContentNegociation::IHandler |
365 virtual void Handle(const std::string& type, | 375 virtual void Handle(const std::string& type, |
366 const std::string& subtype) | 376 const std::string& subtype) |
367 { | 377 { |
368 assert(type == "image"); | 378 assert(type == "image"); |
369 assert(subtype == "jpeg"); | 379 assert(subtype == "jpeg"); |
370 image_.GetDicom().ExtractJpegImage(image_.GetTarget(), image_.GetFrame(), image_.GetMode(), quality_); | 380 image_.GetDicom().ExtractJpegImage(image_.GetTarget(), image_.GetDecoder(), |
381 image_.GetFrame(), image_.GetMode(), quality_); | |
371 image_.SetFormat("image/jpeg"); | 382 image_.SetFormat("image/jpeg"); |
372 } | 383 } |
373 }; | 384 }; |
374 } | 385 } |
375 | 386 |
397 | 408 |
398 ParsedDicomFile dicom(dicomContent); | 409 ParsedDicomFile dicom(dicomContent); |
399 | 410 |
400 try | 411 try |
401 { | 412 { |
402 ImageToEncode image(dicom, frame, mode); | 413 DicomImageDecoder decoder; // TODO plugins |
414 ImageToEncode image(decoder, dicom, frame, mode); | |
403 | 415 |
404 HttpContentNegociation negociation; | 416 HttpContentNegociation negociation; |
405 EncodePng png(image); negociation.Register("image/png", png); | 417 EncodePng png(image); negociation.Register("image/png", png); |
406 EncodeJpeg jpeg(image, call); negociation.Register("image/jpeg", jpeg); | 418 EncodeJpeg jpeg(image, call); negociation.Register("image/jpeg", jpeg); |
407 | 419 |
451 std::string dicomContent; | 463 std::string dicomContent; |
452 context.ReadFile(dicomContent, publicId, FileContentType_Dicom); | 464 context.ReadFile(dicomContent, publicId, FileContentType_Dicom); |
453 | 465 |
454 ParsedDicomFile dicom(dicomContent); | 466 ParsedDicomFile dicom(dicomContent); |
455 ImageBuffer buffer; | 467 ImageBuffer buffer; |
456 dicom.ExtractImage(buffer, frame); | 468 DicomImageDecoder decoder; // TODO plugin |
469 dicom.ExtractImage(buffer, decoder, frame); | |
457 | 470 |
458 ImageAccessor accessor(buffer.GetConstAccessor()); | 471 ImageAccessor accessor(buffer.GetConstAccessor()); |
459 | 472 |
460 std::string result; | 473 std::string result; |
461 accessor.ToMatlabString(result); | 474 accessor.ToMatlabString(result); |