extras.h (5213B)
1 // Copyright 2015 Google Inc. All Rights Reserved. 2 // 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 5 // tree. An additional intellectual property rights grant can be found 6 // in the file PATENTS. All contributing project authors may 7 // be found in the AUTHORS file in the root of the source tree. 8 // ----------------------------------------------------------------------------- 9 // 10 11 #ifndef WEBP_EXTRAS_EXTRAS_H_ 12 #define WEBP_EXTRAS_EXTRAS_H_ 13 14 #include <stddef.h> 15 16 #include "webp/types.h" 17 18 #ifdef __cplusplus 19 extern "C" { 20 #endif 21 22 #include "sharpyuv/sharpyuv.h" 23 #include "webp/encode.h" 24 25 #define WEBP_EXTRAS_ABI_VERSION 0x0003 // MAJOR(8b) + MINOR(8b) 26 27 //------------------------------------------------------------------------------ 28 29 // Returns the version number of the extras library, packed in hexadecimal using 30 // 8bits for each of major/minor/revision. E.g: v2.5.7 is 0x020507. 31 WEBP_EXTERN int WebPGetExtrasVersion(void); 32 33 //------------------------------------------------------------------------------ 34 // Ad-hoc colorspace importers. 35 36 // Import luma sample (gray scale image) into 'picture'. The 'picture' 37 // width and height must be set prior to calling this function. 38 WEBP_EXTERN int WebPImportGray(const uint8_t* gray, WebPPicture* picture); 39 40 // Import rgb sample in RGB565 packed format into 'picture'. The 'picture' 41 // width and height must be set prior to calling this function. 42 WEBP_EXTERN int WebPImportRGB565(const uint8_t* rgb565, WebPPicture* pic); 43 44 // Import rgb sample in RGB4444 packed format into 'picture'. The 'picture' 45 // width and height must be set prior to calling this function. 46 WEBP_EXTERN int WebPImportRGB4444(const uint8_t* rgb4444, WebPPicture* pic); 47 48 // Import a color mapped image. The number of colors is less or equal to 49 // MAX_PALETTE_SIZE. 'pic' must have been initialized. Its content, if any, 50 // will be discarded. Returns 'false' in case of error, or if indexed[] contains 51 // invalid indices. 52 WEBP_EXTERN int 53 WebPImportColorMappedARGB(const uint8_t* indexed, int indexed_stride, 54 const uint32_t palette[], int palette_size, 55 WebPPicture* pic); 56 57 // Convert the ARGB content of 'pic' from associated to unassociated. 58 // 'pic' can be for instance the result of calling of some WebPPictureImportXXX 59 // functions, with pic->use_argb set to 'true'. It is assumed (and not checked) 60 // that the pre-multiplied r/g/b values as less or equal than the alpha value. 61 // Return false in case of error (invalid parameter, ...). 62 WEBP_EXTERN int WebPUnmultiplyARGB(WebPPicture* pic); 63 64 //------------------------------------------------------------------------------ 65 66 // Parse a bitstream, search for VP8 (lossy) header and report a 67 // rough estimation of the quality factor used for compressing the bitstream. 68 // If the bitstream is in lossless format, the special value '101' is returned. 69 // Otherwise (lossy bitstream), the returned value is in the range [0..100]. 70 // Any error (invalid bitstream, animated WebP, incomplete header, etc.) 71 // will return a value of -1. 72 WEBP_EXTERN int VP8EstimateQuality(const uint8_t* const data, size_t size); 73 74 //------------------------------------------------------------------------------ 75 76 // Computes a score between 0 and 100 which represents the risk of having visual 77 // quality loss from converting an RGB image to YUV420. 78 // A low score, typically < 40, means there is a low risk of artifacts from 79 // chroma subsampling and a simple averaging algorithm can be used instead of 80 // the more expensive SharpYuvConvert function. 81 // A medium score, typically >= 40 and < 70, means that simple chroma 82 // subsampling will produce artifacts and it may be advisable to use the more 83 // costly SharpYuvConvert for YUV420 conversion. 84 // A high score, typically >= 70, means there is a very high risk of artifacts 85 // from chroma subsampling even with SharpYuvConvert, and best results might be 86 // achieved by using YUV444. 87 // If not using SharpYuvConvert, a threshold of about 50 can be used to decide 88 // between (simple averaging) 420 and 444. 89 // r_ptr, g_ptr, b_ptr: pointers to the source r, g and b channels. Should point 90 // to uint8_t buffers if rgb_bit_depth is 8, or uint16_t buffers otherwise. 91 // rgb_step: distance in bytes between two horizontally adjacent pixels on the 92 // r, g and b channels. If rgb_bit_depth is > 8, it should be a 93 // multiple of 2. 94 // rgb_stride: distance in bytes between two vertically adjacent pixels on the 95 // r, g, and b channels. If rgb_bit_depth is > 8, it should be a 96 // multiple of 2. 97 // rgb_bit_depth: number of bits for each r/g/b value. Only a value of 8 is 98 // currently supported. 99 // width, height: width and height of the image in pixels 100 // Returns 0 on failure. 101 WEBP_EXTERN int SharpYuvEstimate420Risk( 102 const void* r_ptr, const void* g_ptr, const void* b_ptr, int rgb_step, 103 int rgb_stride, int rgb_bit_depth, int width, int height, 104 const SharpYuvOptions* options, float* score); 105 106 //------------------------------------------------------------------------------ 107 108 #ifdef __cplusplus 109 } // extern "C" 110 #endif 111 112 #endif // WEBP_EXTRAS_EXTRAS_H_