<commit_before>
#include <osg/Image>
#include <osg/Notify>
#include <osg/Geode>
#include <osg/GL>

#include <osgDB/Registry>
#include <osgDB/FileUtils>
#include <osgDB/FileNameUtils>

#include <stdio.h>
#include <tiffio.h>

/****************************************************************************
 *
 * Follows is code extracted from the simage library.  Original Authors:
 *
 *      Systems in Motion,
 *      <URL:http://www.sim.no>
 *
 *      <NAME> <<EMAIL>>
 *      <NAME> <<EMAIL>>
 *      <NAME> <<EMAIL>>
 *
 * The original COPYING notice
 *
 *      All files in this library are public domain, except simage_rgb.cpp which is
 *      Copyright (c) <NAME> <<EMAIL>>. I will contact Mark
 *      very soon to hear if this source also can become public domain.
 *
 *      Please send patches for bugs and new features to: <<EMAIL>>.
 *
 *      <NAME>
 *
 *
 * Ported into the OSG as a plugin, <NAME>ber 2000.
 * Note, reference above to license of simage_rgb is not relevent to the OSG
 * as the OSG does not use it.  Also for patches, bugs and new features
 * please send them direct to the OSG dev team rather than address above.
 *
 **********************************************************************/


#include <string.h>
#include <stdarg.h>
#include <assert.h>
#include <stdlib.h>

#define ERR_NO_ERROR    0
#define ERR_OPEN        1
#define ERR_READ        2
#define ERR_MEM         3
#define ERR_UNSUPPORTED 4
#define ERR_TIFFLIB     5

/* Functions to read TIFF image from memory
 *
 */

tsize_t libtiffStreamReadProc(thandle_t fd, tdata_t buf, tsize_t size)
{
    std::istream *fin = (std::istream*)fd;

    fin->read((char*)buf,size);

    if(fin->bad())
        return -1;

    if(fin->gcount() < size)
    return 0;

    return size;
}

tsize_t libtiffStreamWriteProc(thandle_t fd, tdata_t buf, tsize_t size)
{
    return 0;
}

toff_t libtiffStreamSeekProc(thandle_t fd, toff_t off, int i)
{
    std::istream *fin = (std::istream*)fd;

    toff_t ret;
    switch(i)
    {
        case SEEK_SET:
            fin->seekg(off,std::ios::beg);
            ret = fin->tellg();
            if(fin->bad())
                ret = -1;
            break;

        case SEEK_CUR:
            fin->seekg(off,std::ios::cur);
            ret = fin->tellg();
            if(fin->bad())
                ret = -1;
            break;

        case SEEK_END:
            fin->seekg(off,std::ios::end);
            ret = fin->tellg();
            if(fin->bad())
                ret = -1;
            break;
        default:
            ret = -1;
            break;
    }
    return ret;
}

int libtiffStreamCloseProc(thandle_t fd)
{
    return 0;
}

toff_t libtiffStreamSizeProc(thandle_t fd)
{
    std::istream *fin = (std::istream*)fd;

    std::streampos curPos = fin->tellg();

    fin->seekg(0, std::ios::end);
    toff_t size = fin->tellg();
    fin->seekg(curPos, std::ios::beg);

    return size;
}

int libtiffStreamMapProc(thandle_t fd, tdata_t*addr, toff_t*len)
{
    return 0;
}

void libtiffStreamUnmapProc(thandle_t, tdata_t, toff_t)
{
}

static int tifferror = ERR_NO_ERROR;

int
simage_tiff_error(char * buffer, int buflen)
{
    switch (tifferror)
    {
        case ERR_OPEN:
            strncpy(buffer, "TIFF loader: Error opening file", buflen);
            break;
        case ERR_MEM:
            strncpy(buffer, "TIFF loader: Out of memory error", buflen);
            break;
        case ERR_UNSUPPORTED:
            strncpy(buffer, "TIFF loader: Unsupported image type", buflen);
            break;
        case ERR_TIFFLIB:
            strncpy(buffer, "TIFF loader: Illegal tiff file", buflen);
            break;
    }
    return tifferror;
}


static void
tiff_error(const char*, const char*, va_list)
{
    // values are (const char* module, const char* fmt, va_list list)
    /* FIXME: store error message ? */
}


