<commit_before>/************************************************************************/
/*                                                                      */
/*               Copyright 1998-2001 by <NAME>                  */
/*               Copyright 2001-2002 by <NAME>                */
/*       Cognitive Systems Group, University of Hamburg, Germany        */
/*                                                                      */
/*    This file is part of the VIGRA computer vision library.           */
/*    You may use, modify, and distribute this software according       */
/*    to the terms stated in the LICENSE file included in               */
/*    the VIGRA distribution.                                           */
/*                                                                      */
/*    The VIGRA Website is                                              */
/*        http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/      */
/*    Please direct questions, bug reports, and contributions to        */
/*        <EMAIL>                              */
/*                                                                      */
/*  THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY EXPRESS OR          */
/*  IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED      */
/*  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */
/*                                                                      */
/************************************************************************/

#ifndef VIGRA_IMAGEINFO_HXX
#define VIGRA_IMAGEINFO_HXX

#include <memory>
#include <string>
#include "vigra/utilities.hxx"
#include "vigra/codec.hxx"

namespace vigra
{
/** \addtogroup VigraImpex Image Import/Export Facilities
    
    supports GIF, TIFF, JPEG, BMP, PNM (PBM, PGM, PPM), PNG, SunRaster, KHOROS-VIFF formats
**/
//@{

    /** \brief List the image formats VIGRA can read and write.

        This is useful for creating error messages if VIGRA encounters an
        image format it doesn't recognize.

        <b> Usage:</b>

        <b>\#include</b> "<a href="imageinfo_8hxx-source.html">vigra/imageinfo.hxx</a>"<br>
        Namespace: vigra

        \code
        std::cout << "supported formats: " << vigra::impexListFormats() << std::endl;
        \endcode

    **/
std::string impexListFormats();

    /** \brief List the file extension VIGRA understands.

        This is useful for creating file dialogs that only list image files
        VIGRA can actually import.

        <b> Usage:</b>

        <b>\#include</b> "<a href="imageinfo_8hxx-source.html">vigra/imageinfo.hxx</a>"<br>
        Namespace: vigra

        \code
        std::cout << "supported extensions: " << vigra::impexListExtensions() << std::endl;
        \endcode

    **/
std::string impexListExtensions();

/** \brief Test whether a file is an image format known to VIGRA.

    This checks the first few bytes of the file and compares them with the
    "magic strings" of each recognized image format.

    <b> Usage:</b>

    <b>\#include</b> "<a href="imageinfo_8hxx-source.html">vigra/imageinfo.hxx</a>"<br>
    Namespace: vigra

    \code
    std::cout << "is image: " << vigra::isImage("foo.bmp") << std::endl;
    \endcode

**/
bool isImage(char const * filename);

/********************************************************/
/*                                                      */
/*                   ImageExportInfo                    */
/*                                                      */
/********************************************************/

/** \brief Argument object for the function exportImage().
    See \ref exportImage() for usage example. This object must be used
    to define the properties of an image to be written to disk.

    <b>\#include</b> "<a href="imageinfo_8hxx-source.html">vigra/imageinfo.hxx</a>"<br>
    Namespace: vigra
**/
class ImageExportInfo
{
  public:
        /** Construct ImageExportInfo object.
        
            The image will be stored under the given filename.
            The file type will be guessed from the extension unless overridden
            by \ref setFileType(). Recognized extensions: '.bmp', '.gif',
            '.jpeg', '.jpg', '.p7', '.png', '.pbm', '.pgm', '.pnm', '.ppm', '.ras',
            '.tif', '.tiff', '.xv'.
            JPEG support requires libjpeg, PNG support requires libpng, and
            TIFF support requires libtiff.
        **/
    ImageExportInfo( const char * );

    const char * getFileName() const;

