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

Side by Side Diff: source/convert_to_argb.cc

Issue 1879783002: Fix temporary stride for ConvertToARGB with rotation. (Closed) Base URL: https://chromium.googlesource.com/libyuv/libyuv@master
Patch Set: Created 4 years, 8 months 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
« no previous file with comments | « include/libyuv/version.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 The LibYuv Project Authors. All rights reserved. 2 * Copyright 2011 The LibYuv Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "libyuv/convert_argb.h" 11 #include "libyuv/convert_argb.h"
12 12
13 #include "libyuv/cpu_id.h" 13 #include "libyuv/cpu_id.h"
14 #ifdef HAVE_JPEG 14 #ifdef HAVE_JPEG
15 #include "libyuv/mjpeg_decoder.h" 15 #include "libyuv/mjpeg_decoder.h"
16 #endif 16 #endif
17 #include "libyuv/rotate_argb.h" 17 #include "libyuv/rotate_argb.h"
18 #include "libyuv/row.h" 18 #include "libyuv/row.h"
19 #include "libyuv/video_common.h" 19 #include "libyuv/video_common.h"
20 20
21 #ifdef __cplusplus 21 #ifdef __cplusplus
22 namespace libyuv { 22 namespace libyuv {
23 extern "C" { 23 extern "C" {
24 #endif 24 #endif
25 25
26 // Convert camera sample to I420 with cropping, rotation and vertical flip. 26 // Convert camera sample to ARGB with cropping, rotation and vertical flip.
27 // src_width is used for source stride computation 27 // src_width is used for source stride computation
28 // src_height is used to compute location of planes, and indicate inversion 28 // src_height is used to compute location of planes, and indicate inversion
29 // sample_size is measured in bytes and is the size of the frame. 29 // sample_size is measured in bytes and is the size of the frame.
30 // With MJPEG it is the compressed size of the frame. 30 // With MJPEG it is the compressed size of the frame.
31 LIBYUV_API 31 LIBYUV_API
32 int ConvertToARGB(const uint8* sample, size_t sample_size, 32 int ConvertToARGB(const uint8* sample, size_t sample_size,
33 uint8* crop_argb, int argb_stride, 33 uint8* crop_argb, int argb_stride,
34 int crop_x, int crop_y, 34 int crop_x, int crop_y,
35 int src_width, int src_height, 35 int src_width, int src_height,
36 int crop_width, int crop_height, 36 int crop_width, int crop_height,
37 enum RotationMode rotation, 37 enum RotationMode rotation,
38 uint32 fourcc) { 38 uint32 fourcc) {
39 uint32 format = CanonicalFourCC(fourcc); 39 uint32 format = CanonicalFourCC(fourcc);
40 int aligned_src_width = (src_width + 1) & ~1; 40 int aligned_src_width = (src_width + 1) & ~1;
41 const uint8* src; 41 const uint8* src;
42 const uint8* src_uv; 42 const uint8* src_uv;
43 int abs_src_height = (src_height < 0) ? -src_height : src_height; 43 int abs_src_height = (src_height < 0) ? -src_height : src_height;
44 int inv_crop_height = (crop_height < 0) ? -crop_height : crop_height; 44 int inv_crop_height = (crop_height < 0) ? -crop_height : crop_height;
45 int r = 0; 45 int r = 0;
46 46
47 // One pass rotation is available for some formats. For the rest, convert 47 // One pass rotation is available for some formats. For the rest, convert
48 // to I420 (with optional vertical flipping) into a temporary I420 buffer, 48 // to I420 (with optional vertical flipping) into a temporary I420 buffer,
49 // and then rotate the I420 to the final destination buffer. 49 // and then rotate the I420 to the final destination buffer.
50 // For in-place conversion, if destination crop_argb is same as source sample, 50 // For in-place conversion, if destination crop_argb is same as source sample,
51 // also enable temporary buffer. 51 // also enable temporary buffer.
52 LIBYUV_BOOL need_buf = (rotation && format != FOURCC_ARGB) || 52 LIBYUV_BOOL need_buf = (rotation && format != FOURCC_ARGB) ||
53 crop_argb == sample; 53 crop_argb == sample;
54 uint8* tmp_argb = crop_argb; 54 uint8* dest_argb = crop_argb;
55 int tmp_argb_stride = argb_stride; 55 int dest_argb_stride = argb_stride;
56 uint8* rotate_buffer = NULL; 56 uint8* rotate_buffer = NULL;
57 int abs_crop_height = (crop_height < 0) ? -crop_height : crop_height; 57 int abs_crop_height = (crop_height < 0) ? -crop_height : crop_height;
58 58
59 if (crop_argb == NULL || sample == NULL || 59 if (crop_argb == NULL || sample == NULL ||
60 src_width <= 0 || crop_width <= 0 || 60 src_width <= 0 || crop_width <= 0 ||
61 src_height == 0 || crop_height == 0) { 61 src_height == 0 || crop_height == 0) {
62 return -1; 62 return -1;
63 } 63 }
64 if (src_height < 0) { 64 if (src_height < 0) {
65 inv_crop_height = -inv_crop_height; 65 inv_crop_height = -inv_crop_height;
66 } 66 }
67 67
68 if (need_buf) { 68 if (need_buf) {
69 int argb_size = crop_width * abs_crop_height * 4; 69 int argb_size = crop_width * 4 * abs_crop_height;
70 rotate_buffer = (uint8*)malloc(argb_size); 70 rotate_buffer = (uint8*)malloc(argb_size);
71 if (!rotate_buffer) { 71 if (!rotate_buffer) {
72 return 1; // Out of memory runtime error. 72 return 1; // Out of memory runtime error.
73 } 73 }
74 crop_argb = rotate_buffer; 74 crop_argb = rotate_buffer;
75 argb_stride = crop_width; 75 argb_stride = crop_width * 4;
76 } 76 }
77 77
78 switch (format) { 78 switch (format) {
79 // Single plane formats 79 // Single plane formats
80 case FOURCC_YUY2: 80 case FOURCC_YUY2:
81 src = sample + (aligned_src_width * crop_y + crop_x) * 2; 81 src = sample + (aligned_src_width * crop_y + crop_x) * 2;
82 r = YUY2ToARGB(src, aligned_src_width * 2, 82 r = YUY2ToARGB(src, aligned_src_width * 2,
83 crop_argb, argb_stride, 83 crop_argb, argb_stride,
84 crop_width, inv_crop_height); 84 crop_width, inv_crop_height);
85 break; 85 break;
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 src_width, abs_src_height, crop_width, inv_crop_height); 284 src_width, abs_src_height, crop_width, inv_crop_height);
285 break; 285 break;
286 #endif 286 #endif
287 default: 287 default:
288 r = -1; // unknown fourcc - return failure code. 288 r = -1; // unknown fourcc - return failure code.
289 } 289 }
290 290
291 if (need_buf) { 291 if (need_buf) {
292 if (!r) { 292 if (!r) {
293 r = ARGBRotate(crop_argb, argb_stride, 293 r = ARGBRotate(crop_argb, argb_stride,
294 tmp_argb, tmp_argb_stride, 294 dest_argb, dest_argb_stride,
295 crop_width, abs_crop_height, rotation); 295 crop_width, abs_crop_height, rotation);
296 } 296 }
297 free(rotate_buffer); 297 free(rotate_buffer);
298 } 298 }
299 299
300 return r; 300 return r;
301 } 301 }
302 302
303 #ifdef __cplusplus 303 #ifdef __cplusplus
304 } // extern "C" 304 } // extern "C"
305 } // namespace libyuv 305 } // namespace libyuv
306 #endif 306 #endif
OLDNEW
« no previous file with comments | « include/libyuv/version.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698