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