static void
tiff_warn(const char *, const char *, va_list)
{
    // values are (const char* module, const char* fmt, va_list list)<commit_msg>From <NAME>, fixed warnings.<commit_after>
#include <osg/Image>
#include <osg/Notify>
#include <osg/Geode>
#include <osg/GL>

#include <osgDB/Registry>
#include <osgDB/FileUtils>
#include <osgDB/FileNameUtils>

#include <stdio.h>
#include <tiffio.h>

/****************************************************************************
 *
 * Follows is code extracted from the simage library.  Original Authors:
 *
 *      Systems in Motion,
 *      <URL:http://www.sim.no>
 *
 *      <NAME> <<EMAIL>>
 *      <NAME> <<EMAIL>>
 *      <NAME> <<EMAIL>>
 *
 * The original COPYING notice
 *
 *      All files in this library are public domain, except simage_rgb.cpp which is
 *      Copyright (c) <NAME> <<EMAIL>>. I will contact Mark
 *      very soon to hear if this source also can become public domain.
 *
 *      Please send patches for bugs and new features to: <<EMAIL>>.
 *
 *      <NAME>
 *
 *
 * Ported into the OSG as a plugin, <NAME> 2000.
 * Note, reference above to license of simage_rgb is not relevent to the OSG
 * as the OSG does not use it.  Also for patches, bugs and new features
 * please send them direct to the OSG dev team rather than address above.
 *
 **********************************************************************/


#include <string.h>
#include <stdarg.h>
#include <assert.h>
#include <stdlib.h>

#define ERR_NO_ERROR    0
#define ERR_OPEN        1
#define ERR_READ        2
#define ERR_MEM         3
#define ERR_UNSUPPORTED 4
#define ERR_TIFFLIB     5

/* Functions to read TIFF image from memory
 *
 */

tsize_t libtiffStreamReadProc(thandle_t fd, tdata_t buf, tsize_t size)
{
    std::istream *fin = (std::istream*)fd;

    fin->read((char*)buf,size);

    if(fin->bad())
        return -1;

    if(fin->gcount() < size)
        return 0;

    return size;
}

tsize_t libtiffStreamWriteProc(thandle_t, tdata_t, tsize_t)
{
    return 0;
}

toff_t libtiffStreamSeekProc(thandle_t fd, toff_t off, int i)
{
    std::istream *fin = (std::istream*)fd;

    toff_t ret;
    switch(i)
    {
        case SEEK_SET:
            fin->seekg(off,std::ios::beg);
            ret = fin->tellg();
            if(fin->bad())
                ret = 0;
            break;

        case SEEK_CUR:
            fin->seekg(off,std::ios::cur);
            ret = fin->tellg();
            if(fin->bad())
                ret = 0;
            break;

        case SEEK_END:
            fin->seekg(off,std::ios::end);
            ret = fin->tellg();
            if(fin->bad())
                ret = 0;
            break;
        default:
            ret = 0;
            break;
    }
    return ret;
}

int libtiffStreamCloseProc(thandle_t)
{
    return 0;
}

toff_t libtiffStreamSizeProc(thandle_t fd)
{
    std::istream *fin = (std::istream*)fd;

    std::streampos curPos = fin->tellg();

    fin->seekg(0, std::ios::end);
    toff_t size = fin->tellg();
    fin->seekg(curPos, std::ios::beg);

    return size;
}

int libtiffStreamMapProc(thandle_t, tdata_t*, toff_t*)
{
    return 0;
}

void libtiffStreamUnmapProc(thandle_t, tdata_t, toff_t)
{
}

static int tifferror = ERR_NO_ERROR;

int
simage_tiff_error(char * buffer, int buflen)
{
    switch (tifferror)
    {
        case ERR_OPEN:
            strncpy(buffer, "TIFF loader: Error opening file", buflen);
            break;
        case ERR_MEM:
            strncpy(buffer, "TIFF loader: Out of memory error", buflen);
            break;
        case ERR_UNSUPPORTED:
            strncpy(buffer, "TIFF loader: Unsupported image type", buflen);
            break;
        case ERR_TIFFLIB:
            strncpy(buffer, "TIFF loader: Illegal tiff file", buflen);
            break;
    }
    return tifferror;
}






static void
tiff_error(const char*, const char*, va_list)
{
    // values are (const char* module, const char* fmt, va_list list)
    /* FIXME: store error message ? */
}


static void
tiff_warn(const char *, const char *, va_list)
{
    // values are (const char* module, const char* fmt, va_list list)
{'fraction_non_alphanumeric': 0.15380755237736796, 'fraction_numerical': 0.00501819094216535, 'mean_word_length': 2.5026362038664325, 'pattern_counts': {'":': 0, '<': 66, '<?xml version=': 0, '>': 96, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '919655', 'n_tokens_mistral': 2774, 'n_tokens_neox': 2675, 'n_words': 735}