[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] | 71fe6e3 | 2012-06-18 23:17:52 | [diff] [blame] | 18 | // Calculate the offset of a specific pixel in an RGB32 buffer. |
| 19 | int CalculateRGBOffset(int x, int y, int stride); |
| 20 | |
| 21 | // Calculate the offset of a specific pixel in a YV12/YUV420 buffer. Note that |
| 22 | // the X and Y coordinates must both be even owing to the YV12 buffer layout. |
| 23 | int CalculateYOffset(int x, int y, int stride); |
| 24 | int CalculateUVOffset(int x, int y, int stride); |
| 25 | |
[email protected] | b3ca1f5 | 2012-02-09 19:00:51 | [diff] [blame] | 26 | // Convert and scale YUV to RGB32 on a specific rectangle. The source and |
| 27 | // destination buffers are assumed to contain only |source_buffer_rect| and |
| 28 | // |dest_buffer_rect| areas correspondingly. The scaling factor is determined |
| 29 | // as ratio between |dest_size| and |source_size|. The target rectangle |
| 30 | // |dect_rect| is specified in the destination coordinates. |
| 31 | // |
| 32 | // |source_buffer_rect| and |dest_buffer_rect| must fall entirely within |
| 33 | // the source and destination dimensions, respectively. |dest_rect| must be |
| 34 | // completely contained within the source and destinations buffers boundaries |
| 35 | // including the case when scaling is requested. |
| 36 | // |
| 37 | // N.B. The top left corner coordinates of YUV buffer should have even X and Y |
| 38 | // coordinates. |
| 39 | void ConvertAndScaleYUVToRGB32Rect(const uint8* source_yplane, |
| 40 | const uint8* source_uplane, |
| 41 | const uint8* source_vplane, |
| 42 | int source_ystride, |
| 43 | int source_uvstride, |
| 44 | const SkISize& source_size, |
| 45 | const SkIRect& source_buffer_rect, |
| 46 | uint8* dest_buffer, |
| 47 | int dest_stride, |
| 48 | const SkISize& dest_size, |
| 49 | const SkIRect& dest_buffer_rect, |
| 50 | const SkIRect& dest_rect); |
[email protected] | 5068614 | 2011-02-04 02:08:32 | [diff] [blame] | 51 | |
[email protected] | b3ca1f5 | 2012-02-09 19:00:51 | [diff] [blame] | 52 | // Convert RGB32 to YUV on a specific rectangle. |
[email protected] | 5068614 | 2011-02-04 02:08:32 | [diff] [blame] | 53 | void ConvertRGB32ToYUVWithRect(const uint8* rgb_plane, |
| 54 | uint8* y_plane, |
| 55 | uint8* u_plane, |
| 56 | uint8* v_plane, |
| 57 | int x, |
| 58 | int y, |
| 59 | int width, |
| 60 | int height, |
| 61 | int rgb_stride, |
| 62 | int y_stride, |
| 63 | int uv_stride); |
| 64 | |
[email protected] | 47379e9 | 2011-07-26 15:33:15 | [diff] [blame] | 65 | int RoundToTwosMultiple(int x); |
| 66 | |
| 67 | // Align the sides of the rectangle to multiples of 2 (expanding outwards). |
[email protected] | bcad268 | 2011-09-30 20:35:26 | [diff] [blame] | 68 | SkIRect AlignRect(const SkIRect& rect); |
[email protected] | 47379e9 | 2011-07-26 15:33:15 | [diff] [blame] | 69 | |
[email protected] | 15e7b6c | 2011-12-22 10:20:33 | [diff] [blame] | 70 | // Scales the supplied rectangle from |in_size| coordinates to |out_size|. |
| 71 | // If the result has non-integer coordinates then the smallest integer- |
| 72 | // coordinate rectangle that wholly encloses it is returned. |
[email protected] | bcad268 | 2011-09-30 20:35:26 | [diff] [blame] | 73 | SkIRect ScaleRect(const SkIRect& rect, |
[email protected] | 15e7b6c | 2011-12-22 10:20:33 | [diff] [blame] | 74 | const SkISize& in_size, |
| 75 | const SkISize& out_size); |
[email protected] | 47379e9 | 2011-07-26 15:33:15 | [diff] [blame] | 76 | |
[email protected] | 420a5e4 | 2012-12-18 21:42:12 | [diff] [blame^] | 77 | // Copy content of a rectangle in a RGB32 image. |
[email protected] | b3ca1f5 | 2012-02-09 19:00:51 | [diff] [blame] | 78 | void CopyRGB32Rect(const uint8* source_buffer, |
| 79 | int source_stride, |
| 80 | const SkIRect& source_buffer_rect, |
| 81 | uint8* dest_buffer, |
| 82 | int dest_stride, |
| 83 | const SkIRect& dest_buffer_rect, |
| 84 | const SkIRect& dest_rect); |
| 85 | |
[email protected] | a93c8c84 | 2012-06-02 22:17:03 | [diff] [blame] | 86 | // Replaces every occurrence of "\n" in a string by "\r\n". |
| 87 | std::string ReplaceLfByCrLf(const std::string& in); |
| 88 | |
| 89 | // Replaces every occurrence of "\r\n" in a string by "\n". |
| 90 | std::string ReplaceCrLfByLf(const std::string& in); |
| 91 | |
[email protected] | 31014af | 2012-11-30 04:04:57 | [diff] [blame] | 92 | // Checks if the given string is a valid UTF-8 string. |
| 93 | bool StringIsUtf8(const char* data, size_t length); |
| 94 | |
[email protected] | c3af26f33 | 2010-10-06 22:46:00 | [diff] [blame] | 95 | } // namespace remoting |
| 96 | |
| 97 | #endif // REMOTING_BASE_UTIL_H_ |