Changeset 5633 for pjproject/trunk/third_party/yuv/source/mjpeg_decoder.cc
- Timestamp:
- Jul 28, 2017 2:51:44 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/third_party/yuv/source/mjpeg_decoder.cc
r5358 r5633 14 14 #include <assert.h> 15 15 16 #ifdef __cplusplus 17 #include <new> 18 #endif 19 16 20 #if !defined(__pnacl__) && !defined(__CLR_VER) && \ 17 21 !defined(COVERAGE_ENABLED) && !defined(TARGET_IPHONE_SIMULATOR) … … 22 26 #if defined(_MSC_VER) 23 27 // disable warning 4324: structure was padded due to __declspec(align()) 24 #pragma warning(disable :4324)28 #pragma warning(disable : 4324) 25 29 #endif 26 30 … … 63 67 void term_source(jpeg_decompress_struct* cinfo); 64 68 void ErrorHandler(jpeg_common_struct* cinfo); 69 void OutputHandler(jpeg_common_struct* cinfo); 65 70 66 71 MJpegDecoder::MJpegDecoder() … … 78 83 // Override standard exit()-based error handler. 79 84 error_mgr_->base.error_exit = &ErrorHandler; 85 error_mgr_->base.output_message = &OutputHandler; 80 86 #endif 81 87 decompress_struct_->client_data = NULL; … … 128 134 delete scanlines_[i]; 129 135 } 130 scanlines_[i] = new uint8* 136 scanlines_[i] = new uint8*[scanlines_size]; 131 137 scanlines_sizes_[i] = scanlines_size; 132 138 } … … 194 200 195 201 int MJpegDecoder::GetHorizSubSampFactor(int component) { 196 return decompress_struct_->max_h_samp_factor / 197 GetHorizSampFactor(component); 202 return decompress_struct_->max_h_samp_factor / GetHorizSampFactor(component); 198 203 } 199 204 200 205 int MJpegDecoder::GetVertSubSampFactor(int component) { 201 return decompress_struct_->max_v_samp_factor / 202 GetVertSampFactor(component); 206 return decompress_struct_->max_v_samp_factor / GetVertSampFactor(component); 203 207 } 204 208 … … 244 248 245 249 // TODO(fbarchard): Allow rectangle to be specified: x, y, width, height. 246 LIBYUV_BOOL MJpegDecoder::DecodeToBuffers( 247 uint8** planes, int dst_width, int dst_height) {248 if (dst_width != GetWidth() ||249 250 LIBYUV_BOOL MJpegDecoder::DecodeToBuffers(uint8** planes, 251 int dst_width, 252 int dst_height) { 253 if (dst_width != GetWidth() || dst_height > GetHeight()) { 250 254 // ERROR: Bad dimensions 251 255 return LIBYUV_FALSE; … … 288 292 // TODO(fbarchard): Compute skip to avoid this 289 293 assert(skip % GetVertSubSampFactor(i) == 0); 290 int rows_to_skip = 291 DivideAndRoundDown(skip, GetVertSubSampFactor(i)); 292 int scanlines_to_copy = GetComponentScanlinesPerImcuRow(i) - 293 rows_to_skip; 294 int rows_to_skip = DivideAndRoundDown(skip, GetVertSubSampFactor(i)); 295 int scanlines_to_copy = 296 GetComponentScanlinesPerImcuRow(i) - rows_to_skip; 294 297 int data_to_skip = rows_to_skip * GetComponentStride(i); 295 CopyPlane(databuf_[i] + data_to_skip, GetComponentStride(i), 296 planes[i], GetComponentWidth(i),297 GetComponentWidth(i),scanlines_to_copy);298 CopyPlane(databuf_[i] + data_to_skip, GetComponentStride(i), planes[i], 299 GetComponentWidth(i), GetComponentWidth(i), 300 scanlines_to_copy); 298 301 planes[i] += scanlines_to_copy * GetComponentWidth(i); 299 302 } … … 304 307 // Read full MCUs but cropped horizontally 305 308 for (; lines_left > GetImageScanlinesPerImcuRow(); 306 309 lines_left -= GetImageScanlinesPerImcuRow()) { 307 310 if (!DecodeImcuRow()) { 308 311 FinishDecode(); … … 311 314 for (int i = 0; i < num_outbufs_; ++i) { 312 315 int scanlines_to_copy = GetComponentScanlinesPerImcuRow(i); 313 CopyPlane(databuf_[i], GetComponentStride(i), 314 planes[i], GetComponentWidth(i), 315 GetComponentWidth(i), scanlines_to_copy); 316 CopyPlane(databuf_[i], GetComponentStride(i), planes[i], 317 GetComponentWidth(i), GetComponentWidth(i), scanlines_to_copy); 316 318 planes[i] += scanlines_to_copy * GetComponentWidth(i); 317 319 } … … 327 329 int scanlines_to_copy = 328 330 DivideAndRoundUp(lines_left, GetVertSubSampFactor(i)); 329 CopyPlane(databuf_[i], GetComponentStride(i), 330 planes[i], GetComponentWidth(i), 331 GetComponentWidth(i), scanlines_to_copy); 331 CopyPlane(databuf_[i], GetComponentStride(i), planes[i], 332 GetComponentWidth(i), GetComponentWidth(i), scanlines_to_copy); 332 333 planes[i] += scanlines_to_copy * GetComponentWidth(i); 333 334 } … … 336 337 } 337 338 338 LIBYUV_BOOL MJpegDecoder::DecodeToCallback(CallbackFunction fn, void* opaque, 339 int dst_width, int dst_height) { 340 if (dst_width != GetWidth() || 341 dst_height > GetHeight()) { 339 LIBYUV_BOOL MJpegDecoder::DecodeToCallback(CallbackFunction fn, 340 void* opaque, 341 int dst_width, 342 int dst_height) { 343 if (dst_width != GetWidth() || dst_height > GetHeight()) { 342 344 // ERROR: Bad dimensions 343 345 return LIBYUV_FALSE; … … 394 396 // Read full MCUs until we get to the crop point. 395 397 for (; lines_left >= GetImageScanlinesPerImcuRow(); 396 398 lines_left -= GetImageScanlinesPerImcuRow()) { 397 399 if (!DecodeImcuRow()) { 398 400 FinishDecode(); … … 434 436 435 437 void term_source(j_decompress_ptr cinfo) { 436 // Nothing to do.438 (void)cinfo; // Nothing to do. 437 439 } 438 440 439 441 #ifdef HAVE_SETJMP 440 442 void ErrorHandler(j_common_ptr cinfo) { 441 442 443 444 445 446 447 443 // This is called when a jpeglib command experiences an error. Unfortunately 444 // jpeglib's error handling model is not very flexible, because it expects the 445 // error handler to not return--i.e., it wants the program to terminate. To 446 // recover from errors we use setjmp() as shown in their example. setjmp() is 447 // C's implementation for the "call with current continuation" functionality 448 // seen in some functional programming languages. 449 // A formatted message can be output, but is unsafe for release. 448 450 #ifdef DEBUG 449 451 char buf[JMSG_LENGTH_MAX]; 450 452 (*cinfo->err->format_message)(cinfo, buf); 451 453 // ERROR: Error in jpeglib: buf 452 454 #endif 453 455 … … 457 459 longjmp(mgr->setjmp_buffer, 1); 458 460 } 459 #endif 461 462 // Suppress fprintf warnings. 463 void OutputHandler(j_common_ptr cinfo) { 464 (void)cinfo; 465 } 466 467 #endif // HAVE_SETJMP 460 468 461 469 void MJpegDecoder::AllocOutputBuffers(int num_outbufs) { … … 466 474 DestroyOutputBuffers(); 467 475 468 scanlines_ = new uint8** 476 scanlines_ = new uint8**[num_outbufs]; 469 477 scanlines_sizes_ = new int[num_outbufs]; 470 databuf_ = new uint8* 478 databuf_ = new uint8*[num_outbufs]; 471 479 databuf_strides_ = new int[num_outbufs]; 472 480 … … 484 492 void MJpegDecoder::DestroyOutputBuffers() { 485 493 for (int i = 0; i < num_outbufs_; ++i) { 486 delete 487 delete 488 } 489 delete 490 delete 491 delete 492 delete 494 delete[] scanlines_[i]; 495 delete[] databuf_[i]; 496 } 497 delete[] scanlines_; 498 delete[] databuf_; 499 delete[] scanlines_sizes_; 500 delete[] databuf_strides_; 493 501 scanlines_ = NULL; 494 502 databuf_ = NULL; … … 536 544 inline LIBYUV_BOOL MJpegDecoder::DecodeImcuRow() { 537 545 return (unsigned int)(GetImageScanlinesPerImcuRow()) == 538 jpeg_read_raw_data(decompress_struct_, 539 scanlines_, 540 GetImageScanlinesPerImcuRow()); 546 jpeg_read_raw_data(decompress_struct_, scanlines_, 547 GetImageScanlinesPerImcuRow()); 541 548 } 542 549 543 550 // The helper function which recognizes the jpeg sub-sampling type. 544 551 JpegSubsamplingType MJpegDecoder::JpegSubsamplingTypeHelper( 545 int* subsample_x, int* subsample_y, int number_of_components) { 552 int* subsample_x, 553 int* subsample_y, 554 int number_of_components) { 546 555 if (number_of_components == 3) { // Color images. 547 if (subsample_x[0] == 1 && subsample_y[0] == 1 && 548 subsample_x[1] == 2 && subsample_y[1] == 2 && 549 subsample_x[2] == 2 && subsample_y[2] == 2) { 556 if (subsample_x[0] == 1 && subsample_y[0] == 1 && subsample_x[1] == 2 && 557 subsample_y[1] == 2 && subsample_x[2] == 2 && subsample_y[2] == 2) { 550 558 return kJpegYuv420; 551 559 } else if (subsample_x[0] == 1 && subsample_y[0] == 1 && 552 subsample_x[1] == 2 && subsample_y[1] == 1 &&553 subsample_x[2] == 2 && subsample_y[2] == 1) {560 subsample_x[1] == 2 && subsample_y[1] == 1 && 561 subsample_x[2] == 2 && subsample_y[2] == 1) { 554 562 return kJpegYuv422; 555 563 } else if (subsample_x[0] == 1 && subsample_y[0] == 1 && 556 subsample_x[1] == 1 && subsample_y[1] == 1 &&557 subsample_x[2] == 1 && subsample_y[2] == 1) {564 subsample_x[1] == 1 && subsample_y[1] == 1 && 565 subsample_x[2] == 1 && subsample_y[2] == 1) { 558 566 return kJpegYuv444; 559 567 } … … 568 576 } // namespace libyuv 569 577 #endif // HAVE_JPEG 570
Note: See TracChangeset
for help on using the changeset viewer.