<commit_before>#include <stdio.h>
#include <string.h>

#include <osg/Geode>
#include <osg/Group>
#include <osg/Notify>

#include <osgDB/Registry>

#include "ConvertToPerformer.h"
#include "ConvertFromPerformer.h"

#include <Performer/pfdu.h>
#include <Performer/pr/pfTexture.h>

extern "C" {
extern pfNode *pfdLoadFile_pfb( const char *);
extern int pfdStoreFile_pfb( pfNode *, const char *);
}

class ReaderWriterPFB : public osgDB::ReaderWriter
{

    public:

        ReaderWriterPFB();
        ~ReaderWriterPFB();

        void initPerformer();

        virtual const char* className() { return "Performer Reader/Writer"; }
        virtual bool acceptsExtension(const std::string& extension) { return extension=="pfb"; }

        virtual osg::Image* readImage(const std::string& fileName, const osgDB::ReaderWriter::Options*)
        {
            osg::notify(osg::INFO)<<   "ReaderWriterPFB::readImage( "<<fileName.c_str()<<" )\n";

            initPerformer();

            pfTexture* tex = new pfTexture;
            if (tex->loadFile(fileName.c_str()))
            {
                int s=0;
                int t=0;
                int r=0;
                int comp=0;
                unsigned int* imageData = NULL;

                tex->getImage(&imageData,&comp,&s,&t,&r);

                int internalFormat = comp;

                unsigned int pixelFormat =
                    comp == 1 ? GL_LUMINANCE :
                comp == 2 ? GL_LUMINANCE_ALPHA :
                comp == 3 ? GL_RGB :
                comp == 4 ? GL_RGBA : (GLenum)-1;

                unsigned int dataType = GL_UNSIGNED_BYTE;

                osg::Image* image = new osg::Image;
                image->setFileName(fileName.c_str());
                image->setImage(s,t,r,
                    internalFormat,
                    pixelFormat,
                    dataType,
                    (unsigned char*)imageData);

                return image;
            }

            return NULL;
        }

        virtual osg::Node* readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*)
        {
            osg::notify(osg::INFO)<<   "ReaderWriterPFB::readNode( "<<fileName.c_str()<<" )\n";

            initPerformer();
            pfNode* root = pfdLoadFile_pfb(fileName.c_str());

            ConvertFromPerformer converter;
            return converter.convert(root);

        }

        virtual bool writeNode(const osg::Node& node,const std::string& fileName, const osgDB::ReaderWriter::Options*)
        {
            osg::notify(osg::INFO)<<   "ReaderWriterPFB::writeNode( "<<fileName.c_str()<<" )\n";
            initPerformer();
            ConvertToPerformer converter;
            pfNode* root = converter.convert(&node);
            if (root)
            {
                return pfdStoreFile_pfb(root,fileName.c_str())!=0;
            }
            else
            {
                return false;
            }
        }

    protected:

        bool _performerInitialised;

};
<commit_msg>Fixed problem caused by ReaderWriterPFB::writeNode(..) not ensuring that the file extension was .pfb. Have added a check.<commit_after>#include <stdio.h>
#include <string.h>

#include <osg/Geode>
#include <osg/Group>
#include <osg/Notify>

#include <osgDB/Registry>

#include "ConvertToPerformer.h"
#include "ConvertFromPerformer.h"

#include <Performer/pfdu.h>
#include <Performer/pr/pfTexture.h>

extern "C" {
extern pfNode *pfdLoadFile_pfb( const char *);
extern int pfdStoreFile_pfb( pfNode *, const char *);
}

class ReaderWriterPFB : public osgDB::ReaderWriter
{

    public:

        ReaderWriterPFB();
        ~ReaderWriterPFB();

        void initPerformer();

        virtual const char* className() { return "Performer Reader/Writer"; }
        virtual bool acceptsExtension(const std::string& extension) { return extension=="pfb"; }

        virtual osg::Image* readImage(const std::string& fileName, const osgDB::ReaderWriter::Options*)
        {
            osg::notify(osg::INFO)<<   "ReaderWriterPFB::readImage( "<<fileName.c_str()<<" )\n";

            initPerformer();

            pfTexture* tex = new pfTexture;
            if (tex->loadFile(fileName.c_str()))
            {
                int s=0;
                int t=0;
                int r=0;
                int comp=0;
                unsigned int* imageData = NULL;

                tex->getImage(&imageData,&comp,&s,&t,&r);

                int internalFormat = comp;

                unsigned int pixelFormat =
                    comp == 1 ? GL_LUMINANCE :
                comp == 2 ? GL_LUMINANCE_ALPHA :
                comp == 3 ? GL_RGB :
                comp == 4 ? GL_RGBA : (GLenum)-1;

                unsigned int dataType = GL_UNSIGNED_BYTE;

                osg::Image* image = new osg::Image;
                image->setFileName(fileName.c_str());
                image->setImage(s,t,r,
                    internalFormat,
                    pixelFormat,
                    dataType,
                    (unsigned char*)imageData);

                return image;
            }

            return NULL;
        }

        virtual osg::Node* readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*)
        {
            osg::notify(osg::INFO)<<   "ReaderWriterPFB::readNode( "<<fileName.c_str()<<" )\n";

            initPerformer();
            pfNode* root = pfdLoadFile_pfb(fileName.c_str());

            ConvertFromPerformer converter;
            return converter.convert(root);

        }

        virtual bool writeNode(const osg::Node& node,const std::string& fileName, const osgDB::ReaderWriter::Options*)
        {
            std::string ext = osgDB::getLowerCaseFileExtension(fileName);
            if (!acceptsExtension(ext)) return false;


            osg::notify(osg::INFO)<<   "ReaderWriterPFB::writeNode( "<<fileName.c_str()<<" )\n";
            initPerformer();
            ConvertToPerformer converter;
            pfNode* root = converter.convert(&node);
            if (root)
            {
                return pfdStoreFile_pfb(root,fileName.c_str())!=0;
            }
            else
            {
                return false;
            }
        }

    protected:

        bool _performerInitialised;

};

{'fraction_non_alphanumeric': 0.1205685084637496, 'fraction_numerical': 0.0031938677738741618, 'mean_word_length': 1.8729357798165138, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2634618', 'n_tokens_mistral': 1893, 'n_tokens_neox': 1775, 'n_words': 369}