libextractor

GNU libextractor
Log | Files | Refs | Submodules | README | LICENSE

test_media_lib.h (3663B)


      1 /*
      2      This file is part of libextractor.
      3      Copyright (C) 2026 Vidyut Samanta and Christian Grothoff
      4 
      5      libextractor is free software; you can redistribute it and/or modify
      6      it under the terms of the GNU General Public License as published
      7      by the Free Software Foundation; either version 3, or (at your
      8      option) any later version.
      9 
     10      libextractor is distributed in the hope that it will be useful, but
     11      WITHOUT ANY WARRANTY; without even the implied warranty of
     12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13      General Public License for more details.
     14 
     15      You should have received a copy of the GNU General Public License
     16      along with libextractor; see the file COPYING.  If not, write to the
     17      Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     18      Boston, MA 02110-1301, USA.
     19  */
     20 /**
     21  * @file plugins/test_media_lib.h
     22  * @brief helpers for testing the video thumbnail and audio preview plugins
     23  * @author Christian Grothoff
     24  *
     25  * Checking that a thumbnailer emitted *a* JPEG only proves that the
     26  * plugin ran, not that it looked where it was told to.  The test videos
     27  * therefore change colour at a known point in time and these helpers
     28  * inspect the pixel that comes back.
     29  */
     30 #ifndef TEST_MEDIA_LIB_H
     31 #define TEST_MEDIA_LIB_H
     32 
     33 #include <stdint.h>
     34 #include <stdlib.h>
     35 
     36 /**
     37  * Decode the PNG in @a data into packed 8-bit RGB (an alpha channel is
     38  * dropped).  Only the subset of PNG our own encoders produce is
     39  * understood: 8 bits per channel, RGB or RGBA, not interlaced.
     40  * Requires zlib; without it this always fails (see
     41  * #TEST_MEDIA_HAVE_PNG).
     42  *
     43  * @param data the PNG image
     44  * @param data_len number of bytes in @a data
     45  * @param[out] width set to the width of the image
     46  * @param[out] height set to the height of the image
     47  * @return the pixels (to be freed with free()), NULL on error
     48  */
     49 uint8_t *
     50 TEST_media_png_decode (const void *data,
     51                        size_t data_len,
     52                        uint32_t *width,
     53                        uint32_t *height);
     54 
     55 
     56 /**
     57  * Decode the PNG in @a data and return its centre pixel.
     58  *
     59  * Only the subset of PNG our own encoders produce is understood: 8 bits
     60  * per channel, RGB or RGBA, not interlaced.  Requires zlib; without it
     61  * this always fails and the caller should treat the check as skipped
     62  * (see #TEST_MEDIA_HAVE_PNG).
     63  *
     64  * @param data the PNG image
     65  * @param data_len number of bytes in @a data
     66  * @param[out] rgb set to the red, green and blue value of the centre pixel
     67  * @return 1 on success
     68  */
     69 int
     70 TEST_media_png_center (const void *data,
     71                        size_t data_len,
     72                        uint8_t rgb[3]);
     73 
     74 
     75 /**
     76  * Check that @a data is an Ogg stream whose first page carries the
     77  * OpusHead identification header of RFC 7845.
     78  *
     79  * @param data the stream
     80  * @param data_len number of bytes in @a data
     81  * @return 1 if this is Ogg Opus
     82  */
     83 int
     84 TEST_media_is_ogg_opus (const void *data,
     85                         size_t data_len);
     86 
     87 
     88 /**
     89  * Is the centre pixel of the PNG in @a data approximately @a r, @a g,
     90  * @a b?  Scaling and re-encoding move colours around a little, hence the
     91  * generous tolerance.
     92  *
     93  * @param data the PNG image
     94  * @param data_len number of bytes in @a data
     95  * @param r expected red value
     96  * @param g expected green value
     97  * @param b expected blue value
     98  * @return 1 if the pixel matches (or if PNG support was compiled out)
     99  */
    100 int
    101 TEST_media_png_center_is (const void *data,
    102                           size_t data_len,
    103                           uint8_t r,
    104                           uint8_t g,
    105                           uint8_t b);
    106 
    107 #endif
    108 
    109 /* end of test_media_lib.h */