| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 |
| 11 | #include "libyuv/scale.h" /* For FilterMode */ |
| 12 |
| 13 | #include <assert.h> |
| 14 | #include <string.h> |
| 15 |
| 16 | #include "libyuv/convert_argb.h" |
| 17 | #include "libyuv/convert_from_argb.h" |
| 18 | #include "libyuv/row.h" |
| 19 | #include "libyuv/scale_argb.h" |
| 20 | #include "libyuv/scale_rgb.h" |
| 21 |
| 22 | #ifdef __cplusplus |
| 23 | namespace libyuv { |
| 24 | extern "C" { |
| 25 | #endif |
| 26 |
| 27 | // Scale a 24 bit image. |
| 28 | // Converts to ARGB as intermediate step |
| 29 |
| 30 | LIBYUV_API |
| 31 | int RGBScale(const uint8_t* src_rgb, |
| 32 | int src_stride_rgb, |
| 33 | int src_width, |
| 34 | int src_height, |
| 35 | uint8_t* dst_rgb, |
| 36 | int dst_stride_rgb, |
| 37 | int dst_width, |
| 38 | int dst_height, |
| 39 | enum FilterMode filtering) { |
| 40 | int r; |
| 41 | uint8_t* src_argb = |
| 42 | (uint8_t*)malloc(src_width * src_height * 4 + dst_width * dst_height * 4); |
| 43 | uint8_t* dst_argb = src_argb + src_width * src_height * 4; |
| 44 |
| 45 | if (!src_argb) { |
| 46 | return 1; |
| 47 | } |
| 48 |
| 49 | r = RGB24ToARGB(src_rgb, src_stride_rgb, src_argb, src_width * 4, src_width, |
| 50 | src_height); |
| 51 | if (!r) { |
| 52 | r = ARGBScale(src_argb, src_width * 4, src_width, src_height, dst_argb, |
| 53 | dst_width * 4, dst_width, dst_height, filtering); |
| 54 | if (!r) { |
| 55 | r = ARGBToRGB24(dst_argb, dst_width * 4, dst_rgb, dst_stride_rgb, |
| 56 | dst_width, dst_height); |
| 57 | } |
| 58 | } |
| 59 | free(src_argb); |
| 60 | return r; |
| 61 | } |
| 62 |
| 63 | #ifdef __cplusplus |
| 64 | } // extern "C" |
| 65 | } // namespace libyuv |
| 66 | #endif |
| 67 |