    /** Store image as given file type.
    
        This will override any type guessed
        from the file name's extension. Recognized file types:

        <DL>
        <DT>"BMP"<DD> Microsoft Windows bitmap image file.
        <DT>"GIF"<DD> CompuServe graphics interchange format; 8-bit color.
        <DT>"JPEG"<DD> Joint Photographic Experts Group JFIF format;
        compressed 24-bit color (only available if libjpeg is installed).
        <DT>"PNG"<DD> Portable Network Graphic
        (only available if libpng is installed).
        <DT>"PBM"<DD> Portable bitmap format (black and white).
        <DT>"PGM"<DD> Portable graymap format (gray scale).
        <DT>"PNM"<DD> Portable anymap.
        <DT>"PPM"<DD> Portable pixmap format (color).
        <DT>"SUN"<DD> SUN Rasterfile.
        <DT>"TIFF"<DD> Tagged Image File Format.
        (only available if libtiff is installed.)
        <DT>"VIFF"<DD> Khoros Visualization image file.
        </DL>

        With the exception of TIFF and VIFF, all file types store
        1 byte (gray scale and mapped RGB) or 3 bytes (RGB) per
        pixel.

        TIFF and VIFF are aditionally able to store short and long
        integers (2 or 4 bytes) and real values (32 bit float and
        64 bit double) without conversion. So you will need to use
        TIFF or VIFF if you need to store images with high
        accuracy (the appropriate type to write is automatically
        derived from the image type to be exported). However, many
        other programs using TIFF (e.g. ImageMagick) have not
        implemented support for those pixel types.  So don't be
        surprised if the generated TIFF is not readable in some
        cases.  If this happens, convert the image to 'unsigned
        char' or 'RGBValue\<unsigned char\>' prior to exporting.
    **/
    ImageExportInfo & setFileType( const char * );
    const char * getFileType() const;

    /** Set compression type.
    
        Recognized strings: "" (no compression), "LZW",
        "RunLength", "1" ... "100". A number is interpreted as the
        compression quality for JPEG compression. JPEG compression is
        supported by the JPEG and TIFF formats.
    **/
    ImageExportInfo & setCompression( const char * );
    const char * getCompression() const;

    /** Set the pixel type of the image. Possible values are:
        <DL>
        <DT>"UINT8"<DD> 8-bit unsigned integer (unsigned char)
        <DT>"INT16"<DD> 16-bit signed integer (short)
        <DT>"INT32"<DD> 32-bit signed integer (long)
        <DT>"FLOAT"<DD> 32-bit floating point (float)
        <DT>"DOUBLE"<DD> 64-bit floating point (double)
        </DL>
    **/
    ImageExportInfo & setPixelType( const char * );

    /** Get the pixel type of the image. Possible values are:
        <DL>
        <DT>"UINT8"<DD> 8-bit unsigned integer (unsigned char)
        <DT>"INT16"<DD> 16-bit signed integer (short)
        <DT>"INT32"<DD> 32-bit signed integer (long)
        <DT>"FLOAT"<DD> 32-bit floating point (float)
        <DT>"DOUBLE"<DD> 64-bit floating point (double)
        </DL>
    **/
    const char * getPixelType() const;

    /** Set the image resolution in horizontal direction
    **/
    ImageExportInfo & setXResolution( float );
    float getXResolution() const;

    /** Set the image resolution in vertical direction
    **/
    ImageExportInfo & setYResolution( float );
    float getYResolution() const;

