| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include <setjmp.h> | 7 #include <setjmp.h> |
| 8 | 8 |
| 9 #include "../../../include/fxcodec/fx_codec.h" | 9 #include "../../../include/fxcodec/fx_codec.h" |
| 10 #include "../../../include/fxcrt/fx_safe_types.h" | 10 #include "../../../include/fxcrt/fx_safe_types.h" |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 class CCodec_JpegDecoder : public CCodec_ScanlineDecoder { | 289 class CCodec_JpegDecoder : public CCodec_ScanlineDecoder { |
| 290 public: | 290 public: |
| 291 CCodec_JpegDecoder(); | 291 CCodec_JpegDecoder(); |
| 292 ~CCodec_JpegDecoder() override; | 292 ~CCodec_JpegDecoder() override; |
| 293 | 293 |
| 294 FX_BOOL Create(const uint8_t* src_buf, | 294 FX_BOOL Create(const uint8_t* src_buf, |
| 295 FX_DWORD src_size, | 295 FX_DWORD src_size, |
| 296 int width, | 296 int width, |
| 297 int height, | 297 int height, |
| 298 int nComps, | 298 int nComps, |
| 299 FX_BOOL ColorTransform, | 299 FX_BOOL ColorTransform); |
| 300 IFX_JpegProvider* pJP); | |
| 301 void Destroy() { delete this; } | 300 void Destroy() { delete this; } |
| 302 | 301 |
| 303 // CCodec_ScanlineDecoder | 302 // CCodec_ScanlineDecoder |
| 304 void v_DownScale(int dest_width, int dest_height) override; | 303 void v_DownScale(int dest_width, int dest_height) override; |
| 305 FX_BOOL v_Rewind() override; | 304 FX_BOOL v_Rewind() override; |
| 306 uint8_t* v_GetNextLine() override; | 305 uint8_t* v_GetNextLine() override; |
| 307 FX_DWORD GetSrcOffset() override; | 306 FX_DWORD GetSrcOffset() override; |
| 308 | 307 |
| 309 FX_BOOL InitDecode(); | 308 FX_BOOL InitDecode(); |
| 310 | 309 |
| 311 jmp_buf m_JmpBuf; | 310 jmp_buf m_JmpBuf; |
| 312 struct jpeg_decompress_struct cinfo; | 311 struct jpeg_decompress_struct cinfo; |
| 313 struct jpeg_error_mgr jerr; | 312 struct jpeg_error_mgr jerr; |
| 314 struct jpeg_source_mgr src; | 313 struct jpeg_source_mgr src; |
| 315 const uint8_t* m_SrcBuf; | 314 const uint8_t* m_SrcBuf; |
| 316 FX_DWORD m_SrcSize; | 315 FX_DWORD m_SrcSize; |
| 317 uint8_t* m_pScanlineBuf; | 316 uint8_t* m_pScanlineBuf; |
| 318 | 317 |
| 319 FX_BOOL m_bInited; | 318 FX_BOOL m_bInited; |
| 320 FX_BOOL m_bStarted; | 319 FX_BOOL m_bStarted; |
| 321 FX_BOOL m_bJpegTransform; | 320 FX_BOOL m_bJpegTransform; |
| 322 | 321 |
| 323 protected: | 322 protected: |
| 324 IFX_JpegProvider* m_pExtProvider; | |
| 325 void* m_pExtContext; | |
| 326 FX_DWORD m_nDefaultScaleDenom; | 323 FX_DWORD m_nDefaultScaleDenom; |
| 327 }; | 324 }; |
| 328 | 325 |
| 329 CCodec_JpegDecoder::CCodec_JpegDecoder() { | 326 CCodec_JpegDecoder::CCodec_JpegDecoder() { |
| 330 m_pScanlineBuf = NULL; | 327 m_pScanlineBuf = NULL; |
| 331 m_DownScale = 1; | 328 m_DownScale = 1; |
| 332 m_bStarted = FALSE; | 329 m_bStarted = FALSE; |
| 333 m_bInited = FALSE; | 330 m_bInited = FALSE; |
| 334 m_pExtProvider = NULL; | |
| 335 m_pExtContext = NULL; | |
| 336 FXSYS_memset(&cinfo, 0, sizeof(cinfo)); | 331 FXSYS_memset(&cinfo, 0, sizeof(cinfo)); |
| 337 FXSYS_memset(&jerr, 0, sizeof(jerr)); | 332 FXSYS_memset(&jerr, 0, sizeof(jerr)); |
| 338 FXSYS_memset(&src, 0, sizeof(src)); | 333 FXSYS_memset(&src, 0, sizeof(src)); |
| 339 m_nDefaultScaleDenom = 1; | 334 m_nDefaultScaleDenom = 1; |
| 340 } | 335 } |
| 341 CCodec_JpegDecoder::~CCodec_JpegDecoder() { | 336 CCodec_JpegDecoder::~CCodec_JpegDecoder() { |
| 342 if (m_pExtProvider) { | |
| 343 m_pExtProvider->DestroyDecoder(m_pExtContext); | |
| 344 return; | |
| 345 } | |
| 346 FX_Free(m_pScanlineBuf); | 337 FX_Free(m_pScanlineBuf); |
| 347 if (m_bInited) { | 338 if (m_bInited) { |
| 348 jpeg_destroy_decompress(&cinfo); | 339 jpeg_destroy_decompress(&cinfo); |
| 349 } | 340 } |
| 350 } | 341 } |
| 351 FX_BOOL CCodec_JpegDecoder::InitDecode() { | 342 FX_BOOL CCodec_JpegDecoder::InitDecode() { |
| 352 cinfo.err = &jerr; | 343 cinfo.err = &jerr; |
| 353 cinfo.client_data = &m_JmpBuf; | 344 cinfo.client_data = &m_JmpBuf; |
| 354 if (setjmp(m_JmpBuf) == -1) { | 345 if (setjmp(m_JmpBuf) == -1) { |
| 355 return FALSE; | 346 return FALSE; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 381 m_OutputWidth = m_OrigWidth; | 372 m_OutputWidth = m_OrigWidth; |
| 382 m_OutputHeight = m_OrigHeight; | 373 m_OutputHeight = m_OrigHeight; |
| 383 m_nDefaultScaleDenom = cinfo.scale_denom; | 374 m_nDefaultScaleDenom = cinfo.scale_denom; |
| 384 return TRUE; | 375 return TRUE; |
| 385 } | 376 } |
| 386 FX_BOOL CCodec_JpegDecoder::Create(const uint8_t* src_buf, | 377 FX_BOOL CCodec_JpegDecoder::Create(const uint8_t* src_buf, |
| 387 FX_DWORD src_size, | 378 FX_DWORD src_size, |
| 388 int width, | 379 int width, |
| 389 int height, | 380 int height, |
| 390 int nComps, | 381 int nComps, |
| 391 FX_BOOL ColorTransform, | 382 FX_BOOL ColorTransform) { |
| 392 IFX_JpegProvider* pJP) { | |
| 393 if (pJP) { | |
| 394 m_pExtProvider = pJP; | |
| 395 m_pExtContext = m_pExtProvider->CreateDecoder( | |
| 396 src_buf, src_size, width, height, nComps, ColorTransform); | |
| 397 return m_pExtContext != NULL; | |
| 398 } | |
| 399 _JpegScanSOI(src_buf, src_size); | 383 _JpegScanSOI(src_buf, src_size); |
| 400 m_SrcBuf = src_buf; | 384 m_SrcBuf = src_buf; |
| 401 m_SrcSize = src_size; | 385 m_SrcSize = src_size; |
| 402 jerr.error_exit = _error_fatal; | 386 jerr.error_exit = _error_fatal; |
| 403 jerr.emit_message = _error_do_nothing1; | 387 jerr.emit_message = _error_do_nothing1; |
| 404 jerr.output_message = _error_do_nothing; | 388 jerr.output_message = _error_do_nothing; |
| 405 jerr.format_message = _error_do_nothing2; | 389 jerr.format_message = _error_do_nothing2; |
| 406 jerr.reset_error_mgr = _error_do_nothing; | 390 jerr.reset_error_mgr = _error_do_nothing; |
| 407 src.init_source = _src_do_nothing; | 391 src.init_source = _src_do_nothing; |
| 408 src.term_source = _src_do_nothing; | 392 src.term_source = _src_do_nothing; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 if (ratio >= 4) { | 432 if (ratio >= 4) { |
| 449 return 4; | 433 return 4; |
| 450 } | 434 } |
| 451 if (ratio >= 2) { | 435 if (ratio >= 2) { |
| 452 return 2; | 436 return 2; |
| 453 } | 437 } |
| 454 return 1; | 438 return 1; |
| 455 } | 439 } |
| 456 } | 440 } |
| 457 void CCodec_JpegDecoder::v_DownScale(int dest_width, int dest_height) { | 441 void CCodec_JpegDecoder::v_DownScale(int dest_width, int dest_height) { |
| 458 if (m_pExtProvider) { | |
| 459 m_pExtProvider->DownScale(m_pExtContext, dest_width, dest_height); | |
| 460 return; | |
| 461 } | |
| 462 int old_scale = m_DownScale; | 442 int old_scale = m_DownScale; |
| 463 m_DownScale = | 443 m_DownScale = |
| 464 FX_GetDownsampleRatio(m_OrigWidth, m_OrigHeight, dest_width, dest_height); | 444 FX_GetDownsampleRatio(m_OrigWidth, m_OrigHeight, dest_width, dest_height); |
| 465 m_OutputWidth = (m_OrigWidth + m_DownScale - 1) / m_DownScale; | 445 m_OutputWidth = (m_OrigWidth + m_DownScale - 1) / m_DownScale; |
| 466 m_OutputHeight = (m_OrigHeight + m_DownScale - 1) / m_DownScale; | 446 m_OutputHeight = (m_OrigHeight + m_DownScale - 1) / m_DownScale; |
| 467 m_Pitch = (m_OutputWidth * m_nComps + 3) / 4 * 4; | 447 m_Pitch = (m_OutputWidth * m_nComps + 3) / 4 * 4; |
| 468 if (old_scale != m_DownScale) { | 448 if (old_scale != m_DownScale) { |
| 469 m_NextLine = -1; | 449 m_NextLine = -1; |
| 470 } | 450 } |
| 471 } | 451 } |
| 472 FX_BOOL CCodec_JpegDecoder::v_Rewind() { | 452 FX_BOOL CCodec_JpegDecoder::v_Rewind() { |
| 473 if (m_pExtProvider) { | |
| 474 return m_pExtProvider->Rewind(m_pExtContext); | |
| 475 } | |
| 476 if (m_bStarted) { | 453 if (m_bStarted) { |
| 477 jpeg_destroy_decompress(&cinfo); | 454 jpeg_destroy_decompress(&cinfo); |
| 478 if (!InitDecode()) { | 455 if (!InitDecode()) { |
| 479 return FALSE; | 456 return FALSE; |
| 480 } | 457 } |
| 481 } | 458 } |
| 482 if (setjmp(m_JmpBuf) == -1) { | 459 if (setjmp(m_JmpBuf) == -1) { |
| 483 return FALSE; | 460 return FALSE; |
| 484 } | 461 } |
| 485 cinfo.scale_denom = m_nDefaultScaleDenom * m_DownScale; | 462 cinfo.scale_denom = m_nDefaultScaleDenom * m_DownScale; |
| 486 m_OutputWidth = (m_OrigWidth + m_DownScale - 1) / m_DownScale; | 463 m_OutputWidth = (m_OrigWidth + m_DownScale - 1) / m_DownScale; |
| 487 m_OutputHeight = (m_OrigHeight + m_DownScale - 1) / m_DownScale; | 464 m_OutputHeight = (m_OrigHeight + m_DownScale - 1) / m_DownScale; |
| 488 if (!jpeg_start_decompress(&cinfo)) { | 465 if (!jpeg_start_decompress(&cinfo)) { |
| 489 jpeg_destroy_decompress(&cinfo); | 466 jpeg_destroy_decompress(&cinfo); |
| 490 return FALSE; | 467 return FALSE; |
| 491 } | 468 } |
| 492 if ((int)cinfo.output_width > m_OrigWidth) { | 469 if ((int)cinfo.output_width > m_OrigWidth) { |
| 493 FXSYS_assert(FALSE); | 470 FXSYS_assert(FALSE); |
| 494 return FALSE; | 471 return FALSE; |
| 495 } | 472 } |
| 496 m_bStarted = TRUE; | 473 m_bStarted = TRUE; |
| 497 return TRUE; | 474 return TRUE; |
| 498 } | 475 } |
| 499 uint8_t* CCodec_JpegDecoder::v_GetNextLine() { | 476 uint8_t* CCodec_JpegDecoder::v_GetNextLine() { |
| 500 if (m_pExtProvider) { | |
| 501 return m_pExtProvider->GetNextLine(m_pExtContext); | |
| 502 } | |
| 503 int nlines = jpeg_read_scanlines(&cinfo, &m_pScanlineBuf, 1); | 477 int nlines = jpeg_read_scanlines(&cinfo, &m_pScanlineBuf, 1); |
| 504 if (nlines < 1) { | 478 if (nlines < 1) { |
| 505 return NULL; | 479 return NULL; |
| 506 } | 480 } |
| 507 return m_pScanlineBuf; | 481 return m_pScanlineBuf; |
| 508 } | 482 } |
| 509 FX_DWORD CCodec_JpegDecoder::GetSrcOffset() { | 483 FX_DWORD CCodec_JpegDecoder::GetSrcOffset() { |
| 510 if (m_pExtProvider) { | |
| 511 return m_pExtProvider->GetSrcOffset(m_pExtContext); | |
| 512 } | |
| 513 return (FX_DWORD)(m_SrcSize - src.bytes_in_buffer); | 484 return (FX_DWORD)(m_SrcSize - src.bytes_in_buffer); |
| 514 } | 485 } |
| 515 ICodec_ScanlineDecoder* CCodec_JpegModule::CreateDecoder( | 486 ICodec_ScanlineDecoder* CCodec_JpegModule::CreateDecoder( |
| 516 const uint8_t* src_buf, | 487 const uint8_t* src_buf, |
| 517 FX_DWORD src_size, | 488 FX_DWORD src_size, |
| 518 int width, | 489 int width, |
| 519 int height, | 490 int height, |
| 520 int nComps, | 491 int nComps, |
| 521 FX_BOOL ColorTransform) { | 492 FX_BOOL ColorTransform) { |
| 522 if (src_buf == NULL || src_size == 0) { | 493 if (src_buf == NULL || src_size == 0) { |
| 523 return NULL; | 494 return NULL; |
| 524 } | 495 } |
| 525 CCodec_JpegDecoder* pDecoder = new CCodec_JpegDecoder; | 496 CCodec_JpegDecoder* pDecoder = new CCodec_JpegDecoder; |
| 526 if (!pDecoder->Create(src_buf, src_size, width, height, nComps, | 497 if (!pDecoder->Create(src_buf, src_size, width, height, nComps, |
| 527 ColorTransform, m_pExtProvider)) { | 498 ColorTransform)) { |
| 528 delete pDecoder; | 499 delete pDecoder; |
| 529 return NULL; | 500 return NULL; |
| 530 } | 501 } |
| 531 return pDecoder; | 502 return pDecoder; |
| 532 } | 503 } |
| 533 FX_BOOL CCodec_JpegModule::LoadInfo(const uint8_t* src_buf, | 504 FX_BOOL CCodec_JpegModule::LoadInfo(const uint8_t* src_buf, |
| 534 FX_DWORD src_size, | 505 FX_DWORD src_size, |
| 535 int& width, | 506 int& width, |
| 536 int& height, | 507 int& height, |
| 537 int& num_components, | 508 int& num_components, |
| 538 int& bits_per_components, | 509 int& bits_per_components, |
| 539 FX_BOOL& color_transform, | 510 FX_BOOL& color_transform, |
| 540 uint8_t** icc_buf_ptr, | 511 uint8_t** icc_buf_ptr, |
| 541 FX_DWORD* icc_length) { | 512 FX_DWORD* icc_length) { |
| 542 if (m_pExtProvider) { | |
| 543 return m_pExtProvider->LoadInfo(src_buf, src_size, width, height, | |
| 544 num_components, bits_per_components, | |
| 545 color_transform, icc_buf_ptr, icc_length); | |
| 546 } | |
| 547 return _JpegLoadInfo(src_buf, src_size, width, height, num_components, | 513 return _JpegLoadInfo(src_buf, src_size, width, height, num_components, |
| 548 bits_per_components, color_transform, icc_buf_ptr, | 514 bits_per_components, color_transform, icc_buf_ptr, |
| 549 icc_length); | 515 icc_length); |
| 550 } | 516 } |
| 551 FX_BOOL CCodec_JpegModule::Encode(const CFX_DIBSource* pSource, | 517 FX_BOOL CCodec_JpegModule::Encode(const CFX_DIBSource* pSource, |
| 552 uint8_t*& dest_buf, | 518 uint8_t*& dest_buf, |
| 553 FX_STRSIZE& dest_size, | 519 FX_STRSIZE& dest_size, |
| 554 int quality, | 520 int quality, |
| 555 const uint8_t* icc_buf, | 521 const uint8_t* icc_buf, |
| 556 FX_DWORD icc_length) { | 522 FX_DWORD icc_length) { |
| 557 if (m_pExtProvider) { | |
| 558 return m_pExtProvider->Encode(pSource, dest_buf, dest_size, quality, | |
| 559 icc_buf, icc_length); | |
| 560 } | |
| 561 if (pSource->GetBPP() < 8 || pSource->GetPalette() != NULL) { | 523 if (pSource->GetBPP() < 8 || pSource->GetPalette() != NULL) { |
| 562 ASSERT(pSource->GetBPP() >= 8 && pSource->GetPalette() == NULL); | 524 ASSERT(pSource->GetBPP() >= 8 && pSource->GetPalette() == NULL); |
| 563 return FALSE; | 525 return FALSE; |
| 564 } | 526 } |
| 565 _JpegEncode(pSource, dest_buf, dest_size, quality, icc_buf, icc_length); | 527 _JpegEncode(pSource, dest_buf, dest_size, quality, icc_buf, icc_length); |
| 566 return TRUE; | 528 return TRUE; |
| 567 } | 529 } |
| 568 struct FXJPEG_Context { | 530 struct FXJPEG_Context { |
| 569 jmp_buf m_JumpMark; | 531 jmp_buf m_JumpMark; |
| 570 jpeg_decompress_struct m_Info; | 532 jpeg_decompress_struct m_Info; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 591 } | 553 } |
| 592 } | 554 } |
| 593 }; | 555 }; |
| 594 static void* jpeg_alloc_func(unsigned int size) { | 556 static void* jpeg_alloc_func(unsigned int size) { |
| 595 return FX_Alloc(char, size); | 557 return FX_Alloc(char, size); |
| 596 } | 558 } |
| 597 static void jpeg_free_func(void* p) { | 559 static void jpeg_free_func(void* p) { |
| 598 FX_Free(p); | 560 FX_Free(p); |
| 599 } | 561 } |
| 600 void* CCodec_JpegModule::Start() { | 562 void* CCodec_JpegModule::Start() { |
| 601 if (m_pExtProvider) { | |
| 602 return m_pExtProvider->Start(); | |
| 603 } | |
| 604 FXJPEG_Context* p = FX_Alloc(FXJPEG_Context, 1); | 563 FXJPEG_Context* p = FX_Alloc(FXJPEG_Context, 1); |
| 605 p->m_AllocFunc = jpeg_alloc_func; | 564 p->m_AllocFunc = jpeg_alloc_func; |
| 606 p->m_FreeFunc = jpeg_free_func; | 565 p->m_FreeFunc = jpeg_free_func; |
| 607 p->m_ErrMgr.error_exit = _error_fatal1; | 566 p->m_ErrMgr.error_exit = _error_fatal1; |
| 608 p->m_ErrMgr.emit_message = _error_do_nothing1; | 567 p->m_ErrMgr.emit_message = _error_do_nothing1; |
| 609 p->m_ErrMgr.output_message = _error_do_nothing; | 568 p->m_ErrMgr.output_message = _error_do_nothing; |
| 610 p->m_ErrMgr.format_message = _error_do_nothing2; | 569 p->m_ErrMgr.format_message = _error_do_nothing2; |
| 611 p->m_ErrMgr.reset_error_mgr = _error_do_nothing; | 570 p->m_ErrMgr.reset_error_mgr = _error_do_nothing; |
| 612 p->m_SrcMgr.init_source = _src_do_nothing; | 571 p->m_SrcMgr.init_source = _src_do_nothing; |
| 613 p->m_SrcMgr.term_source = _src_do_nothing; | 572 p->m_SrcMgr.term_source = _src_do_nothing; |
| 614 p->m_SrcMgr.skip_input_data = _src_skip_data1; | 573 p->m_SrcMgr.skip_input_data = _src_skip_data1; |
| 615 p->m_SrcMgr.fill_input_buffer = _src_fill_buffer; | 574 p->m_SrcMgr.fill_input_buffer = _src_fill_buffer; |
| 616 p->m_SrcMgr.resync_to_restart = _src_resync; | 575 p->m_SrcMgr.resync_to_restart = _src_resync; |
| 617 p->m_Info.client_data = p; | 576 p->m_Info.client_data = p; |
| 618 p->m_Info.err = &p->m_ErrMgr; | 577 p->m_Info.err = &p->m_ErrMgr; |
| 619 if (setjmp(p->m_JumpMark) == -1) { | 578 if (setjmp(p->m_JumpMark) == -1) { |
| 620 return 0; | 579 return 0; |
| 621 } | 580 } |
| 622 jpeg_create_decompress(&p->m_Info); | 581 jpeg_create_decompress(&p->m_Info); |
| 623 p->m_Info.src = &p->m_SrcMgr; | 582 p->m_Info.src = &p->m_SrcMgr; |
| 624 p->m_SkipSize = 0; | 583 p->m_SkipSize = 0; |
| 625 return p; | 584 return p; |
| 626 } | 585 } |
| 627 void CCodec_JpegModule::Finish(void* pContext) { | 586 void CCodec_JpegModule::Finish(void* pContext) { |
| 628 if (m_pExtProvider) { | |
| 629 m_pExtProvider->Finish(pContext); | |
| 630 return; | |
| 631 } | |
| 632 FXJPEG_Context* p = (FXJPEG_Context*)pContext; | 587 FXJPEG_Context* p = (FXJPEG_Context*)pContext; |
| 633 jpeg_destroy_decompress(&p->m_Info); | 588 jpeg_destroy_decompress(&p->m_Info); |
| 634 p->m_FreeFunc(p); | 589 p->m_FreeFunc(p); |
| 635 } | 590 } |
| 636 void CCodec_JpegModule::Input(void* pContext, | 591 void CCodec_JpegModule::Input(void* pContext, |
| 637 const unsigned char* src_buf, | 592 const unsigned char* src_buf, |
| 638 FX_DWORD src_size) { | 593 FX_DWORD src_size) { |
| 639 if (m_pExtProvider) { | |
| 640 m_pExtProvider->Input(pContext, src_buf, src_size); | |
| 641 return; | |
| 642 } | |
| 643 FXJPEG_Context* p = (FXJPEG_Context*)pContext; | 594 FXJPEG_Context* p = (FXJPEG_Context*)pContext; |
| 644 if (p->m_SkipSize) { | 595 if (p->m_SkipSize) { |
| 645 if (p->m_SkipSize > src_size) { | 596 if (p->m_SkipSize > src_size) { |
| 646 p->m_SrcMgr.bytes_in_buffer = 0; | 597 p->m_SrcMgr.bytes_in_buffer = 0; |
| 647 p->m_SkipSize -= src_size; | 598 p->m_SkipSize -= src_size; |
| 648 return; | 599 return; |
| 649 } | 600 } |
| 650 src_size -= p->m_SkipSize; | 601 src_size -= p->m_SkipSize; |
| 651 src_buf += p->m_SkipSize; | 602 src_buf += p->m_SkipSize; |
| 652 p->m_SkipSize = 0; | 603 p->m_SkipSize = 0; |
| 653 } | 604 } |
| 654 p->m_SrcMgr.next_input_byte = src_buf; | 605 p->m_SrcMgr.next_input_byte = src_buf; |
| 655 p->m_SrcMgr.bytes_in_buffer = src_size; | 606 p->m_SrcMgr.bytes_in_buffer = src_size; |
| 656 } | 607 } |
| 657 int CCodec_JpegModule::ReadHeader(void* pContext, | 608 int CCodec_JpegModule::ReadHeader(void* pContext, |
| 658 int* width, | 609 int* width, |
| 659 int* height, | 610 int* height, |
| 660 int* nComps) { | 611 int* nComps) { |
| 661 if (m_pExtProvider) { | |
| 662 return m_pExtProvider->ReadHeader(pContext, width, height, nComps); | |
| 663 } | |
| 664 FXJPEG_Context* p = (FXJPEG_Context*)pContext; | 612 FXJPEG_Context* p = (FXJPEG_Context*)pContext; |
| 665 if (setjmp(p->m_JumpMark) == -1) { | 613 if (setjmp(p->m_JumpMark) == -1) { |
| 666 return 1; | 614 return 1; |
| 667 } | 615 } |
| 668 int ret = jpeg_read_header(&p->m_Info, true); | 616 int ret = jpeg_read_header(&p->m_Info, true); |
| 669 if (ret == JPEG_SUSPENDED) { | 617 if (ret == JPEG_SUSPENDED) { |
| 670 return 2; | 618 return 2; |
| 671 } | 619 } |
| 672 if (ret != JPEG_HEADER_OK) { | 620 if (ret != JPEG_HEADER_OK) { |
| 673 return 1; | 621 return 1; |
| 674 } | 622 } |
| 675 *width = p->m_Info.image_width; | 623 *width = p->m_Info.image_width; |
| 676 *height = p->m_Info.image_height; | 624 *height = p->m_Info.image_height; |
| 677 *nComps = p->m_Info.num_components; | 625 *nComps = p->m_Info.num_components; |
| 678 return 0; | 626 return 0; |
| 679 } | 627 } |
| 680 int CCodec_JpegModule::StartScanline(void* pContext, int down_scale) { | 628 int CCodec_JpegModule::StartScanline(void* pContext, int down_scale) { |
| 681 if (m_pExtProvider) { | |
| 682 return m_pExtProvider->StartScanline(pContext, down_scale); | |
| 683 } | |
| 684 FXJPEG_Context* p = (FXJPEG_Context*)pContext; | 629 FXJPEG_Context* p = (FXJPEG_Context*)pContext; |
| 685 if (setjmp(p->m_JumpMark) == -1) { | 630 if (setjmp(p->m_JumpMark) == -1) { |
| 686 return 0; | 631 return 0; |
| 687 } | 632 } |
| 688 p->m_Info.scale_denom = down_scale; | 633 p->m_Info.scale_denom = down_scale; |
| 689 return jpeg_start_decompress(&p->m_Info); | 634 return jpeg_start_decompress(&p->m_Info); |
| 690 } | 635 } |
| 691 FX_BOOL CCodec_JpegModule::ReadScanline(void* pContext, | 636 FX_BOOL CCodec_JpegModule::ReadScanline(void* pContext, |
| 692 unsigned char* dest_buf) { | 637 unsigned char* dest_buf) { |
| 693 if (m_pExtProvider) { | |
| 694 return m_pExtProvider->ReadScanline(pContext, dest_buf); | |
| 695 } | |
| 696 FXJPEG_Context* p = (FXJPEG_Context*)pContext; | 638 FXJPEG_Context* p = (FXJPEG_Context*)pContext; |
| 697 if (setjmp(p->m_JumpMark) == -1) { | 639 if (setjmp(p->m_JumpMark) == -1) { |
| 698 return FALSE; | 640 return FALSE; |
| 699 } | 641 } |
| 700 int nlines = jpeg_read_scanlines(&p->m_Info, &dest_buf, 1); | 642 int nlines = jpeg_read_scanlines(&p->m_Info, &dest_buf, 1); |
| 701 return nlines == 1; | 643 return nlines == 1; |
| 702 } | 644 } |
| 703 FX_DWORD CCodec_JpegModule::GetAvailInput(void* pContext, | 645 FX_DWORD CCodec_JpegModule::GetAvailInput(void* pContext, |
| 704 uint8_t** avail_buf_ptr) { | 646 uint8_t** avail_buf_ptr) { |
| 705 if (m_pExtProvider) { | |
| 706 return m_pExtProvider->GetAvailInput(pContext, avail_buf_ptr); | |
| 707 } | |
| 708 if (avail_buf_ptr != NULL) { | 647 if (avail_buf_ptr != NULL) { |
| 709 *avail_buf_ptr = NULL; | 648 *avail_buf_ptr = NULL; |
| 710 if (((FXJPEG_Context*)pContext)->m_SrcMgr.bytes_in_buffer > 0) { | 649 if (((FXJPEG_Context*)pContext)->m_SrcMgr.bytes_in_buffer > 0) { |
| 711 *avail_buf_ptr = | 650 *avail_buf_ptr = |
| 712 (uint8_t*)((FXJPEG_Context*)pContext)->m_SrcMgr.next_input_byte; | 651 (uint8_t*)((FXJPEG_Context*)pContext)->m_SrcMgr.next_input_byte; |
| 713 } | 652 } |
| 714 } | 653 } |
| 715 return (FX_DWORD)((FXJPEG_Context*)pContext)->m_SrcMgr.bytes_in_buffer; | 654 return (FX_DWORD)((FXJPEG_Context*)pContext)->m_SrcMgr.bytes_in_buffer; |
| 716 } | 655 } |
| OLD | NEW |