<commit_before>/*******************************************************************************
 * This file is part of TERMINAL RECALL 
 * Copyright (c) 2012, 2013 <NAME>.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the COPYING and CREDITS files for more details.
 * 
 * Contributors:
 *      chuck - initial API and implementation
 ******************************************************************************/
package org.jtrfp.trcl;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;

import javax.imageio.ImageIO;
import javax.media.opengl.GL3;

import org.jtrfp.trcl.gpu.GLTexture;
import org.jtrfp.trcl.gpu.GPU;

public class Texture implements TextureDescription
	{
	TextureTreeNode nodeForThisTexture;
	private Color averageColor;
	private static double pixelSize=1./512.; //This is a kludge; doesn't scale with megatexture
	private static TextureTreeNode rootNode=null;
	private static GLTexture globalTexture;
	private static final Texture fallbackTexture;
	static  {
		Texture t;
		t=new Texture(RGBA8FromPNG(Texture.class.getResourceAsStream("/fallbackTexture.png")));
		fallbackTexture=t;
		}
	private static ByteBuffer emptyRow=null;
	
	public Texture(ByteBuffer imageRGB8)
		{
		final int sideLength=(int)Math.sqrt((imageRGB8.capacity()/4));
		TextureTreeNode newNode = new TextureTreeNode(sideLength,null);
		nodeForThisTexture=newNode;
		newNode.setImage(imageRGB8);
		registerNode(newNode);
		}//end constructor
	
	public Texture(BufferedImage img)
		{
		final int sideLength=img.getWidth();
		TextureTreeNode newNode = new TextureTreeNode(sideLength,null);
		nodeForThisTexture=newNode;
		BufferedImage scaledDown=new BufferedImage(img.getWidth(),img.getHeight(),BufferedImage.TYPE_INT_ARGB);
		Graphics g = scaledDown.getGraphics();
		g.drawImage(img,0, 0, img.getWidth(), img.getHeight(), 0, 0, img.getWidth(), img.getHeight(), null);
		g.drawImage(img, 4, 4, img.getWidth()-2, img.getHeight()-2, 0, 0, img.getWidth(), img.getHeight(), null);
		g.dispose();
		long redA=0,greenA=0,blueA=0;
		ByteBuffer data = ByteBuffer.allocateDirect(img.getWidth()*img.getHeight()*4);
		for(int y=0; y<img.getHeight(); y++)
			{for(int x=0; x<img.getWidth(); x++)
				{Color c= new Color(scaledDown.getRGB(x, y),true);
				data.put((byte)c.getRed());
				data.put((byte)c.getGreen());
				data.put((byte)c.getBlue());
				data.put((byte)c.getAlpha());
				redA+=c.getRed();
				greenA+=c.getGreen();
				blueA+=c.getBlue();
				}//end for(x)
			}//end for(y)
		final int div=data.capacity()/4;
		averageColor=new Color((redA/div)/255f,(greenA/div)/255f,(blueA/div)/255f);
		newNode.setImage(data);
		registerNode(newNode);
		}<commit_msg>Removed sub-scaled texture blitting (ineffective seam removal)<commit_after>/*******************************************************************************
 * This file is part of TERMINAL RECALL 
 * Copyright (c) 2012, 2013 <NAME>.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the COPYING and CREDITS files for more details.
 * 
 * Contributors:
 *      chuck - initial API and implementation
 ******************************************************************************/
package org.jtrfp.trcl;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;

import javax.imageio.ImageIO;
import javax.media.opengl.GL3;

import org.jtrfp.trcl.gpu.GLTexture;
import org.jtrfp.trcl.gpu.GPU;

public class Texture implements TextureDescription
	{
	TextureTreeNode nodeForThisTexture;
	private Color averageColor;
	private static double pixelSize=1./512.; //This is a kludge; doesn't scale with megatexture
	private static TextureTreeNode rootNode=null;
	private static GLTexture globalTexture;
	private static final Texture fallbackTexture;
	static  {
		Texture t;
		t=new Texture(RGBA8FromPNG(Texture.class.getResourceAsStream("/fallbackTexture.png")));
		fallbackTexture=t;
		}
	private static ByteBuffer emptyRow=null;
	
	public Texture(ByteBuffer imageRGB8)
		{
		final int sideLength=(int)Math.sqrt((imageRGB8.capacity()/4));
		TextureTreeNode newNode = new TextureTreeNode(sideLength,null);
		nodeForThisTexture=newNode;
		newNode.setImage(imageRGB8);
		registerNode(newNode);
		}//end constructor
	
	public Texture(BufferedImage img)
		{
		final int sideLength=img.getWidth();
		TextureTreeNode newNode = new TextureTreeNode(sideLength,null);
		nodeForThisTexture=newNode;
		//BufferedImage scaledDown=new BufferedImage(img.getWidth(),img.getHeight(),BufferedImage.TYPE_INT_ARGB);
		//Graphics g = scaledDown.getGraphics();
		//g.drawImage(img,0, 0, img.getWidth(), img.getHeight(), 0, 0, img.getWidth(), img.getHeight(), null);
		//g.drawImage(img, 4, 4, img.getWidth()-2, img.getHeight()-2, 0, 0, img.getWidth(), img.getHeight(), null);
		//g.dispose();
		long redA=0,greenA=0,blueA=0;
		ByteBuffer data = ByteBuffer.allocateDirect(img.getWidth()*img.getHeight()*4);
		for(int y=0; y<img.getHeight(); y++)
			{for(int x=0; x<img.getWidth(); x++)
				{Color c= new Color(img.getRGB(x, y),true);
				data.put((byte)c.getRed());
				data.put((byte)c.getGreen());
				data.put((byte)c.getBlue());
				data.put((byte)c.getAlpha());
				redA+=c.getRed();
				greenA+=c.getGreen();
				blueA+=c.getBlue();
				}//end for(x)
			}//end for(y)
		final int div=data.capacity()/4;
		averageColor=new Color((redA/div)/255f,(greenA/div)/255f,(blueA/div)/255f);
		newNode.setImage(data);
		registerNode(newNode);
		}
{'fraction_non_alphanumeric': 0.17115325787702662, 'fraction_numerical': 0.014071581523401652, 'mean_word_length': 5.157250470809793, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, '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': '400653', 'n_tokens_mistral': 2253, 'n_tokens_neox': 2050, 'n_words': 500}