  private:
    std::string m_filename, m_filetype, m_pixeltype, m_comp;
    float m_x_res, m_y_res;
};

// return an encoder for a given ImageExportInfo object<commit_msg>adapted documentation of setPixelType() to new export semantics (forse output pixel type)<commit_after>/************************************************************************/
/*                                                                      */
/*               Copyright 1998-2001 by <NAME>                  */
/*               Copyright 2001-2002 by <NAME>                */
/*       Cognitive Systems Group, University of Hamburg, Germany        */
/*                                                                      */
/*    This file is part of the VIGRA computer vision library.           */
/*    You may use, modify, and distribute this software according       */
/*    to the terms stated in the LICENSE file included in               */
/*    the VIGRA distribution.                                           */
/*                                                                      */
/*    The VIGRA Website is                                              */
/*        http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/      */
/*    Please direct questions, bug reports, and contributions to        */
/*        <EMAIL>                              */
/*                                                                      */
/*  THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY EXPRESS OR          */
/*  IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED      */
/*  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */
/*                                                                      */
/************************************************************************/

#ifndef VIGRA_IMAGEINFO_HXX
#define VIGRA_IMAGEINFO_HXX

#include <memory>
#include <string>
#include "vigra/utilities.hxx"
#include "vigra/codec.hxx"

namespace vigra
{
/** \addtogroup VigraImpex Image Import/Export Facilities
    
    supports GIF, TIFF, JPEG, BMP, PNM (PBM, PGM, PPM), PNG, SunRaster, KHOROS-VIFF formats
**/
//@{

    /** \brief List the image formats VIGRA can read and write.

        This is useful for creating error messages if VIGRA encounters an
        image format it doesn't recognize.

        <b> Usage:</b>

        <b>\#include</b> "<a href="imageinfo_8hxx-source.html">vigra/imageinfo.hxx</a>"<br>
        Namespace: vigra

        \code
        std::cout << "supported formats: " << vigra::impexListFormats() << std::endl;
        \endcode

    **/
std::string impexListFormats();

    /** \brief List the file extension VIGRA understands.

        This is useful for creating file dialogs that only list image files
        VIGRA can actually import.

        <b> Usage:</b>

        <b>\#include</b> "<a href="imageinfo_8hxx-source.html">vigra/imageinfo.hxx</a>"<br>
        Namespace: vigra

        \code
        std::cout << "supported extensions: " << vigra::impexListExtensions() << std::endl;
        \endcode

    **/
std::string impexListExtensions();

/** \brief Test whether a file is an image format known to VIGRA.

    This checks the first few bytes of the file and compares them with the
    "magic strings" of each recognized image format.

    <b> Usage:</b>

    <b>\#include</b> "<a href="imageinfo_8hxx-source.html">vigra/imageinfo.hxx</a>"<br>
    Namespace: vigra

    \code
    std::cout << "is image: " << vigra::isImage("foo.bmp") << std::endl;
    \endcode

**/
bool isImage(char const * filename);

/********************************************************/
/*                                                      */
/*                   ImageExportInfo                    */
/*                                                      */
/********************************************************/

/** \brief Argument object for the function exportImage().
    See \ref exportImage() for usage example. This object must be used
    to define the properties of an image to be written to disk.

    <b>\#include</b> "<a href="imageinfo_8hxx-source.html">vigra/imageinfo.hxx</a>"<br>
    Namespace: vigra
**/
class ImageExportInfo
{
  public:
        /** Construct ImageExportInfo object.
        
            The image will be stored under the given filename.
            The file type will be guessed from the extension unless overridden
            by \ref setFileType(). Recognized extensions: '.bmp', '.gif',
            '.jpeg', '.jpg', '.p7', '.png', '.pbm', '.pgm', '.pnm', '.ppm', '.ras',
            '.tif', '.tiff', '.xv'.
            JPEG support requires libjpeg, PNG support requires libpng, and
            TIFF support requires libtiff.
        **/
    ImageExportInfo( const char * );

    const char * getFileName() const;

