From d4e8f1222ca17b57ac74019b2fc3706e1192645c Mon Sep 17 00:00:00 2001 From: Wei Li Date: Mon, 21 Mar 2016 11:20:44 -0700 Subject: Re-enable several MSVC warnings Re-enable the following warnings: 4245: signed/unsigned conversion mismatch; 4310: cast may truncate data; 4389: operator on signed/unsigned mismatch; 4701: use potentially uninitialized local variable; 4706: assignment within conditional expression Clean up the code to avoid those warnings. BUG=pdfium:29 R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1801383002 . --- core/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp | 5 +- core/fpdfapi/fpdf_font/fpdf_font_cid.cpp | 3 +- core/fpdfapi/fpdf_page/cpdf_page.cpp | 7 +- core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp | 14 +- core/fpdfapi/fpdf_parser/cpdf_parser.cpp | 5 +- core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp | 6 +- core/fpdfapi/fpdf_render/fpdf_render_text.cpp | 9 +- core/fpdfdoc/doc_ap.cpp | 4 +- core/fxcodec/codec/codec_int.h | 1 - core/fxcodec/codec/fx_codec_flate.cpp | 6 +- core/fxcodec/codec/fx_codec_jpx_opj.cpp | 16 +- core/fxcodec/codec/fx_codec_tiff.cpp | 6 +- core/fxcodec/jbig2/JBig2_Context.cpp | 18 +-- core/fxcodec/jbig2/JBig2_Image.cpp | 195 +++++++++++------------- core/fxcodec/jbig2/JBig2_TrdProc.cpp | 69 ++++----- core/fxcrt/fx_basic_maps.cpp | 15 +- core/fxcrt/fx_basic_wstring.cpp | 20 +-- core/fxge/dib/fx_dib_composite.cpp | 124 ++++++--------- core/fxge/dib/fx_dib_main.cpp | 21 ++- core/fxge/ge/fx_ge_font.cpp | 2 +- core/fxge/ge/fx_ge_path.cpp | 4 +- core/fxge/ge/fx_ge_text.cpp | 5 +- core/fxge/win32/fx_win32_gdipext.cpp | 4 +- 23 files changed, 267 insertions(+), 292 deletions(-) (limited to 'core') diff --git a/core/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp b/core/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp index 42315dad53..2fddf10a78 100644 --- a/core/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp +++ b/core/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp @@ -924,7 +924,7 @@ CPDF_Font* CPDF_Document::AddFont(CFX_Font* pFont, int charset, FX_BOOL bVert) { pFontDict = new CPDF_Dictionary; CFX_ByteString cmap; CFX_ByteString ordering; - int supplement; + int supplement = 0; CPDF_Array* pWidthArray = new CPDF_Array; switch (charset) { case FXFONT_CHINESEBIG5_CHARSET: @@ -936,7 +936,8 @@ CPDF_Font* CPDF_Document::AddFont(CFX_Font* pFont, int charset, FX_BOOL bVert) { break; case FXFONT_GB2312_CHARSET: cmap = bVert ? "GBK-EUC-V" : "GBK-EUC-H"; - ordering = "GB1", supplement = 2; + ordering = "GB1"; + supplement = 2; pWidthArray->AddInteger(7716); _InsertWidthArray1(pFont, pEncoding.get(), 0x20, 0x20, pWidthArray); pWidthArray->AddInteger(814); diff --git a/core/fpdfapi/fpdf_font/fpdf_font_cid.cpp b/core/fpdfapi/fpdf_font/fpdf_font_cid.cpp index 1295c624ad..f370b86049 100644 --- a/core/fpdfapi/fpdf_font/fpdf_font_cid.cpp +++ b/core/fpdfapi/fpdf_font/fpdf_font_cid.cpp @@ -1584,7 +1584,8 @@ void CPDF_CIDFont::LoadMetricsArray(CPDF_Array* pArray, int nElements) { int width_status = 0; int iCurElement = 0; - int first_code = 0, last_code; + int first_code = 0; + int last_code = 0; FX_DWORD count = pArray->GetCount(); for (FX_DWORD i = 0; i < count; i++) { CPDF_Object* pObj = pArray->GetElementValue(i); diff --git a/core/fpdfapi/fpdf_page/cpdf_page.cpp b/core/fpdfapi/fpdf_page/cpdf_page.cpp index 0da5452969..2c01cd5573 100644 --- a/core/fpdfapi/fpdf_page/cpdf_page.cpp +++ b/core/fpdfapi/fpdf_page/cpdf_page.cpp @@ -140,7 +140,12 @@ void CPDF_Page::GetDisplayMatrix(CFX_Matrix& matrix, return; } CFX_Matrix display_matrix; - int x0, y0, x1, y1, x2, y2; + int x0 = 0; + int y0 = 0; + int x1 = 0; + int y1 = 0; + int x2 = 0; + int y2 = 0; iRotate %= 4; switch (iRotate) { case 0: diff --git a/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp b/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp index c9f05ac5ab..87ed09735a 100644 --- a/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp +++ b/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp @@ -41,11 +41,11 @@ CPDF_StreamParser::~CPDF_StreamParser() { } } -FX_DWORD _DecodeAllScanlines(ICodec_ScanlineDecoder* pDecoder, - uint8_t*& dest_buf, - FX_DWORD& dest_size) { +FX_DWORD DecodeAllScanlines(ICodec_ScanlineDecoder* pDecoder, + uint8_t*& dest_buf, + FX_DWORD& dest_size) { if (!pDecoder) { - return (FX_DWORD)-1; + return static_cast(-1); } int ncomps = pDecoder->CountComps(); int bpc = pDecoder->GetBPC(); @@ -54,7 +54,7 @@ FX_DWORD _DecodeAllScanlines(ICodec_ScanlineDecoder* pDecoder, int pitch = (width * ncomps * bpc + 7) / 8; if (height == 0 || pitch > (1 << 30) / height) { delete pDecoder; - return -1; + return static_cast(-1); } dest_buf = FX_Alloc2D(uint8_t, pitch, height); dest_size = pitch * height; // Safe since checked alloc returned. @@ -88,7 +88,7 @@ FX_DWORD PDF_DecodeInlineStream(const uint8_t* src_buf, if (decoder == "CCITTFaxDecode" || decoder == "CCF") { ICodec_ScanlineDecoder* pDecoder = FPDFAPI_CreateFaxDecoder(src_buf, limit, width, height, pParam); - return _DecodeAllScanlines(pDecoder, dest_buf, dest_size); + return DecodeAllScanlines(pDecoder, dest_buf, dest_size); } if (decoder == "ASCII85Decode" || decoder == "A85") { return A85Decode(src_buf, limit, dest_buf, dest_size); @@ -109,7 +109,7 @@ FX_DWORD PDF_DecodeInlineStream(const uint8_t* src_buf, CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder( src_buf, limit, width, height, 0, pParam ? pParam->GetIntegerBy("ColorTransform", 1) : 1); - return _DecodeAllScanlines(pDecoder, dest_buf, dest_size); + return DecodeAllScanlines(pDecoder, dest_buf, dest_size); } if (decoder == "RunLengthDecode" || decoder == "RL") { return RunLengthDecode(src_buf, limit, dest_buf, dest_size); diff --git a/core/fpdfapi/fpdf_parser/cpdf_parser.cpp b/core/fpdfapi/fpdf_parser/cpdf_parser.cpp index c9b8583d16..3ee53e6cf9 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_parser.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_parser.cpp @@ -1538,9 +1538,8 @@ CPDF_Parser::Error CPDF_Parser::StartAsyncParse(IFX_FileRead* pFileAccess) { FX_FILESIZE dwFirstXRefOffset = m_pSyntax->SavePos(); FX_BOOL bXRefRebuilt = FALSE; - FX_BOOL bLoadV4 = FALSE; - if (!(bLoadV4 = LoadCrossRefV4(dwFirstXRefOffset, 0, FALSE)) && - !LoadCrossRefV5(&dwFirstXRefOffset, TRUE)) { + FX_BOOL bLoadV4 = LoadCrossRefV4(dwFirstXRefOffset, 0, FALSE); + if (!bLoadV4 && !LoadCrossRefV5(&dwFirstXRefOffset, TRUE)) { if (!RebuildCrossRef()) return FORMAT_ERROR; diff --git a/core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp b/core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp index f7fc3099fc..c91e99b9cb 100644 --- a/core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp +++ b/core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp @@ -177,14 +177,14 @@ FX_DWORD RunLengthDecode(const uint8_t* src_buf, old = dest_size; dest_size += src_buf[i] + 1; if (dest_size < old) { - return (FX_DWORD)-1; + return static_cast(-1); } i += src_buf[i] + 2; } else if (src_buf[i] > 128) { old = dest_size; dest_size += 257 - src_buf[i]; if (dest_size < old) { - return (FX_DWORD)-1; + return static_cast(-1); } i += 2; } else { @@ -192,7 +192,7 @@ FX_DWORD RunLengthDecode(const uint8_t* src_buf, } } if (dest_size >= _STREAM_MAX_SIZE_) { - return -1; + return static_cast(-1); } dest_buf = FX_Alloc(uint8_t, dest_size); i = 0; diff --git a/core/fpdfapi/fpdf_render/fpdf_render_text.cpp b/core/fpdfapi/fpdf_render/fpdf_render_text.cpp index fe72bb3aee..6741d1a70b 100644 --- a/core/fpdfapi/fpdf_render/fpdf_render_text.cpp +++ b/core/fpdfapi/fpdf_render/fpdf_render_text.cpp @@ -140,12 +140,12 @@ CFX_GlyphBitmap* CPDF_Type3Cache::RenderGlyph(CPDF_Type3Glyphs* pSize, text_matrix.Set(pMatrix->a, pMatrix->b, pMatrix->c, pMatrix->d, 0, 0); image_matrix.Concat(text_matrix); CFX_DIBitmap* pResBitmap = NULL; - int left, top; + int left = 0; + int top = 0; if (FXSYS_fabs(image_matrix.b) < FXSYS_fabs(image_matrix.a) / 100 && FXSYS_fabs(image_matrix.c) < FXSYS_fabs(image_matrix.d) / 100) { - int top_line, bottom_line; - top_line = _DetectFirstLastScan(pBitmap, TRUE); - bottom_line = _DetectFirstLastScan(pBitmap, FALSE); + int top_line = _DetectFirstLastScan(pBitmap, TRUE); + int bottom_line = _DetectFirstLastScan(pBitmap, FALSE); if (top_line == 0 && bottom_line == pBitmap->GetHeight() - 1) { FX_FLOAT top_y = image_matrix.d + image_matrix.f; FX_FLOAT bottom_y = image_matrix.f; @@ -167,7 +167,6 @@ CFX_GlyphBitmap* CPDF_Type3Cache::RenderGlyph(CPDF_Type3Glyphs* pSize, } else { left = FXSYS_round(image_matrix.e); } - } else { } } if (!pResBitmap) { diff --git a/core/fpdfdoc/doc_ap.cpp b/core/fpdfdoc/doc_ap.cpp index 43dcfb4ac0..e64080dbd0 100644 --- a/core/fpdfdoc/doc_ap.cpp +++ b/core/fpdfdoc/doc_ap.cpp @@ -303,8 +303,8 @@ static FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, pDRDict = pFormDict->GetDictBy("DR"); bUseFormRes = TRUE; } - CPDF_Dictionary* pDRFontDict = NULL; - if (pDRDict && (pDRFontDict = pDRDict->GetDictBy("Font"))) { + CPDF_Dictionary* pDRFontDict = pDRDict ? pDRDict->GetDictBy("Font") : nullptr; + if (pDRFontDict) { pFontDict = pDRFontDict->GetDictBy(sFontName.Mid(1)); if (!pFontDict && !bUseFormRes) { pDRDict = pFormDict->GetDictBy("DR"); diff --git a/core/fxcodec/codec/codec_int.h b/core/fxcodec/codec/codec_int.h index d2f44dd674..d19a694222 100644 --- a/core/fxcodec/codec/codec_int.h +++ b/core/fxcodec/codec/codec_int.h @@ -47,7 +47,6 @@ class CCodec_ScanlineDecoder : public ICodec_ScanlineDecoder { ~CCodec_ScanlineDecoder() override; // ICodec_ScanlineDecoder - FX_DWORD GetSrcOffset() override { return -1; } void DownScale(int dest_width, int dest_height) override; const uint8_t* GetScanline(int line) override; FX_BOOL SkipToScanline(int line, IFX_Pause* pPause) override; diff --git a/core/fxcodec/codec/fx_codec_flate.cpp b/core/fxcodec/codec/fx_codec_flate.cpp index 49a4f34166..27416f1c67 100644 --- a/core/fxcodec/codec/fx_codec_flate.cpp +++ b/core/fxcodec/codec/fx_codec_flate.cpp @@ -147,7 +147,7 @@ int CLZWDecoder::Decode(uint8_t* dest_buf, m_Early = bEarlyChange ? 1 : 0; m_nCodes = 0; FX_DWORD old_code = (FX_DWORD)-1; - uint8_t last_char; + uint8_t last_char = 0; while (1) { if (m_InPos + m_CodeLen > src_size * 8) { break; @@ -942,7 +942,7 @@ FX_DWORD CCodec_FlateModule::FlateOrLZWDecode(FX_BOOL bLZW, offset = src_size; int err = decoder->Decode(NULL, dest_size, src_buf, offset, bEarlyChange); if (err || dest_size == 0 || dest_size + 1 < dest_size) { - return -1; + return static_cast(-1); } } { @@ -965,7 +965,7 @@ FX_DWORD CCodec_FlateModule::FlateOrLZWDecode(FX_BOOL bLZW, ret = TIFF_Predictor(dest_buf, dest_size, Colors, BitsPerComponent, Columns); } - return ret ? offset : -1; + return ret ? offset : static_cast(-1); } FX_BOOL CCodec_FlateModule::Encode(const uint8_t* src_buf, FX_DWORD src_size, diff --git a/core/fxcodec/codec/fx_codec_jpx_opj.cpp b/core/fxcodec/codec/fx_codec_jpx_opj.cpp index aaa89388b8..a57b93df22 100644 --- a/core/fxcodec/codec/fx_codec_jpx_opj.cpp +++ b/core/fxcodec/codec/fx_codec_jpx_opj.cpp @@ -24,16 +24,17 @@ static void fx_warning_callback(const char* msg, void* client_data) { static void fx_info_callback(const char* msg, void* client_data) { (void)client_data; } + OPJ_SIZE_T opj_read_from_memory(void* p_buffer, OPJ_SIZE_T nb_bytes, void* p_user_data) { DecodeData* srcData = static_cast(p_user_data); if (!srcData || !srcData->src_data || srcData->src_size == 0) { - return -1; + return static_cast(-1); } // Reads at EOF return an error code. if (srcData->offset >= srcData->src_size) { - return -1; + return static_cast(-1); } OPJ_SIZE_T bufferLength = srcData->src_size - srcData->offset; OPJ_SIZE_T readlength = nb_bytes < bufferLength ? nb_bytes : bufferLength; @@ -41,16 +42,17 @@ OPJ_SIZE_T opj_read_from_memory(void* p_buffer, srcData->offset += readlength; return readlength; } + OPJ_SIZE_T opj_write_from_memory(void* p_buffer, OPJ_SIZE_T nb_bytes, void* p_user_data) { DecodeData* srcData = static_cast(p_user_data); if (!srcData || !srcData->src_data || srcData->src_size == 0) { - return -1; + return static_cast(-1); } // Writes at EOF return an error code. if (srcData->offset >= srcData->src_size) { - return -1; + return static_cast(-1); } OPJ_SIZE_T bufferLength = srcData->src_size - srcData->offset; OPJ_SIZE_T writeLength = nb_bytes < bufferLength ? nb_bytes : bufferLength; @@ -58,17 +60,18 @@ OPJ_SIZE_T opj_write_from_memory(void* p_buffer, srcData->offset += writeLength; return writeLength; } + OPJ_OFF_T opj_skip_from_memory(OPJ_OFF_T nb_bytes, void* p_user_data) { DecodeData* srcData = static_cast(p_user_data); if (!srcData || !srcData->src_data || srcData->src_size == 0) { - return -1; + return static_cast(-1); } // Offsets are signed and may indicate a negative skip. Do not support this // because of the strange return convention where either bytes skipped or // -1 is returned. Following that convention, a successful relative seek of // -1 bytes would be required to to give the same result as the error case. if (nb_bytes < 0) { - return -1; + return static_cast(-1); } // FIXME: use std::make_unsigned::type once c++11 lib is OK'd. uint64_t unsignedNbBytes = static_cast(nb_bytes); @@ -89,6 +92,7 @@ OPJ_OFF_T opj_skip_from_memory(OPJ_OFF_T nb_bytes, void* p_user_data) { } return nb_bytes; } + OPJ_BOOL opj_seek_from_memory(OPJ_OFF_T nb_bytes, void* p_user_data) { DecodeData* srcData = static_cast(p_user_data); if (!srcData || !srcData->src_data || srcData->src_size == 0) { diff --git a/core/fxcodec/codec/fx_codec_tiff.cpp b/core/fxcodec/codec/fx_codec_tiff.cpp index 2af92f2f12..0312622fb4 100644 --- a/core/fxcodec/codec/fx_codec_tiff.cpp +++ b/core/fxcodec/codec/fx_codec_tiff.cpp @@ -122,20 +122,20 @@ static toff_t _tiff_seek(thandle_t context, toff_t offset, int whence) { case 2: if (pTiffContext->isDecoder) { if (pTiffContext->io.in->GetSize() < (FX_FILESIZE)offset) { - return -1; + return static_cast(-1); } pTiffContext->offset = (FX_DWORD)(pTiffContext->io.in->GetSize() - offset); } else { if (pTiffContext->io.out->GetSize() < (FX_FILESIZE)offset) { - return -1; + return static_cast(-1); } pTiffContext->offset = (FX_DWORD)(pTiffContext->io.out->GetSize() - offset); } break; default: - return -1; + return static_cast(-1); } ASSERT(pTiffContext->isDecoder ? (pTiffContext->offset <= (FX_DWORD)pTiffContext->io.in->GetSize()) diff --git a/core/fxcodec/jbig2/JBig2_Context.cpp b/core/fxcodec/jbig2/JBig2_Context.cpp index 89157b9bf1..805a102c74 100644 --- a/core/fxcodec/jbig2/JBig2_Context.cpp +++ b/core/fxcodec/jbig2/JBig2_Context.cpp @@ -201,7 +201,7 @@ int32_t CJBig2_Context::getFirstPage(uint8_t* pBuf, } int32_t CJBig2_Context::Continue(IFX_Pause* pPause) { m_ProcessingStatus = FXCODEC_STATUS_DECODE_READY; - int32_t nRet; + int32_t nRet = 0; if (m_PauseStep <= 1) { nRet = decode_EmbedOrgnazation(pPause); } else if (m_PauseStep == 2) { @@ -683,14 +683,14 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) { } pTRD->SBRTEMPLATE = (wFlags >> 15) & 0x0001; - uint8_t cSBHUFFFS; - uint8_t cSBHUFFDS; - uint8_t cSBHUFFDT; - uint8_t cSBHUFFRDW; - uint8_t cSBHUFFRDH; - uint8_t cSBHUFFRDX; - uint8_t cSBHUFFRDY; - uint8_t cSBHUFFRSIZE; + uint8_t cSBHUFFFS = 0; + uint8_t cSBHUFFDS = 0; + uint8_t cSBHUFFDT = 0; + uint8_t cSBHUFFRDW = 0; + uint8_t cSBHUFFRDH = 0; + uint8_t cSBHUFFRDX = 0; + uint8_t cSBHUFFRDY = 0; + uint8_t cSBHUFFRSIZE = 0; if (pTRD->SBHUFF == 1) { if (m_pStream->readShortInteger(&wFlags) != 0) return JBIG2_ERROR_TOO_SHORT; diff --git a/core/fxcodec/jbig2/JBig2_Image.cpp b/core/fxcodec/jbig2/JBig2_Image.cpp index 311c38270e..dddc1d29d0 100644 --- a/core/fxcodec/jbig2/JBig2_Image.cpp +++ b/core/fxcodec/jbig2/JBig2_Image.cpp @@ -665,74 +665,46 @@ FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, int32_t y, JBig2ComposeOp op, const FX_RECT* pSrcRect) { - int32_t xs0, ys0, xs1, ys1, xd0, yd0, xd1, yd1, xx, yy, w, h, middleDwords, - lineLeft; - FX_DWORD s1, d1, d2, shift, shift1, shift2, tmp, tmp1, tmp2, maskL, maskR, - maskM; - uint8_t *lineSrc, *lineDst, *sp, *dp; - int32_t sw, sh; if (!m_pData) { return FALSE; } + // TODO(weili): Check whether the range check is correct. Should x>=1048576? if (x < -1048576 || x > 1048576 || y < -1048576 || y > 1048576) { return FALSE; } - sw = pSrcRect->Width(); - sh = pSrcRect->Height(); - if (y < 0) { - ys0 = -y; - } else { - ys0 = 0; - } - if (y + sh > pDst->m_nHeight) { - ys1 = pDst->m_nHeight - y; - } else { - ys1 = sh; - } - if (x < 0) { - xs0 = -x; - } else { - xs0 = 0; - } - if (x + sw > pDst->m_nWidth) { - xs1 = pDst->m_nWidth - x; - } else { - xs1 = sw; - } + int32_t sw = pSrcRect->Width(); + int32_t sh = pSrcRect->Height(); + int32_t ys0 = y < 0 ? -y : 0; + int32_t ys1 = y + sh > pDst->m_nHeight ? pDst->m_nHeight - y : sh; + int32_t xs0 = x < 0 ? -x : 0; + int32_t xs1 = x + sw > pDst->m_nWidth ? pDst->m_nWidth - x : sw; if ((ys0 >= ys1) || (xs0 >= xs1)) { return 0; } - w = xs1 - xs0; - h = ys1 - ys0; - if (y < 0) { - yd0 = 0; - } else { - yd0 = y; - } - if (x < 0) { - xd0 = 0; - } else { - xd0 = x; - } - xd1 = xd0 + w; - yd1 = yd0 + h; - d1 = xd0 & 31; - d2 = xd1 & 31; - s1 = xs0 & 31; - maskL = 0xffffffff >> d1; - maskR = 0xffffffff << ((32 - (xd1 & 31)) % 32); - maskM = maskL & maskR; - lineSrc = m_pData + (pSrcRect->top + ys0) * m_nStride + - (((xs0 + pSrcRect->left) >> 5) << 2); - lineLeft = m_nStride - ((xs0 >> 5) << 2); - lineDst = pDst->m_pData + yd0 * pDst->m_nStride + ((xd0 >> 5) << 2); + int32_t w = xs1 - xs0; + int32_t h = ys1 - ys0; + int32_t yd0 = y < 0 ? 0 : y; + int32_t xd0 = x < 0 ? 0 : x; + int32_t xd1 = xd0 + w; + int32_t yd1 = yd0 + h; + int32_t d1 = xd0 & 31; + int32_t d2 = xd1 & 31; + int32_t s1 = xs0 & 31; + int32_t maskL = 0xffffffff >> d1; + int32_t maskR = 0xffffffff << ((32 - (xd1 & 31)) % 32); + int32_t maskM = maskL & maskR; + uint8_t* lineSrc = m_pData + (pSrcRect->top + ys0) * m_nStride + + (((xs0 + pSrcRect->left) >> 5) << 2); + int32_t lineLeft = m_nStride - ((xs0 >> 5) << 2); + uint8_t* lineDst = pDst->m_pData + yd0 * pDst->m_nStride + ((xd0 >> 5) << 2); if ((xd0 & ~31) == ((xd1 - 1) & ~31)) { if ((xs0 & ~31) == ((xs1 - 1) & ~31)) { if (s1 > d1) { - shift = s1 - d1; - for (yy = yd0; yy < yd1; yy++) { - tmp1 = JBIG2_GETDWORD(lineSrc) << shift; - tmp2 = JBIG2_GETDWORD(lineDst); + FX_DWORD shift = s1 - d1; + for (int32_t yy = yd0; yy < yd1; yy++) { + FX_DWORD tmp1 = JBIG2_GETDWORD(lineSrc) << shift; + FX_DWORD tmp2 = JBIG2_GETDWORD(lineDst); + FX_DWORD tmp = 0; switch (op) { case JBIG2_COMPOSE_OR: tmp = (tmp2 & ~maskM) | ((tmp1 | tmp2) & maskM); @@ -758,10 +730,11 @@ FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, lineDst += pDst->m_nStride; } } else { - shift = d1 - s1; - for (yy = yd0; yy < yd1; yy++) { - tmp1 = JBIG2_GETDWORD(lineSrc) >> shift; - tmp2 = JBIG2_GETDWORD(lineDst); + FX_DWORD shift = d1 - s1; + for (int32_t yy = yd0; yy < yd1; yy++) { + FX_DWORD tmp1 = JBIG2_GETDWORD(lineSrc) >> shift; + FX_DWORD tmp2 = JBIG2_GETDWORD(lineDst); + FX_DWORD tmp = 0; switch (op) { case JBIG2_COMPOSE_OR: tmp = (tmp2 & ~maskM) | ((tmp1 | tmp2) & maskM); @@ -788,12 +761,13 @@ FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, } } } else { - shift1 = s1 - d1; - shift2 = 32 - shift1; - for (yy = yd0; yy < yd1; yy++) { - tmp1 = (JBIG2_GETDWORD(lineSrc) << shift1) | - (JBIG2_GETDWORD(lineSrc + 4) >> shift2); - tmp2 = JBIG2_GETDWORD(lineDst); + FX_DWORD shift1 = s1 - d1; + FX_DWORD shift2 = 32 - shift1; + for (int32_t yy = yd0; yy < yd1; yy++) { + FX_DWORD tmp1 = (JBIG2_GETDWORD(lineSrc) << shift1) | + (JBIG2_GETDWORD(lineSrc + 4) >> shift2); + FX_DWORD tmp2 = JBIG2_GETDWORD(lineDst); + FX_DWORD tmp = 0; switch (op) { case JBIG2_COMPOSE_OR: tmp = (tmp2 & ~maskM) | ((tmp1 | tmp2) & maskM); @@ -821,16 +795,17 @@ FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, } } else { if (s1 > d1) { - shift1 = s1 - d1; - shift2 = 32 - shift1; - middleDwords = (xd1 >> 5) - ((xd0 + 31) >> 5); - for (yy = yd0; yy < yd1; yy++) { - sp = lineSrc; - dp = lineDst; + FX_DWORD shift1 = s1 - d1; + FX_DWORD shift2 = 32 - shift1; + int32_t middleDwords = (xd1 >> 5) - ((xd0 + 31) >> 5); + for (int32_t yy = yd0; yy < yd1; yy++) { + uint8_t* sp = lineSrc; + uint8_t* dp = lineDst; if (d1 != 0) { - tmp1 = (JBIG2_GETDWORD(sp) << shift1) | - (JBIG2_GETDWORD(sp + 4) >> shift2); - tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp1 = (JBIG2_GETDWORD(sp) << shift1) | + (JBIG2_GETDWORD(sp + 4) >> shift2); + FX_DWORD tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp = 0; switch (op) { case JBIG2_COMPOSE_OR: tmp = (tmp2 & ~maskL) | ((tmp1 | tmp2) & maskL); @@ -855,10 +830,11 @@ FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, sp += 4; dp += 4; } - for (xx = 0; xx < middleDwords; xx++) { - tmp1 = (JBIG2_GETDWORD(sp) << shift1) | - (JBIG2_GETDWORD(sp + 4) >> shift2); - tmp2 = JBIG2_GETDWORD(dp); + for (int32_t xx = 0; xx < middleDwords; xx++) { + FX_DWORD tmp1 = (JBIG2_GETDWORD(sp) << shift1) | + (JBIG2_GETDWORD(sp + 4) >> shift2); + FX_DWORD tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp = 0; switch (op) { case JBIG2_COMPOSE_OR: tmp = tmp1 | tmp2; @@ -884,11 +860,12 @@ FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, dp += 4; } if (d2 != 0) { - tmp1 = + FX_DWORD tmp1 = (JBIG2_GETDWORD(sp) << shift1) | (((sp + 4) < lineSrc + lineLeft ? JBIG2_GETDWORD(sp + 4) : 0) >> shift2); - tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp = 0; switch (op) { case JBIG2_COMPOSE_OR: tmp = (tmp2 & ~maskR) | ((tmp1 | tmp2) & maskR); @@ -915,13 +892,14 @@ FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, lineDst += pDst->m_nStride; } } else if (s1 == d1) { - middleDwords = (xd1 >> 5) - ((xd0 + 31) >> 5); - for (yy = yd0; yy < yd1; yy++) { - sp = lineSrc; - dp = lineDst; + int32_t middleDwords = (xd1 >> 5) - ((xd0 + 31) >> 5); + for (int32_t yy = yd0; yy < yd1; yy++) { + uint8_t* sp = lineSrc; + uint8_t* dp = lineDst; if (d1 != 0) { - tmp1 = JBIG2_GETDWORD(sp); - tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp1 = JBIG2_GETDWORD(sp); + FX_DWORD tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp = 0; switch (op) { case JBIG2_COMPOSE_OR: tmp = (tmp2 & ~maskL) | ((tmp1 | tmp2) & maskL); @@ -946,9 +924,10 @@ FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, sp += 4; dp += 4; } - for (xx = 0; xx < middleDwords; xx++) { - tmp1 = JBIG2_GETDWORD(sp); - tmp2 = JBIG2_GETDWORD(dp); + for (int32_t xx = 0; xx < middleDwords; xx++) { + FX_DWORD tmp1 = JBIG2_GETDWORD(sp); + FX_DWORD tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp = 0; switch (op) { case JBIG2_COMPOSE_OR: tmp = tmp1 | tmp2; @@ -974,8 +953,9 @@ FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, dp += 4; } if (d2 != 0) { - tmp1 = JBIG2_GETDWORD(sp); - tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp1 = JBIG2_GETDWORD(sp); + FX_DWORD tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp = 0; switch (op) { case JBIG2_COMPOSE_OR: tmp = (tmp2 & ~maskR) | ((tmp1 | tmp2) & maskR); @@ -1002,15 +982,16 @@ FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, lineDst += pDst->m_nStride; } } else { - shift1 = d1 - s1; - shift2 = 32 - shift1; - middleDwords = (xd1 >> 5) - ((xd0 + 31) >> 5); - for (yy = yd0; yy < yd1; yy++) { - sp = lineSrc; - dp = lineDst; + FX_DWORD shift1 = d1 - s1; + FX_DWORD shift2 = 32 - shift1; + int32_t middleDwords = (xd1 >> 5) - ((xd0 + 31) >> 5); + for (int32_t yy = yd0; yy < yd1; yy++) { + uint8_t* sp = lineSrc; + uint8_t* dp = lineDst; if (d1 != 0) { - tmp1 = JBIG2_GETDWORD(sp) >> shift1; - tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp1 = JBIG2_GETDWORD(sp) >> shift1; + FX_DWORD tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp = 0; switch (op) { case JBIG2_COMPOSE_OR: tmp = (tmp2 & ~maskL) | ((tmp1 | tmp2) & maskL); @@ -1034,10 +1015,11 @@ FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, dp[3] = (uint8_t)tmp; dp += 4; } - for (xx = 0; xx < middleDwords; xx++) { - tmp1 = (JBIG2_GETDWORD(sp) << shift2) | - ((JBIG2_GETDWORD(sp + 4)) >> shift1); - tmp2 = JBIG2_GETDWORD(dp); + for (int32_t xx = 0; xx < middleDwords; xx++) { + FX_DWORD tmp1 = (JBIG2_GETDWORD(sp) << shift2) | + ((JBIG2_GETDWORD(sp + 4)) >> shift1); + FX_DWORD tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp = 0; switch (op) { case JBIG2_COMPOSE_OR: tmp = tmp1 | tmp2; @@ -1063,11 +1045,12 @@ FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, dp += 4; } if (d2 != 0) { - tmp1 = + FX_DWORD tmp1 = (JBIG2_GETDWORD(sp) << shift2) | (((sp + 4) < lineSrc + lineLeft ? JBIG2_GETDWORD(sp + 4) : 0) >> shift1); - tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp = 0; switch (op) { case JBIG2_COMPOSE_OR: tmp = (tmp2 & ~maskR) | ((tmp1 | tmp2) & maskR); diff --git a/core/fxcodec/jbig2/JBig2_TrdProc.cpp b/core/fxcodec/jbig2/JBig2_TrdProc.cpp index 401249e3f2..1a078a1592 100644 --- a/core/fxcodec/jbig2/JBig2_TrdProc.cpp +++ b/core/fxcodec/jbig2/JBig2_TrdProc.cpp @@ -15,48 +15,39 @@ CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream, JBig2ArithCtx* grContext) { - int32_t STRIPT, FIRSTS; - FX_DWORD NINSTANCES; - int32_t DT, DFS, CURS; - int32_t SI, TI; - CJBig2_Image* IBI; - FX_DWORD WI, HI; - int32_t IDS; - FX_BOOL RI; - int32_t RDWI, RDHI, RDXI, RDYI; - CJBig2_Image* IBOI; - FX_DWORD WOI, HOI; - FX_BOOL bFirst; - FX_DWORD nTmp; - int32_t nVal, nBits; std::unique_ptr pHuffmanDecoder( new CJBig2_HuffmanDecoder(pStream)); std::unique_ptr SBREG(new CJBig2_Image(SBW, SBH)); SBREG->fill(SBDEFPIXEL); + int32_t STRIPT; if (pHuffmanDecoder->decodeAValue(SBHUFFDT, &STRIPT) != 0) return nullptr; STRIPT *= SBSTRIPS; STRIPT = -STRIPT; - FIRSTS = 0; - NINSTANCES = 0; + FX_DWORD NINSTANCES = 0; while (NINSTANCES < SBNUMINSTANCES) { + int32_t DT; if (pHuffmanDecoder->decodeAValue(SBHUFFDT, &DT) != 0) return nullptr; DT *= SBSTRIPS; STRIPT = STRIPT + DT; - bFirst = TRUE; + bool bFirst = true; + int32_t FIRSTS = 0; + int32_t CURS = 0; for (;;) { if (bFirst) { + int32_t DFS; if (pHuffmanDecoder->decodeAValue(SBHUFFFS, &DFS) != 0) return nullptr; FIRSTS = FIRSTS + DFS; CURS = FIRSTS; - bFirst = FALSE; + bFirst = false; } else { - nVal = pHuffmanDecoder->decodeAValue(SBHUFFDS, &IDS); + int32_t IDS; + int32_t nVal = pHuffmanDecoder->decodeAValue(SBHUFFDS, &IDS); if (nVal == JBIG2_OOB) { break; } else if (nVal != 0) { @@ -67,20 +58,22 @@ CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream, } uint8_t CURT = 0; if (SBSTRIPS != 1) { - nTmp = 1; + FX_DWORD nTmp = 1; while ((FX_DWORD)(1 << nTmp) < SBSTRIPS) { nTmp++; } + int32_t nVal; if (pStream->readNBits(nTmp, &nVal) != 0) return nullptr; CURT = nVal; } - TI = STRIPT + CURT; - nVal = 0; - nBits = 0; + int32_t TI = STRIPT + CURT; + int32_t nVal = 0; + int32_t nBits = 0; FX_DWORD IDI; for (;;) { + FX_DWORD nTmp; if (pStream->read1Bit(&nTmp) != 0) return nullptr; @@ -96,16 +89,18 @@ CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream, break; } } - if (SBREFINE == 0) { - RI = 0; - } else { - if (pStream->read1Bit(&RI) != 0) { - return nullptr; - } + FX_BOOL RI = 0; + if (SBREFINE != 0 && pStream->read1Bit(&RI) != 0) { + return nullptr; } + CJBig2_Image* IBI = nullptr; if (RI == 0) { IBI = SBSYMS[IDI]; } else { + int32_t RDWI; + int32_t RDHI; + int32_t RDXI; + int32_t RDYI; if ((pHuffmanDecoder->decodeAValue(SBHUFFRDW, &RDWI) != 0) || (pHuffmanDecoder->decodeAValue(SBHUFFRDH, &RDHI) != 0) || (pHuffmanDecoder->decodeAValue(SBHUFFRDX, &RDXI) != 0) || @@ -114,13 +109,13 @@ CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream, return nullptr; } pStream->alignByte(); - nTmp = pStream->getOffset(); - IBOI = SBSYMS[IDI]; + FX_DWORD nTmp = pStream->getOffset(); + CJBig2_Image* IBOI = SBSYMS[IDI]; if (!IBOI) return nullptr; - WOI = IBOI->m_nWidth; - HOI = IBOI->m_nHeight; + FX_DWORD WOI = IBOI->m_nWidth; + FX_DWORD HOI = IBOI->m_nHeight; if ((int)(WOI + RDWI) < 0 || (int)(HOI + RDHI) < 0) return nullptr; @@ -155,8 +150,8 @@ CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream, if (!IBI) { continue; } - WI = IBI->m_nWidth; - HI = IBI->m_nHeight; + FX_DWORD WI = IBI->m_nWidth; + FX_DWORD HI = IBI->m_nHeight; if (TRANSPOSED == 0 && ((REFCORNER == JBIG2_CORNER_TOPRIGHT) || (REFCORNER == JBIG2_CORNER_BOTTOMRIGHT))) { CURS = CURS + WI - 1; @@ -164,7 +159,7 @@ CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream, (REFCORNER == JBIG2_CORNER_BOTTOMRIGHT))) { CURS = CURS + HI - 1; } - SI = CURS; + int32_t SI = CURS; if (TRANSPOSED == 0) { switch (REFCORNER) { case JBIG2_CORNER_TOPLEFT: @@ -277,7 +272,7 @@ CJBig2_Image* CJBig2_TRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, int32_t FIRSTS = 0; FX_DWORD NINSTANCES = 0; while (NINSTANCES < SBNUMINSTANCES) { - int32_t CURS; + int32_t CURS = 0; int32_t DT; pIADT->decode(pArithDecoder, &DT); DT *= SBSTRIPS; diff --git a/core/fxcrt/fx_basic_maps.cpp b/core/fxcrt/fx_basic_maps.cpp index eb4f2868f5..bad1868286 100644 --- a/core/fxcrt/fx_basic_maps.cpp +++ b/core/fxcrt/fx_basic_maps.cpp @@ -39,19 +39,16 @@ void CFX_MapPtrToPtr::GetNextAssoc(FX_POSITION& rNextPosition, ASSERT(pAssocRet); if (pAssocRet == (CAssoc*)-1) { for (FX_DWORD nBucket = 0; nBucket < m_nHashTableSize; nBucket++) { - if ((pAssocRet = m_pHashTable[nBucket])) + pAssocRet = m_pHashTable[nBucket]; + if (pAssocRet) break; } ASSERT(pAssocRet); } - CAssoc* pAssocNext; - if ((pAssocNext = pAssocRet->pNext) == NULL) { - for (FX_DWORD nBucket = (HashKey(pAssocRet->key) % m_nHashTableSize) + 1; - nBucket < m_nHashTableSize; nBucket++) { - if ((pAssocNext = m_pHashTable[nBucket])) { - break; - } - } + CAssoc* pAssocNext = pAssocRet->pNext; + for (FX_DWORD nBucket = (HashKey(pAssocRet->key) % m_nHashTableSize) + 1; + nBucket < m_nHashTableSize && !pAssocNext; nBucket++) { + pAssocNext = m_pHashTable[nBucket]; } rNextPosition = (FX_POSITION)pAssocNext; rKey = pAssocRet->key; diff --git a/core/fxcrt/fx_basic_wstring.cpp b/core/fxcrt/fx_basic_wstring.cpp index 95b761bd09..8282bd5014 100644 --- a/core/fxcrt/fx_basic_wstring.cpp +++ b/core/fxcrt/fx_basic_wstring.cpp @@ -640,13 +640,12 @@ FX_STRSIZE CFX_WideString::Replace(const FX_WCHAR* lpszOld, FX_STRSIZE nCount = 0; FX_WCHAR* lpszStart = m_pData->m_String; FX_WCHAR* lpszEnd = m_pData->m_String + m_pData->m_nDataLength; - FX_WCHAR* lpszTarget; - { - while ((lpszTarget = (FX_WCHAR*)FXSYS_wcsstr(lpszStart, lpszOld)) && - lpszStart < lpszEnd) { - nCount++; - lpszStart = lpszTarget + nSourceLen; - } + while (lpszStart < lpszEnd) { + FX_WCHAR* lpszTarget = FXSYS_wcsstr(lpszStart, lpszOld); + if (!lpszTarget) + break; + nCount++; + lpszStart = lpszTarget + nSourceLen; } if (nCount > 0) { CopyBeforeWrite(); @@ -667,9 +666,10 @@ FX_STRSIZE CFX_WideString::Replace(const FX_WCHAR* lpszOld, lpszStart = m_pData->m_String; lpszEnd = m_pData->m_String + std::max(m_pData->m_nDataLength, nNewLength); { - while ((lpszTarget = (FX_WCHAR*)FXSYS_wcsstr(lpszStart, lpszOld)) != - NULL && - lpszStart < lpszEnd) { + while (lpszStart < lpszEnd) { + FX_WCHAR* lpszTarget = FXSYS_wcsstr(lpszStart, lpszOld); + if (!lpszTarget) + break; FX_STRSIZE nBalance = nOldLength - (FX_STRSIZE)(lpszTarget - m_pData->m_String + nSourceLen); diff --git a/core/fxge/dib/fx_dib_composite.cpp b/core/fxge/dib/fx_dib_composite.cpp index 0bf67ccb71..5bfe46e572 100644 --- a/core/fxge/dib/fx_dib_composite.cpp +++ b/core/fxge/dib/fx_dib_composite.cpp @@ -200,7 +200,9 @@ void _RGB_Blend(int blend_mode, const uint8_t* src_scan, uint8_t* dest_scan, int results[3]) { - _RGB src, back, result; + _RGB src; + _RGB back; + _RGB result = {0, 0, 0}; src.red = src_scan[2]; src.green = src_scan[1]; src.blue = src_scan[0]; @@ -291,7 +293,6 @@ void _CompositeRow_Argb2Graya(uint8_t* dest_scan, if (blend_type) { FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE; - int blended_color; if (src_alpha_scan) { for (int col = 0; col < pixel_count; col++) { uint8_t back_alpha = *dst_alpha_scan; @@ -332,12 +333,10 @@ void _CompositeRow_Argb2Graya(uint8_t* dest_scan, } else { gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan); } - if (bNonseparableBlend) { - blended_color = - blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan; - } - gray = bNonseparableBlend ? blended_color - : _BLEND(blend_type, *dest_scan, gray); + if (bNonseparableBlend) + gray = blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan; + else + gray = _BLEND(blend_type, *dest_scan, gray); *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio); dest_scan++; dst_alpha_scan++; @@ -498,7 +497,6 @@ inline void _CompositeRow_Argb2Gray(uint8_t* dest_scan, if (blend_type) { FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE; - int blended_color; if (src_alpha_scan) { for (int col = 0; col < pixel_count; col++) { int src_alpha = *src_alpha_scan++; @@ -511,12 +509,10 @@ inline void _CompositeRow_Argb2Gray(uint8_t* dest_scan, else gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan); - if (bNonseparableBlend) { - blended_color = - blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan; - } - gray = bNonseparableBlend ? blended_color - : _BLEND(blend_type, *dest_scan, gray); + if (bNonseparableBlend) + gray = blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan; + else + gray = _BLEND(blend_type, *dest_scan, gray); *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, src_alpha); } dest_scan++; @@ -534,12 +530,10 @@ inline void _CompositeRow_Argb2Gray(uint8_t* dest_scan, else gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan); - if (bNonseparableBlend) { - blended_color = - blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan; - } - gray = bNonseparableBlend ? blended_color - : _BLEND(blend_type, *dest_scan, gray); + if (bNonseparableBlend) + gray = blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan; + else + gray = _BLEND(blend_type, *dest_scan, gray); *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, src_alpha); } dest_scan++; @@ -599,19 +593,16 @@ inline void _CompositeRow_Rgb2Gray(uint8_t* dest_scan, } if (blend_type) { FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE; - int blended_color; for (int col = 0; col < pixel_count; col++) { if (pIccTransform) { pIccModule->TranslateScanline(pIccTransform, &gray, src_scan, 1); } else { gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan); } - if (bNonseparableBlend) { - blended_color = - blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan; - } - gray = bNonseparableBlend ? blended_color - : _BLEND(blend_type, *dest_scan, gray); + if (bNonseparableBlend) + gray = blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan; + else + gray = _BLEND(blend_type, *dest_scan, gray); if (clip_scan && clip_scan[col] < 255) { *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, clip_scan[col]); } else { @@ -650,7 +641,6 @@ void _CompositeRow_Rgb2Graya(uint8_t* dest_scan, pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule(); } if (blend_type) { - int blended_color; FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE; for (int col = 0; col < pixel_count; col++) { int back_alpha = *dest_alpha_scan; @@ -685,12 +675,10 @@ void _CompositeRow_Rgb2Graya(uint8_t* dest_scan, } else { gray = FXRGB2GRAY(src_scan[2], src_scan[1], *src_scan); } - if (bNonseparableBlend) { - blended_color = - blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan; - } - gray = bNonseparableBlend ? blended_color - : _BLEND(blend_type, *dest_scan, gray); + if (bNonseparableBlend) + gray = blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan; + else + gray = _BLEND(blend_type, *dest_scan, gray); *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio); dest_scan++; src_scan += src_Bpp; @@ -1849,19 +1837,16 @@ inline void _CompositeRow_8bppPal2Gray(uint8_t* dest_scan, if (src_alpha_scan) { if (blend_type) { FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE; - int blended_color; for (int col = 0; col < pixel_count; col++) { uint8_t gray = pPalette[*src_scan]; int src_alpha = *src_alpha_scan++; if (clip_scan) { src_alpha = clip_scan[col] * src_alpha / 255; } - if (bNonseparableBlend) { - blended_color = - blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan; - } - gray = bNonseparableBlend ? blended_color - : _BLEND(blend_type, *dest_scan, gray); + if (bNonseparableBlend) + gray = blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan; + else + gray = _BLEND(blend_type, *dest_scan, gray); if (src_alpha) { *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, src_alpha); } else { @@ -1889,15 +1874,12 @@ inline void _CompositeRow_8bppPal2Gray(uint8_t* dest_scan, } else { if (blend_type) { FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE; - int blended_color; for (int col = 0; col < pixel_count; col++) { uint8_t gray = pPalette[*src_scan]; - if (bNonseparableBlend) { - blended_color = - blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan; - } - gray = bNonseparableBlend ? blended_color - : _BLEND(blend_type, *dest_scan, gray); + if (bNonseparableBlend) + gray = blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan; + else + gray = _BLEND(blend_type, *dest_scan, gray); if (clip_scan && clip_scan[col] < 255) { *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, clip_scan[col]); } else { @@ -1931,7 +1913,6 @@ inline void _CompositeRow_8bppPal2Graya(uint8_t* dest_scan, if (src_alpha_scan) { if (blend_type) { FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE; - int blended_color; for (int col = 0; col < pixel_count; col++) { uint8_t gray = pPalette[*src_scan]; src_scan++; @@ -1961,12 +1942,10 @@ inline void _CompositeRow_8bppPal2Graya(uint8_t* dest_scan, *dest_alpha_scan = back_alpha + src_alpha - back_alpha * src_alpha / 255; int alpha_ratio = src_alpha * 255 / (*dest_alpha_scan); - if (bNonseparableBlend) { - blended_color = - blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan; - } - gray = bNonseparableBlend ? blended_color - : _BLEND(blend_type, *dest_scan, gray); + if (bNonseparableBlend) + gray = blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan; + else + gray = _BLEND(blend_type, *dest_scan, gray); *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio); dest_alpha_scan++; dest_scan++; @@ -2008,7 +1987,6 @@ inline void _CompositeRow_8bppPal2Graya(uint8_t* dest_scan, } else { if (blend_type) { FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE; - int blended_color; for (int col = 0; col < pixel_count; col++) { uint8_t gray = pPalette[*src_scan]; src_scan++; @@ -2028,12 +2006,10 @@ inline void _CompositeRow_8bppPal2Graya(uint8_t* dest_scan, back_alpha + src_alpha - back_alpha * src_alpha / 255; *dest_alpha_scan++ = dest_alpha; int alpha_ratio = src_alpha * 255 / dest_alpha; - if (bNonseparableBlend) { - blended_color = - blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan; - } - gray = bNonseparableBlend ? blended_color - : _BLEND(blend_type, *dest_scan, gray); + if (bNonseparableBlend) + gray = blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan; + else + gray = _BLEND(blend_type, *dest_scan, gray); *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio); dest_scan++; } @@ -2074,18 +2050,15 @@ inline void _CompositeRow_1bppPal2Gray(uint8_t* dest_scan, int set_gray = pPalette[1]; if (blend_type) { FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE; - int blended_color; for (int col = 0; col < pixel_count; col++) { uint8_t gray = (src_scan[(col + src_left) / 8] & (1 << (7 - (col + src_left) % 8))) ? set_gray : reset_gray; - if (bNonseparableBlend) { - blended_color = - blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan; - } - gray = bNonseparableBlend ? blended_color - : _BLEND(blend_type, *dest_scan, gray); + if (bNonseparableBlend) + gray = blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan; + else + gray = _BLEND(blend_type, *dest_scan, gray); if (clip_scan && clip_scan[col] < 255) { *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, clip_scan[col]); } else { @@ -2120,7 +2093,6 @@ inline void _CompositeRow_1bppPal2Graya(uint8_t* dest_scan, int set_gray = pPalette[1]; if (blend_type) { FX_BOOL bNonseparableBlend = blend_type >= FXDIB_BLEND_NONSEPARABLE; - int blended_color; for (int col = 0; col < pixel_count; col++) { uint8_t gray = (src_scan[(col + src_left) / 8] & (1 << (7 - (col + src_left) % 8))) @@ -2142,12 +2114,10 @@ inline void _CompositeRow_1bppPal2Graya(uint8_t* dest_scan, back_alpha + src_alpha - back_alpha * src_alpha / 255; *dest_alpha_scan++ = dest_alpha; int alpha_ratio = src_alpha * 255 / dest_alpha; - if (bNonseparableBlend) { - blended_color = - blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan; - } - gray = bNonseparableBlend ? blended_color - : _BLEND(blend_type, *dest_scan, gray); + if (bNonseparableBlend) + gray = blend_type == FXDIB_BLEND_LUMINOSITY ? gray : *dest_scan; + else + gray = _BLEND(blend_type, *dest_scan, gray); *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, alpha_ratio); dest_scan++; } diff --git a/core/fxge/dib/fx_dib_main.cpp b/core/fxge/dib/fx_dib_main.cpp index 8ce20568df..a7f7dc75bc 100644 --- a/core/fxge/dib/fx_dib_main.cpp +++ b/core/fxge/dib/fx_dib_main.cpp @@ -1234,14 +1234,31 @@ void CFX_DIBitmap::DownSampleScanline(int line, } } } + +// TODO(weili): Split this function into two for handling CMYK and RGB +// colors separately. FX_BOOL CFX_DIBitmap::ConvertColorScale(FX_DWORD forecolor, FX_DWORD backcolor) { ASSERT(!IsAlphaMask()); if (!m_pBuffer || IsAlphaMask()) { return FALSE; } - int fc, fm, fy, fk, bc, bm, by, bk; - int fr, fg, fb, br, bg, bb; + // Values used for CMYK colors. + int fc = 0; + int fm = 0; + int fy = 0; + int fk = 0; + int bc = 0; + int bm = 0; + int by = 0; + int bk = 0; + // Values used for RGB colors. + int fr = 0; + int fg = 0; + int fb = 0; + int br = 0; + int bg = 0; + int bb = 0; FX_BOOL isCmykImage = IsCmykImage(); if (isCmykImage) { fc = FXSYS_GetCValue(forecolor); diff --git a/core/fxge/ge/fx_ge_font.cpp b/core/fxge/ge/fx_ge_font.cpp index 67b968b44d..098195dded 100644 --- a/core/fxge/ge/fx_ge_font.cpp +++ b/core/fxge/ge/fx_ge_font.cpp @@ -522,7 +522,7 @@ FX_DWORD CFX_UnicodeEncodingEx::CharCodeFromUnicode(FX_WCHAR Unicode) const { return Unicode; } } - return -1; + return static_cast(-1); } CFX_UnicodeEncodingEx* FX_CreateFontEncodingEx(CFX_Font* pFont, diff --git a/core/fxge/ge/fx_ge_path.cpp b/core/fxge/ge/fx_ge_path.cpp index 0b52cdf9e4..de84de2518 100644 --- a/core/fxge/ge/fx_ge_path.cpp +++ b/core/fxge/ge/fx_ge_path.cpp @@ -340,7 +340,9 @@ CFX_FloatRect CFX_PathData::GetBoundingBox(FX_FLOAT line_width, -100000 * 1.0f); int iPoint = 0; FX_FLOAT half_width = line_width; - int iStartPoint, iEndPoint, iMiddlePoint; + int iStartPoint = 0; + int iEndPoint = 0; + int iMiddlePoint = 0; FX_BOOL bJoin; while (iPoint < m_PointCount) { if (m_pPoints[iPoint].m_Flag == FXPT_MOVETO) { diff --git a/core/fxge/ge/fx_ge_text.cpp b/core/fxge/ge/fx_ge_text.cpp index 3f001d2f96..bcc630ca71 100644 --- a/core/fxge/ge/fx_ge_text.cpp +++ b/core/fxge/ge/fx_ge_text.cpp @@ -375,7 +375,10 @@ FX_BOOL CFX_RenderDevice::DrawNormalText(int nChars, uint8_t* dest_buf = bitmap.GetBuffer(); int dest_pitch = bitmap.GetPitch(); int Bpp = bitmap.GetBPP() / 8; - int a, r, g, b; + int a = 0; + int r = 0; + int g = 0; + int b = 0; if (anti_alias == FXFT_RENDER_MODE_LCD) { _Color2Argb(fill_color, fill_color, alpha_flag | (1 << 24), pIccTransform); ArgbDecode(fill_color, a, r, g, b); diff --git a/core/fxge/win32/fx_win32_gdipext.cpp b/core/fxge/win32/fx_win32_gdipext.cpp index ce181bb448..2fdfa3a8c7 100644 --- a/core/fxge/win32/fx_win32_gdipext.cpp +++ b/core/fxge/win32/fx_win32_gdipext.cpp @@ -982,7 +982,7 @@ static GpPen* _GdipCreatePen(const CFX_GraphStateData* pGraphState, } GpPen* pPen = NULL; CallFunc(GdipCreatePen1)((ARGB)argb, width, UnitWorld, &pPen); - LineCap lineCap; + LineCap lineCap = LineCapFlat; DashCap dashCap = DashCapFlat; FX_BOOL bDashExtend = FALSE; switch (pGraphState->m_LineCap) { @@ -1000,7 +1000,7 @@ static GpPen* _GdipCreatePen(const CFX_GraphStateData* pGraphState, break; } CallFunc(GdipSetPenLineCap197819)(pPen, lineCap, lineCap, dashCap); - LineJoin lineJoin; + LineJoin lineJoin = LineJoinMiterClipped; switch (pGraphState->m_LineJoin) { case CFX_GraphStateData::LineJoinMiter: lineJoin = LineJoinMiterClipped; -- cgit v1.2.3