Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(194)

Side by Side Diff: third_party/libwebp/enc/picture_rescale.c

Issue 1546003002: libwebp: update to 0.5.0 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase around clang-cl fix Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 Google Inc. All Rights Reserved. 1 // Copyright 2014 Google Inc. All Rights Reserved.
2 // 2 //
3 // Use of this source code is governed by a BSD-style license 3 // Use of this source code is governed by a BSD-style license
4 // that can be found in the COPYING file in the root of the source 4 // that can be found in the COPYING file in the root of the source
5 // tree. An additional intellectual property rights grant can be found 5 // tree. An additional intellectual property rights grant can be found
6 // in the file PATENTS. All contributing project authors may 6 // in the file PATENTS. All contributing project authors may
7 // be found in the AUTHORS file in the root of the source tree. 7 // be found in the AUTHORS file in the root of the source tree.
8 // ----------------------------------------------------------------------------- 8 // -----------------------------------------------------------------------------
9 // 9 //
10 // WebPPicture tools: copy, crop, rescaling and view. 10 // WebPPicture tools: copy, crop, rescaling and view.
(...skipping 12 matching lines...) Expand all
23 // Grab the 'specs' (writer, *opaque, width, height...) from 'src' and copy them 23 // Grab the 'specs' (writer, *opaque, width, height...) from 'src' and copy them
24 // into 'dst'. Mark 'dst' as not owning any memory. 24 // into 'dst'. Mark 'dst' as not owning any memory.
25 static void PictureGrabSpecs(const WebPPicture* const src, 25 static void PictureGrabSpecs(const WebPPicture* const src,
26 WebPPicture* const dst) { 26 WebPPicture* const dst) {
27 assert(src != NULL && dst != NULL); 27 assert(src != NULL && dst != NULL);
28 *dst = *src; 28 *dst = *src;
29 WebPPictureResetBuffers(dst); 29 WebPPictureResetBuffers(dst);
30 } 30 }
31 31
32 //------------------------------------------------------------------------------ 32 //------------------------------------------------------------------------------
33 // Picture copying
34
35 static void CopyPlane(const uint8_t* src, int src_stride,
36 uint8_t* dst, int dst_stride, int width, int height) {
37 while (height-- > 0) {
38 memcpy(dst, src, width);
39 src += src_stride;
40 dst += dst_stride;
41 }
42 }
43 33
44 // Adjust top-left corner to chroma sample position. 34 // Adjust top-left corner to chroma sample position.
45 static void SnapTopLeftPosition(const WebPPicture* const pic, 35 static void SnapTopLeftPosition(const WebPPicture* const pic,
46 int* const left, int* const top) { 36 int* const left, int* const top) {
47 if (!pic->use_argb) { 37 if (!pic->use_argb) {
48 *left &= ~1; 38 *left &= ~1;
49 *top &= ~1; 39 *top &= ~1;
50 } 40 }
51 } 41 }
52 42
(...skipping 10 matching lines...) Expand all
63 } 53 }
64 54
65 int WebPPictureCopy(const WebPPicture* src, WebPPicture* dst) { 55 int WebPPictureCopy(const WebPPicture* src, WebPPicture* dst) {
66 if (src == NULL || dst == NULL) return 0; 56 if (src == NULL || dst == NULL) return 0;
67 if (src == dst) return 1; 57 if (src == dst) return 1;
68 58
69 PictureGrabSpecs(src, dst); 59 PictureGrabSpecs(src, dst);
70 if (!WebPPictureAlloc(dst)) return 0; 60 if (!WebPPictureAlloc(dst)) return 0;
71 61
72 if (!src->use_argb) { 62 if (!src->use_argb) {
73 CopyPlane(src->y, src->y_stride, 63 WebPCopyPlane(src->y, src->y_stride,
74 dst->y, dst->y_stride, dst->width, dst->height); 64 dst->y, dst->y_stride, dst->width, dst->height);
75 CopyPlane(src->u, src->uv_stride, 65 WebPCopyPlane(src->u, src->uv_stride, dst->u, dst->uv_stride,
76 dst->u, dst->uv_stride, HALVE(dst->width), HALVE(dst->height)); 66 HALVE(dst->width), HALVE(dst->height));
77 CopyPlane(src->v, src->uv_stride, 67 WebPCopyPlane(src->v, src->uv_stride, dst->v, dst->uv_stride,
78 dst->v, dst->uv_stride, HALVE(dst->width), HALVE(dst->height)); 68 HALVE(dst->width), HALVE(dst->height));
79 if (dst->a != NULL) { 69 if (dst->a != NULL) {
80 CopyPlane(src->a, src->a_stride, 70 WebPCopyPlane(src->a, src->a_stride,
81 dst->a, dst->a_stride, dst->width, dst->height); 71 dst->a, dst->a_stride, dst->width, dst->height);
82 } 72 }
83 } else { 73 } else {
84 CopyPlane((const uint8_t*)src->argb, 4 * src->argb_stride, 74 WebPCopyPlane((const uint8_t*)src->argb, 4 * src->argb_stride,
85 (uint8_t*)dst->argb, 4 * dst->argb_stride, 75 (uint8_t*)dst->argb, 4 * dst->argb_stride,
86 4 * dst->width, dst->height); 76 4 * dst->width, dst->height);
87 } 77 }
88 return 1; 78 return 1;
89 } 79 }
90 80
91 int WebPPictureIsView(const WebPPicture* picture) { 81 int WebPPictureIsView(const WebPPicture* picture) {
92 if (picture == NULL) return 0; 82 if (picture == NULL) return 0;
93 if (picture->use_argb) { 83 if (picture->use_argb) {
94 return (picture->memory_argb_ == NULL); 84 return (picture->memory_argb_ == NULL);
95 } 85 }
96 return (picture->memory_ == NULL); 86 return (picture->memory_ == NULL);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 if (!AdjustAndCheckRectangle(pic, &left, &top, width, height)) return 0; 127 if (!AdjustAndCheckRectangle(pic, &left, &top, width, height)) return 0;
138 128
139 PictureGrabSpecs(pic, &tmp); 129 PictureGrabSpecs(pic, &tmp);
140 tmp.width = width; 130 tmp.width = width;
141 tmp.height = height; 131 tmp.height = height;
142 if (!WebPPictureAlloc(&tmp)) return 0; 132 if (!WebPPictureAlloc(&tmp)) return 0;
143 133
144 if (!pic->use_argb) { 134 if (!pic->use_argb) {
145 const int y_offset = top * pic->y_stride + left; 135 const int y_offset = top * pic->y_stride + left;
146 const int uv_offset = (top / 2) * pic->uv_stride + left / 2; 136 const int uv_offset = (top / 2) * pic->uv_stride + left / 2;
147 CopyPlane(pic->y + y_offset, pic->y_stride, 137 WebPCopyPlane(pic->y + y_offset, pic->y_stride,
148 tmp.y, tmp.y_stride, width, height); 138 tmp.y, tmp.y_stride, width, height);
149 CopyPlane(pic->u + uv_offset, pic->uv_stride, 139 WebPCopyPlane(pic->u + uv_offset, pic->uv_stride,
150 tmp.u, tmp.uv_stride, HALVE(width), HALVE(height)); 140 tmp.u, tmp.uv_stride, HALVE(width), HALVE(height));
151 CopyPlane(pic->v + uv_offset, pic->uv_stride, 141 WebPCopyPlane(pic->v + uv_offset, pic->uv_stride,
152 tmp.v, tmp.uv_stride, HALVE(width), HALVE(height)); 142 tmp.v, tmp.uv_stride, HALVE(width), HALVE(height));
153 143
154 if (tmp.a != NULL) { 144 if (tmp.a != NULL) {
155 const int a_offset = top * pic->a_stride + left; 145 const int a_offset = top * pic->a_stride + left;
156 CopyPlane(pic->a + a_offset, pic->a_stride, 146 WebPCopyPlane(pic->a + a_offset, pic->a_stride,
157 tmp.a, tmp.a_stride, width, height); 147 tmp.a, tmp.a_stride, width, height);
158 } 148 }
159 } else { 149 } else {
160 const uint8_t* const src = 150 const uint8_t* const src =
161 (const uint8_t*)(pic->argb + top * pic->argb_stride + left); 151 (const uint8_t*)(pic->argb + top * pic->argb_stride + left);
162 CopyPlane(src, pic->argb_stride * 4, 152 WebPCopyPlane(src, pic->argb_stride * 4, (uint8_t*)tmp.argb,
163 (uint8_t*)tmp.argb, tmp.argb_stride * 4, 153 tmp.argb_stride * 4, width * 4, height);
164 width * 4, height);
165 } 154 }
166 WebPPictureFree(pic); 155 WebPPictureFree(pic);
167 *pic = tmp; 156 *pic = tmp;
168 return 1; 157 return 1;
169 } 158 }
170 159
171 //------------------------------------------------------------------------------ 160 //------------------------------------------------------------------------------
172 // Simple picture rescaler 161 // Simple picture rescaler
173 162
174 static void RescalePlane(const uint8_t* src, 163 static void RescalePlane(const uint8_t* src,
(...skipping 28 matching lines...) Expand all
203 } 192 }
204 193
205 int WebPPictureRescale(WebPPicture* pic, int width, int height) { 194 int WebPPictureRescale(WebPPicture* pic, int width, int height) {
206 WebPPicture tmp; 195 WebPPicture tmp;
207 int prev_width, prev_height; 196 int prev_width, prev_height;
208 rescaler_t* work; 197 rescaler_t* work;
209 198
210 if (pic == NULL) return 0; 199 if (pic == NULL) return 0;
211 prev_width = pic->width; 200 prev_width = pic->width;
212 prev_height = pic->height; 201 prev_height = pic->height;
213 // if width is unspecified, scale original proportionally to height ratio. 202 if (!WebPRescalerGetScaledDimensions(
214 if (width == 0) { 203 prev_width, prev_height, &width, &height)) {
215 width = (prev_width * height + prev_height / 2) / prev_height; 204 return 0;
216 } 205 }
217 // if height is unspecified, scale original proportionally to width ratio.
218 if (height == 0) {
219 height = (prev_height * width + prev_width / 2) / prev_width;
220 }
221 // Check if the overall dimensions still make sense.
222 if (width <= 0 || height <= 0) return 0;
223 206
224 PictureGrabSpecs(pic, &tmp); 207 PictureGrabSpecs(pic, &tmp);
225 tmp.width = width; 208 tmp.width = width;
226 tmp.height = height; 209 tmp.height = height;
227 if (!WebPPictureAlloc(&tmp)) return 0; 210 if (!WebPPictureAlloc(&tmp)) return 0;
228 211
229 if (!pic->use_argb) { 212 if (!pic->use_argb) {
230 work = (rescaler_t*)WebPSafeMalloc(2ULL * width, sizeof(*work)); 213 work = (rescaler_t*)WebPSafeMalloc(2ULL * width, sizeof(*work));
231 if (work == NULL) { 214 if (work == NULL) {
232 WebPPictureFree(&tmp); 215 WebPPictureFree(&tmp);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 work, 4); 255 work, 4);
273 AlphaMultiplyARGB(&tmp, 1); 256 AlphaMultiplyARGB(&tmp, 1);
274 } 257 }
275 WebPPictureFree(pic); 258 WebPPictureFree(pic);
276 WebPSafeFree(work); 259 WebPSafeFree(work);
277 *pic = tmp; 260 *pic = tmp;
278 return 1; 261 return 1;
279 } 262 }
280 263
281 //------------------------------------------------------------------------------ 264 //------------------------------------------------------------------------------
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698