[email protected] | a101cf3 | 2012-01-14 00:34:23 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | c3af26f33 | 2010-10-06 22:46:00 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef REMOTING_BASE_UTIL_H_ |
| 6 | #define REMOTING_BASE_UTIL_H_ |
| 7 | |
[email protected] | 82156e8 | 2011-12-20 07:09:01 | [diff] [blame] | 8 | #include <string> |
| 9 | |
[email protected] | 3adf1b2 | 2010-11-09 23:22:20 | [diff] [blame] | 10 | #include "media/base/video_frame.h" |
[email protected] | dc454a7c | 2011-08-12 22:01:13 | [diff] [blame] | 11 | #include "third_party/skia/include/core/SkRect.h" |
[email protected] | c3af26f33 | 2010-10-06 22:46:00 | [diff] [blame] | 12 | |
| 13 | namespace remoting { |
| 14 | |
[email protected] | a101cf3 | 2012-01-14 00:34:23 | [diff] [blame] | 15 | // Return a string that contains the current date formatted as 'MMDD/HHMMSS:'. |
[email protected] | 82d105e | 2011-08-04 03:19:35 | [diff] [blame] | 16 | std::string GetTimestampString(); |
| 17 | |
[email protected] | b3ca1f5 | 2012-02-09 19:00:51 | [diff] [blame] | 18 | // Convert and scale YUV to RGB32 on a specific rectangle. The source and |
| 19 | // destination buffers are assumed to contain only |source_buffer_rect| and |
| 20 | // |dest_buffer_rect| areas correspondingly. The scaling factor is determined |
| 21 | // as ratio between |dest_size| and |source_size|. The target rectangle |
| 22 | // |dect_rect| is specified in the destination coordinates. |
| 23 | // |
| 24 | // |source_buffer_rect| and |dest_buffer_rect| must fall entirely within |
| 25 | // the source and destination dimensions, respectively. |dest_rect| must be |
| 26 | // completely contained within the source and destinations buffers boundaries |
| 27 | // including the case when scaling is requested. |
| 28 | // |
| 29 | // N.B. The top left corner coordinates of YUV buffer should have even X and Y |
| 30 | // coordinates. |
| 31 | void ConvertAndScaleYUVToRGB32Rect(const uint8* source_yplane, |
| 32 | const uint8* source_uplane, |
| 33 | const uint8* source_vplane, |
| 34 | int source_ystride, |
| 35 | int source_uvstride, |
| 36 | const SkISize& source_size, |
| 37 | const SkIRect& source_buffer_rect, |
| 38 | uint8* dest_buffer, |
| 39 | int dest_stride, |
| 40 | const SkISize& dest_size, |
| 41 | const SkIRect& dest_buffer_rect, |
| 42 | const SkIRect& dest_rect); |
[email protected] | 5068614 | 2011-02-04 02:08:32 | [diff] [blame] | 43 | |
[email protected] | b3ca1f5 | 2012-02-09 19:00:51 | [diff] [blame] | 44 | // Convert RGB32 to YUV on a specific rectangle. |
[email protected] | 5068614 | 2011-02-04 02:08:32 | [diff] [blame] | 45 | void ConvertRGB32ToYUVWithRect(const uint8* rgb_plane, |
| 46 | uint8* y_plane, |
| 47 | uint8* u_plane, |
| 48 | uint8* v_plane, |
| 49 | int x, |
| 50 | int y, |
| 51 | int width, |
| 52 | int height, |
| 53 | int rgb_stride, |
| 54 | int y_stride, |
| 55 | int uv_stride); |
| 56 | |
[email protected] | 47379e9 | 2011-07-26 15:33:15 | [diff] [blame] | 57 | int RoundToTwosMultiple(int x); |
| 58 | |
| 59 | // Align the sides of the rectangle to multiples of 2 (expanding outwards). |
[email protected] | bcad268 | 2011-09-30 20:35:26 | [diff] [blame] | 60 | SkIRect AlignRect(const SkIRect& rect); |
[email protected] | 47379e9 | 2011-07-26 15:33:15 | [diff] [blame] | 61 | |
[email protected] | 15e7b6c | 2011-12-22 10:20:33 | [diff] [blame] | 62 | // Scales the supplied rectangle from |in_size| coordinates to |out_size|. |
| 63 | // If the result has non-integer coordinates then the smallest integer- |
| 64 | // coordinate rectangle that wholly encloses it is returned. |
[email protected] | bcad268 | 2011-09-30 20:35:26 | [diff] [blame] | 65 | SkIRect ScaleRect(const SkIRect& rect, |
[email protected] | 15e7b6c | 2011-12-22 10:20:33 | [diff] [blame] | 66 | const SkISize& in_size, |
| 67 | const SkISize& out_size); |
[email protected] | 47379e9 | 2011-07-26 15:33:15 | [diff] [blame] | 68 | |
[email protected] | 2cc0ec84 | 2011-08-01 19:59:42 | [diff] [blame] | 69 | // Copy pixels in the rectangle from source to destination. |
| 70 | void CopyRect(const uint8* src_plane, |
| 71 | int src_plane_stride, |
| 72 | uint8* dest_plane, |
| 73 | int dest_plane_stride, |
| 74 | int bytes_per_pixel, |
[email protected] | dc454a7c | 2011-08-12 22:01:13 | [diff] [blame] | 75 | const SkIRect& rect); |
[email protected] | 2cc0ec84 | 2011-08-01 19:59:42 | [diff] [blame] | 76 | |
[email protected] | b3ca1f5 | 2012-02-09 19:00:51 | [diff] [blame] | 77 | void CopyRGB32Rect(const uint8* source_buffer, |
| 78 | int source_stride, |
| 79 | const SkIRect& source_buffer_rect, |
| 80 | uint8* dest_buffer, |
| 81 | int dest_stride, |
| 82 | const SkIRect& dest_buffer_rect, |
| 83 | const SkIRect& dest_rect); |
| 84 | |
[email protected] | a93c8c84 | 2012-06-02 22:17:03 | [diff] [blame^] | 85 | // Replaces every occurrence of "\n" in a string by "\r\n". |
| 86 | std::string ReplaceLfByCrLf(const std::string& in); |
| 87 | |
| 88 | // Replaces every occurrence of "\r\n" in a string by "\n". |
| 89 | std::string ReplaceCrLfByLf(const std::string& in); |
| 90 | |
[email protected] | c3af26f33 | 2010-10-06 22:46:00 | [diff] [blame] | 91 | } // namespace remoting |
| 92 | |
| 93 | #endif // REMOTING_BASE_UTIL_H_ |