    /** Store image as given file type.
    
        This will override any type guessed
        from the file name's extension. Recognized file types:

        <DL>
        <DT>"BMP"<DD> Microsoft Windows bitmap image file.
        <DT>"GIF"<DD> CompuServe graphics interchange format; 8-bit color.
        <DT>"JPEG"<DD> Joint Photographic Experts Group JFIF format;
        compressed 24-bit color (only available if libjpeg is installed).
        <DT>"PNG"<DD> Portable Network Graphic
        (only available if libpng is installed).
        <DT>"PBM"<DD> Portable bitmap format (black and white).
        <DT>"PGM"<DD> Portable graymap format (gray scale).
        <DT>"PNM"<DD> Portable anymap.
        <DT>"PPM"<DD> Portable pixmap format (color).
        <DT>"SUN"<DD> SUN Rasterfile.
        <DT>"TIFF"<DD> Tagged Image File Format.
        (only available if libtiff is installed.)
        <DT>"VIFF"<DD> Khoros Visualization image file.
        </DL>

        With the exception of TIFF and VIFF, all file types store
        1 byte (gray scale and mapped RGB) or 3 bytes (RGB) per
        pixel.

        TIFF and VIFF are aditionally able to store short and long
        integers (2 or 4 bytes) and real values (32 bit float and
        64 bit double) without conversion. So you will need to use
        TIFF or VIFF if you need to store images with high
        accuracy (the appropriate type to write is automatically
        derived from the image type to be exported). However, many
        other programs using TIFF (e.g. ImageMagick) have not
        implemented support for those pixel types.  So don't be
        surprised if the generated TIFF is not readable in some
        cases.  If this happens, export the image as 'unsigned
        char' or 'RGBValue\<unsigned char\>' by calling
        \ref ImageExportInfo::setPixelType().
    **/
    ImageExportInfo & setFileType( const char * );
    const char * getFileType() const;

    /** Set compression type.
    
        Recognized strings: "" (no compression), "LZW",
        "RunLength", "1" ... "100". A number is interpreted as the
        compression quality for JPEG compression. JPEG compression is
        supported by the JPEG and TIFF formats. "LZW" is only available
        if libtiff was installed with LZW enabled. By default, libtiff comes
        with LZW disabled due to Unisys patent enforcement. In this case,
        VIGRA stores the image uncompressed.
    **/
    ImageExportInfo & setCompression( const char * );
    const char * getCompression() const;

    /** Set the pixel type of the image file. Possible values are:
        <DL>
        <DT>"UINT8"<DD> 8-bit unsigned integer (unsigned char)
        <DT>"INT16"<DD> 16-bit signed integer (short)
        <DT>"INT32"<DD> 32-bit signed integer (long)
        <DT>"FLOAT"<DD> 32-bit floating point (float)
        <DT>"DOUBLE"<DD> 64-bit floating point (double)
        </DL>
        
        <b>Usage:</b>
        FImage img(w,h);
        
        // by default, float images are exported with pixeltype float
        // when the target format support this type, i.e. is TIFF or VIFF.
        exportImage(srcImageRange(img), ImageExportInfo("asFloat.tif"));
        
        // if this is not desired, force a different pixeltype
        exportImage(srcImageRange(img), ImageExportInfo("asByte.tif").setPixelType("UINT8"));
    **/
    ImageExportInfo & setPixelType( const char * );

    /** Get the pixel type of the image. Possible values are:
        <DL>
        <DT>"UINT8"<DD> 8-bit unsigned integer (unsigned char)
        <DT>"INT16"<DD> 16-bit signed integer (short)
        <DT>"INT32"<DD> 32-bit signed integer (long)
        <DT>"FLOAT"<DD> 32-bit floating point (float)
        <DT>"DOUBLE"<DD> 64-bit floating point (double)
        </DL>
    **/
    const char * getPixelType() const;

    /** Set the image resolution in horizontal direction
    **/
    ImageExportInfo & setXResolution( float );
    float getXResolution() const;

    /** Set the image resolution in vertical direction
    **/
    ImageExportInfo & setYResolution( float );
    float getYResolution() const;

  private:
    std::string m_filename, m_filetype, m_pixeltype, m_comp;
    float m_x_res, m_y_res;
};

// return an encoder for a given ImageExportInfo object
{'fraction_non_alphanumeric': 0.13244065021634896, 'fraction_numerical': 0.007542977429540404, 'mean_word_length': 2.0179989412387505, 'pattern_counts': {'":': 0, '<': 201, '<?xml version=': 0, '>': 165, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 46, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2855536', 'n_tokens_mistral': 4740, 'n_tokens_neox': 4478, 'n_words': 1600}