<commit_before>//
//  libavg - Media Playback Engine. 
//  Copyright (C) 2003-2011 <NAME>
//
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2 of the License, or (at your option) any later version.
//
//  This library is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
//  Current versions can be found at www.libavg.de
//

#include "BmpTextureMover.h"

#include "Bitmap.h"
#include "GLTexture.h"

#include "../base/Logger.h"
#include "../base/Exception.h"

#include <iostream>
#include <cstring>

using namespace std;
using namespace boost;

namespace avg {
    
BmpTextureMover::BmpTextureMover(const IntPoint& size, PixelFormat pf)
    : TextureMover(size, pf)
{
}

BmpTextureMover::~BmpTextureMover()
{
}

void BmpTextureMover::moveBmpToTexture(BitmapPtr pBmp, GLTexturePtr pTex)
{
    AVG_ASSERT(pBmp->getSize() == pTex->getSize());
    AVG_ASSERT(getSize() == pBmp->getSize());
    AVG_ASSERT(pBmp->getPixelFormat() == getPF());
    pTex->activate();
    unsigned char * pStartPos = pBmp->getPixels();
    IntPoint size = pTex->getSize();
    glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, size.x, size.y,
            pTex->getGLFormat(getPF()), pTex->getGLType(getPF()), 
            pStartPos);
    OGLErrorCheck(AVG_ERR_VIDEO_GENERAL, 
            "BmpTextureMover::moveBmpToTexture: glTexSubImage2D()");
}

BitmapPtr BmpTextureMover::moveTextureToBmp(GLTexturePtr pTex) const
{
    AVG_ASSERT(getSize() == pTex->getGLSize());
    BitmapPtr pBmp(new Bitmap(pTex->getGLSize(), getPF()));

    pTex->activate(GL_TEXTURE0);

    unsigned char * pStartPos = pBmp->getPixels();
    glGetTexImage(GL_TEXTURE_2D, 0, GLTexture::getGLFormat(getPF()), 
            GLTexture::getGLType(getPF()), pStartPos);
    OGLErrorCheck(AVG_ERR_VIDEO_GENERAL, 
            "BmpTextureMover::moveTextureToBmp: glGetTexImage()");
    
    IntPoint activeSize = pTex->getSize();
    if (activeSize != pTex->getGLSize()) {
        BitmapPtr pTempBmp = pBmp;
        pBmp = BitmapPtr(new Bitmap(activeSize, getPF(), pStartPos, 
                pTempBmp->getStride(), true)); 
    }
    
    return pBmp;
}

BitmapPtr BmpTextureMover::lock()
{
    m_pBmp = BitmapPtr(new Bitmap(getSize(), getPF()));
    return m_pBmp;
}

void BmpTextureMover::unlock()
{
}

void BmpTextureMover::moveToTexture(GLTexturePtr pTex)
{
    moveBmpToTexture(m_pBmp, pTex);
    m_pBmp = BitmapPtr();
}

}
<commit_msg>renderer branch: Reverted 6746 - unneeded.<commit_after>//
//  libavg - Media Playback Engine. 
//  Copyright (C) 2003-2011 <NAME>
//
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2 of the License, or (at your option) any later version.
//
//  This library is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
//  Current versions can be found at www.libavg.de
//

#include "BmpTextureMover.h"

#include "Bitmap.h"
#include "GLTexture.h"

#include "../base/Logger.h"
#include "../base/Exception.h"

#include <iostream>
#include <cstring>

using namespace std;
using namespace boost;

namespace avg {
    
BmpTextureMover::BmpTextureMover(const IntPoint& size, PixelFormat pf)
    : TextureMover(size, pf)
{
    m_pBmp = BitmapPtr(new Bitmap(size, pf));
}

BmpTextureMover::~BmpTextureMover()
{
}

void BmpTextureMover::moveBmpToTexture(BitmapPtr pBmp, GLTexturePtr pTex)
{
    AVG_ASSERT(pBmp->getSize() == pTex->getSize());
    AVG_ASSERT(getSize() == pBmp->getSize());
    AVG_ASSERT(pBmp->getPixelFormat() == getPF());
    pTex->activate();
    unsigned char * pStartPos = pBmp->getPixels();
    IntPoint size = pTex->getSize();
    glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, size.x, size.y,
            pTex->getGLFormat(getPF()), pTex->getGLType(getPF()), 
            pStartPos);
    OGLErrorCheck(AVG_ERR_VIDEO_GENERAL, 
            "BmpTextureMover::moveBmpToTexture: glTexSubImage2D()");
}

BitmapPtr BmpTextureMover::moveTextureToBmp(GLTexturePtr pTex) const
{
    AVG_ASSERT(getSize() == pTex->getGLSize());
    BitmapPtr pBmp(new Bitmap(pTex->getGLSize(), getPF()));

    pTex->activate(GL_TEXTURE0);

    unsigned char * pStartPos = pBmp->getPixels();
    glGetTexImage(GL_TEXTURE_2D, 0, GLTexture::getGLFormat(getPF()), 
            GLTexture::getGLType(getPF()), pStartPos);
    OGLErrorCheck(AVG_ERR_VIDEO_GENERAL, 
            "BmpTextureMover::moveTextureToBmp: glGetTexImage()");
    
    IntPoint activeSize = pTex->getSize();
    if (activeSize != pTex->getGLSize()) {
        BitmapPtr pTempBmp = pBmp;
        pBmp = BitmapPtr(new Bitmap(activeSize, getPF(), pStartPos, 
                pTempBmp->getStride(), true)); 
    }
    
    return pBmp;
}

BitmapPtr BmpTextureMover::lock()
{
    return m_pBmp;
}

void BmpTextureMover::unlock()
{
}

void BmpTextureMover::moveToTexture(GLTexturePtr pTex)
{
    moveBmpToTexture(m_pBmp, pTex);
}

}

{'fraction_non_alphanumeric': 0.12476595744680852, 'fraction_numerical': 0.011574468085106383, 'mean_word_length': 3.697042366107114, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 41, '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': '6323131', 'n_tokens_mistral': 2059, 'n_tokens_neox': 1975, 'n_words': 504}