diff --git a/frameworks/common/image.cpp b/frameworks/common/image.cpp index e88e5fc74647008558bf42f6c6a3a8945822ee34..7620d4edeb4fb7d97d1940db13df7c2c4c1dcedb 100755 --- a/frameworks/common/image.cpp +++ b/frameworks/common/image.cpp @@ -33,16 +33,9 @@ Image::~Image() if (srcType_ == IMG_SRC_FILE) { CacheManager::GetInstance().Close(path_); } - if (imageInfo_ != nullptr) { - if (mallocFlag_) { - if (imageInfo_->data != nullptr) { - UIFree(reinterpret_cast(const_cast(imageInfo_->data))); - } - mallocFlag_ = false; - } - UIFree(reinterpret_cast(const_cast(imageInfo_))); - imageInfo_ = nullptr; - } + + ReInitImageInfo(nullptr, false); + if (path_ != nullptr) { UIFree(reinterpret_cast(const_cast(path_))); path_ = nullptr; @@ -92,9 +85,10 @@ bool Image::SetStandardSrc(const char* src) if (src == nullptr) { return false; } + srcType_ = IMG_SRC_UNKNOWN; + const char* ptr = strrchr(src, '.'); if (ptr == nullptr) { - srcType_ = IMG_SRC_UNKNOWN; return false; } @@ -110,14 +104,12 @@ bool Image::SetStandardSrc(const char* src) size_t strLen = strlen(src) + 1; char* imagePath = static_cast(UIMalloc(static_cast(strLen))); if (imagePath == nullptr) { - srcType_ = IMG_SRC_UNKNOWN; return false; } if (strcpy_s(imagePath, strLen, src) != EOK) { UIFree(reinterpret_cast(imagePath)); imagePath = nullptr; - srcType_ = IMG_SRC_UNKNOWN; return false; } path_ = imagePath; @@ -130,16 +122,16 @@ bool Image::SetLiteSrc(const char* src) if (src == nullptr) { return false; } + srcType_ = IMG_SRC_UNKNOWN; + const char* ptr = strrchr(src, '.'); if (ptr == nullptr) { - srcType_ = IMG_SRC_UNKNOWN; return false; } size_t strLen = strlen(src) + 1; char* imagePath = static_cast(UIMalloc(static_cast(strLen))); if (imagePath == nullptr) { - srcType_ = IMG_SRC_UNKNOWN; return false; } if (IsImgValid(ptr)) { @@ -147,21 +139,18 @@ bool Image::SetLiteSrc(const char* src) if (memcpy_s(imagePath, strLen, src, strLen) != EOK) { UIFree(reinterpret_cast(imagePath)); imagePath = nullptr; - srcType_ = IMG_SRC_UNKNOWN; return false; } (ptr - src + imagePath)[1] = '\0'; // remove suffix if (strcat_s(imagePath, strLen, suffixName) != EOK) { UIFree(reinterpret_cast(imagePath)); imagePath = nullptr; - srcType_ = IMG_SRC_UNKNOWN; return false; } } else { if (memcpy_s(imagePath, strLen, src, strLen) != EOK) { UIFree(reinterpret_cast(imagePath)); imagePath = nullptr; - srcType_ = IMG_SRC_UNKNOWN; return false; } } @@ -184,43 +173,30 @@ bool Image::SetSrc(const char* src) return SetStandardSrc(src); } return SetLiteSrc(src); - } else { - path_ = src; - srcType_ = IMG_SRC_UNKNOWN; } + srcType_ = IMG_SRC_UNKNOWN; return true; } bool Image::SetSrc(const ImageInfo* src) { - if (imageInfo_ != nullptr) { - if (mallocFlag_) { - if (imageInfo_->data != nullptr) { - UIFree(reinterpret_cast(const_cast(imageInfo_->data))); - } - mallocFlag_ = false; - } - UIFree(reinterpret_cast(const_cast(imageInfo_))); - imageInfo_ = nullptr; - } + ReInitImageInfo(nullptr, false); + srcType_ = IMG_SRC_UNKNOWN; + imageInfo_ = nullptr; if (src != nullptr) { imageInfo_ = static_cast(UIMalloc(static_cast(sizeof(ImageInfo)))); if (imageInfo_ == nullptr) { - srcType_ = IMG_SRC_UNKNOWN; return false; } if (memcpy_s(const_cast(imageInfo_), sizeof(ImageInfo), src, sizeof(ImageInfo)) != EOK) { - srcType_ = IMG_SRC_UNKNOWN; return false; } srcType_ = IMG_SRC_VARIABLE; - } else { - imageInfo_ = src; - srcType_ = IMG_SRC_UNKNOWN; } + return true; } @@ -240,24 +216,50 @@ void Image::DrawImage(BufferInfo& gfxDstBuffer, } #if ENABLE_JPEG_AND_PNG + +static inline void FreePngBytep(png_bytep** rowPointer, uint16_t size) +{ + png_bytep* tmpRowPointer = *rowPointer; + for (uint16_t i = 0; i < size; i++) { + UIFree(tmpRowPointer[i]); + tmpRowPointer[i] = nullptr; + } + UIFree(*rowPointer); + *rowPointer = nullptr; +} + +static inline png_bytep* MallocPngBytep(uint16_t height, uint32_t rowBytes) +{ + png_bytep* rowPointer = static_cast(UIMalloc(sizeof(png_bytep) * height)); + if (rowPointer == nullptr) { + return nullptr; + } + for (uint16_t y = 0; y < height; y++) { + rowPointer[y] = static_cast(UIMalloc(rowBytes)); + if (rowPointer[y] == nullptr) { + FreePngBytep(&rowPointer, y); + return nullptr; + } + } + return rowPointer; +} + bool Image::SetPNGSrc(const char* src) { + srcType_ = IMG_SRC_UNKNOWN; FILE* infile = nullptr; png_bytep* rowPointer = nullptr; png_structp png = png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr); if (png == nullptr) { - srcType_ = IMG_SRC_UNKNOWN; return false; } png_infop info = png_create_info_struct(png); if (info == nullptr) { - srcType_ = IMG_SRC_UNKNOWN; png_destroy_read_struct(&png, &info, nullptr); return false; } if ((infile = fopen(src, "rb")) == nullptr) { GRAPHIC_LOGE("can't open %s\n", src); - srcType_ = IMG_SRC_UNKNOWN; png_destroy_read_struct(&png, &info, nullptr); return false; } @@ -292,49 +294,26 @@ bool Image::SetPNGSrc(const char* src) png_set_interlace_handling(png); png_read_update_info(png, info); - rowPointer = static_cast(UIMalloc(sizeof(png_bytep) * height)); + rowPointer = MallocPngBytep(height, png_get_rowbytes(png, info)); if (rowPointer == nullptr) { - srcType_ = IMG_SRC_UNKNOWN; fclose(infile); png_destroy_read_struct(&png, &info, nullptr); return false; } - for (uint16_t y = 0; y < height; y++) { - rowPointer[y] = static_cast(UIMalloc(png_get_rowbytes(png, info))); - if (rowPointer[y] == nullptr) { - for (uint16_t i = 0; i < y; i++) { - UIFree(rowPointer[i]); - rowPointer[i] = nullptr; - } - fclose(infile); - UIFree(rowPointer); - srcType_ = IMG_SRC_UNKNOWN; - png_destroy_read_struct(&png, &info, nullptr); - return false; - } - } + png_read_image(png, rowPointer); fclose(infile); png_destroy_read_struct(&png, &info, nullptr); + ImageInfo* imgInfo = static_cast(UIMalloc(sizeof(ImageInfo))); if (imgInfo == nullptr) { - for (uint16_t i = 0; i < height; i++) { - UIFree(rowPointer[i]); - rowPointer[i] = nullptr; - } - UIFree(rowPointer); - srcType_ = IMG_SRC_UNKNOWN; + FreePngBytep(&rowPointer, height); return false; } uint8_t* srcData = static_cast(UIMalloc(dataSize)); if (srcData == nullptr) { - for (uint16_t i = 0; i < height; i++) { - UIFree(rowPointer[i]); - rowPointer[i] = nullptr; - } - UIFree(rowPointer); + FreePngBytep(&rowPointer, height); UIFree(imgInfo); - srcType_ = IMG_SRC_UNKNOWN; return false; } uint32_t n = 0; @@ -346,10 +325,8 @@ bool Image::SetPNGSrc(const char* src) srcData[n++] = row[x + 0]; // 0: R channel srcData[n++] = row[x + 3]; // 3: Alpha channel } - UIFree(row); - row = nullptr; } - UIFree(rowPointer); + FreePngBytep(&rowPointer, height); imgInfo->header.width = width; imgInfo->header.height = height; @@ -357,18 +334,7 @@ bool Image::SetPNGSrc(const char* src) imgInfo->dataSize = dataSize; imgInfo->data = srcData; - if (imageInfo_ != nullptr) { - if (mallocFlag_) { - if (imageInfo_->data != nullptr) { - UIFree(reinterpret_cast(const_cast(imageInfo_->data))); - } - mallocFlag_ = false; - } - UIFree(reinterpret_cast(const_cast(imageInfo_))); - imageInfo_ = nullptr; - } - imageInfo_ = imgInfo; - mallocFlag_ = true; + ReInitImageInfo(imgInfo, true); srcType_ = IMG_SRC_VARIABLE; return true; } @@ -378,10 +344,10 @@ bool Image::SetJPEGSrc(const char* src) struct jpeg_decompress_struct cinfo; struct jpeg_error_mgr jerr; FILE* infile = nullptr; + srcType_ = IMG_SRC_UNKNOWN; if ((infile = fopen(src, "rb")) == nullptr) { GRAPHIC_LOGE("can't open %s\n", src); - srcType_ = IMG_SRC_UNKNOWN; return false; } cinfo.err = jpeg_std_error(&jerr); @@ -402,7 +368,6 @@ bool Image::SetJPEGSrc(const char* src) jpeg_finish_decompress(&cinfo); jpeg_destroy_decompress(&cinfo); fclose(infile); - srcType_ = IMG_SRC_UNKNOWN; return false; } uint8_t* srcData = static_cast(UIMalloc(dataSize)); @@ -411,7 +376,6 @@ bool Image::SetJPEGSrc(const char* src) jpeg_destroy_decompress(&cinfo); fclose(infile); UIFree(imgInfo); - srcType_ = IMG_SRC_UNKNOWN; return false; } uint32_t n = 0; @@ -434,20 +398,22 @@ bool Image::SetJPEGSrc(const char* src) imgInfo->dataSize = dataSize; imgInfo->data = srcData; - if (imageInfo_ != nullptr) { - if (mallocFlag_) { - if (imageInfo_->data != nullptr) { - UIFree(reinterpret_cast(const_cast(imageInfo_->data))); - } - mallocFlag_ = false; - } - UIFree(reinterpret_cast(const_cast(imageInfo_))); - imageInfo_ = nullptr; - } - imageInfo_ = imgInfo; - mallocFlag_ = true; + ReInitImageInfo(imgInfo, true); srcType_ = IMG_SRC_VARIABLE; return true; } #endif + +void Image::ReInitImageInfo(ImageInfo* imgInfo, bool mallocFlag) +{ + if (mallocFlag_) { + if (imageInfo_->data != nullptr) { + UIFree(reinterpret_cast(const_cast(imageInfo_->data))); + } + } + UIFree(reinterpret_cast(const_cast(imageInfo_))); + + imageInfo_ = imgInfo; + mallocFlag_ = mallocFlag; +} } // namespace OHOS \ No newline at end of file diff --git a/frameworks/components/ui_arc_scroll_bar.cpp b/frameworks/components/ui_arc_scroll_bar.cpp old mode 100644 new mode 100755 index 3e2d151c9f521da7358acd1a96836c724382e936..c667e41ab74c03d84a80a14dc12221c79196b798 --- a/frameworks/components/ui_arc_scroll_bar.cpp +++ b/frameworks/components/ui_arc_scroll_bar.cpp @@ -92,7 +92,7 @@ void UIArcScrollBar::DrawForeground(BufferInfo& gfxDstBuffer, const Rect& invali if ((startAngle > endAngle_) || (endAngle < startAngle_)) { return; } - ArcInfo arcInfo = {0}; + ArcInfo arcInfo = {{0, 0}, {0, 0}, 0, 0, 0, nullptr}; arcInfo.radius = (radius_ > 0) ? (radius_ - 1) : 0; arcInfo.center = center_; arcInfo.startAngle = MATH_MAX(startAngle, startAngle_); @@ -103,7 +103,7 @@ void UIArcScrollBar::DrawForeground(BufferInfo& gfxDstBuffer, const Rect& invali void UIArcScrollBar::DrawBackground(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea, uint8_t backgroundOpa) { - ArcInfo arcInfo = {0}; + ArcInfo arcInfo = {{0, 0}, {0, 0}, 0, 0, 0, nullptr}; arcInfo.radius = radius_; arcInfo.center = center_; arcInfo.startAngle = startAngle_; diff --git a/frameworks/dock/screen_device_proxy.cpp b/frameworks/dock/screen_device_proxy.cpp index 73fe10e4e0c8e7369592960de69ce09f49a1c551..2ea4b4afa9be6f9af5b8a75d518e0c9235a39898 100755 --- a/frameworks/dock/screen_device_proxy.cpp +++ b/frameworks/dock/screen_device_proxy.cpp @@ -41,15 +41,6 @@ void ScreenDeviceProxy::OnRenderFinish(const Rect& mask) void ScreenDeviceProxy::DrawAnimatorBuffer(const Rect& invalidatedArea) { - Rect invalidRect = curViewRect_; - transMap_.SetTransMapRect(curViewRect_); - invalidRect.Join(invalidRect, transMap_.GetBoxRect()); - - if (invalidRect.Intersect(invalidRect, invalidatedArea)) { - uint8_t pxSize = DrawUtils::GetPxSizeByColorMode(animatorImageInfo_.header.colorMode); - TransformDataInfo imageTranDataInfo = {animatorImageInfo_.header, animatorImageInfo_.data, pxSize, LEVEL0, - BILINEAR}; - } } void ScreenDeviceProxy::SetAnimatorRect(const Rect& rect) diff --git a/frameworks/draw/draw_utils.cpp b/frameworks/draw/draw_utils.cpp index baca057e037fbaca190f80128fdc60238c7920d6..b220105eee77388c9cdd306994f135ca344b9d59 100755 --- a/frameworks/draw/draw_utils.cpp +++ b/frameworks/draw/draw_utils.cpp @@ -146,10 +146,6 @@ namespace OHOS { ASSERT(0); \ } -#ifdef VERSION_STANDARD -const int16_t HARDWARE_ACC_SIZE_LIMIT = 50 * 50; -#endif - namespace { static constexpr uint8_t OPACITY_STEP_A1 = 255; static constexpr uint8_t OPACITY_STEP_A2 = 85; diff --git a/interfaces/kits/common/image.h b/interfaces/kits/common/image.h index ba89a55878133bef01b7034046889db17896384a..5c8e186b70c33426b4ad1c0e77e29afa239fd4e5 100755 --- a/interfaces/kits/common/image.h +++ b/interfaces/kits/common/image.h @@ -169,6 +169,7 @@ private: !strcmp(suffix, ".JPG") || !strcmp(suffix, ".jpeg") || !strcmp(suffix, ".JPEG") || !strcmp(suffix, ".BMP") || !strcmp(suffix, ".bmp")); } + void ReInitImageInfo(ImageInfo* imgInfo, bool mallocFlag); }; } // namespace OHOS #endif // GRAPHIC_LITE_IMAGE_H