Commit 9debcfaf0e7398c7de140e3e5ced0a95d3a43aa2
1 parent
fd925950
修复crop边界导致崩溃的问题
Showing
1 changed file
with
24 additions
and
0 deletions
src/utils/CropUtil.cpp
... | ... | @@ -46,6 +46,28 @@ int CropUtil::release(){ |
46 | 46 | aclrtDestroyContext(m_ctx); |
47 | 47 | } |
48 | 48 | |
49 | +static void adj_position(ImageData& src, uint32_t& xmin, uint32_t& ymin, uint32_t& xmax, uint32_t& ymax) { | |
50 | + if (xmin < 0) | |
51 | + { | |
52 | + xmin = 0; | |
53 | + } | |
54 | + | |
55 | + if (ymin < 0) | |
56 | + { | |
57 | + ymin = 0; | |
58 | + } | |
59 | + | |
60 | + if (xmax > src.width) | |
61 | + { | |
62 | + xmax = src.width; | |
63 | + } | |
64 | + | |
65 | + if (ymax > src.height) | |
66 | + { | |
67 | + ymax = src.height; | |
68 | + } | |
69 | +} | |
70 | + | |
49 | 71 | ImageData* CropUtil::crop(ImageData& src, uint32_t xmin, uint32_t ymin, uint32_t xmax, uint32_t ymax) { |
50 | 72 | int ret = aclrtSetCurrentContext(m_ctx); |
51 | 73 | if (ACL_SUCCESS != ret) |
... | ... | @@ -53,6 +75,8 @@ ImageData* CropUtil::crop(ImageData& src, uint32_t xmin, uint32_t ymin, uint32_t |
53 | 75 | return nullptr; |
54 | 76 | } |
55 | 77 | |
78 | + adj_position(src, xmin, ymin, xmax, ymax); | |
79 | + | |
56 | 80 | int width = xmax - xmin; |
57 | 81 | int height = ymax - ymin; |
58 | 82 | uint32_t alignWidth = (width + 127) / 128 * 128; | ... | ... |