<commit_before>#include <array>
#include <string>
#include <iostream>
#include <vector>
#include <memory>
#include <map>
#include <conio.h>
#include <dpmi.h>
#include <go32.h>
#include <sys/movedata.h>
#include <pc.h>
#include <sys/farptr.h>
#include <bios.h>
#include <sys/nearptr.h>

#include <cstdlib>
#include <cstdio>
#include <functional>
#include <cmath>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstring>
#include <memory>
#include <iostream>
#include <map>
#include <array>
#include <iostream>

#include <conio.h>

#include "Vipper/Vipper.h"
#include "NativeBitmap.h"
#include "CDOSRenderer.h"

//
// Created by monty on 06/10/16.
//
#include <memory>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>

#include "NativeBitmap.h"


#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"



namespace RunTheWorld {

  std::vector<char> readToBuffer(FILE *fileDescriptor) {
    const unsigned N = 1024;
    std::vector<char> total;
    while (true) {
      char buffer[N];
      size_t read = fread((void *) &buffer[0], 1, N, fileDescriptor);
      if (read) {
	for (int c = 0; c < read; ++c) {
	  total.push_back(buffer[c]);
	}
      }
      if (read < N) {
	break;
      }
    }

    return total;
  }
  
  
  std::vector<char> loadBinaryFileFromPath(const std::string &path) {
    FILE *fd;

    fd = fopen(path.c_str(), "rb");

    if (fd == nullptr) {
      exit(0);
    }

    std::vector<char> toReturn = readToBuffer(fd);
    fclose(fd);

    return toReturn;
  }
  
    Vipper::IRenderer::BitmapId CDOSRenderer::loadBitmap( std::string path ) {
      auto id = mSprites.size() + 1;
      
      std::cout << "loading " << path << std::endl;

      auto buffer = loadBinaryFileFromPath( path );
      int xSize;
      int ySize;
      int components;
      
      auto image = stbi_load_from_memory((const stbi_uc *) buffer.data(), buffer.size(), &xSize, &ySize, &components, 0 );
      auto rawData = new int[ xSize * ySize ];
      std::memcpy( rawData, image, xSize * ySize * 4 );
      stbi_image_free(image);
      mSprites[ id ] = std::make_shared<odb::NativeBitmap>( path, xSize, ySize, rawData );
      return id;
    }
    
    Vipper::IRenderer::SoundId CDOSRenderer::loadSound( std::string path ) {
      return 0;
    }
    
    Vipper::IRenderer::FontId CDOSRenderer::loadFont( std::string path, int sizeInPt ) {
      return 0;
    }

  void CDOSRenderer::fill(float x0, float x1, float y0, float x2, float x3, float y1, std::array<int, 4> shade ) {
      
        float fromY = std::min( y0, y1 );
        float toY = std::max( y0, y1 );<commit_msg>Proper optimization for image reuse<commit_after>#include <array>
#include <string>
#include <iostream>
#include <vector>
#include <memory>
#include <map>
#include <conio.h>
#include <dpmi.h>
#include <go32.h>
#include <sys/movedata.h>
#include <pc.h>
#include <sys/farptr.h>
#include <bios.h>
#include <sys/nearptr.h>

#include <cstdlib>
#include <cstdio>
#include <functional>
#include <cmath>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstring>
#include <memory>
#include <iostream>
#include <map>
#include <array>
#include <iostream>

#include <conio.h>

#include "Vipper/Vipper.h"
#include "NativeBitmap.h"
#include "CDOSRenderer.h"

//
// Created by monty on 06/10/16.
//
#include <memory>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>

#include "NativeBitmap.h"


#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"



namespace RunTheWorld {

  std::vector<char> readToBuffer(FILE *fileDescriptor) {
    const unsigned N = 1024;
    std::vector<char> total;
    while (true) {
      char buffer[N];
      size_t read = fread((void *) &buffer[0], 1, N, fileDescriptor);
      if (read) {
	for (int c = 0; c < read; ++c) {
	  total.push_back(buffer[c]);
	}
      }
      if (read < N) {
	break;
      }
    }

    return total;
  }
  
  
  std::vector<char> loadBinaryFileFromPath(const std::string &path) {
    FILE *fd;

    fd = fopen(path.c_str(), "rb");

    if (fd == nullptr) {
      exit(0);
    }

    std::vector<char> toReturn = readToBuffer(fd);
    fclose(fd);

    return toReturn;
  }
  
    Vipper::IRenderer::BitmapId CDOSRenderer::loadBitmap( std::string path ) {
      

      auto id = 1;

      for ( const auto& bitmap : mSprites ) {
	if (bitmap->getId() == path ) {
	  return id;
	}
	++id;
      }
      
      id = mSprites.size() + 1;
      
      std::cout << "loading " << path << std::endl;

      auto buffer = loadBinaryFileFromPath( path );
      int xSize;
      int ySize;
      int components;
      
      auto image = stbi_load_from_memory((const stbi_uc *) buffer.data(), buffer.size(), &xSize, &ySize, &components, 0 );
      auto rawData = new int[ xSize * ySize ];
      std::memcpy( rawData, image, xSize * ySize * 4 );
      stbi_image_free(image);
      mSprites.push_back( std::make_shared<odb::NativeBitmap>( path, xSize, ySize, rawData ) );
      return id;
    }
    
    Vipper::IRenderer::SoundId CDOSRenderer::loadSound( std::string path ) {
      return 0;
    }
    
    Vipper::IRenderer::FontId CDOSRenderer::loadFont( std::string path, int sizeInPt ) {
      return 0;
    }

  void CDOSRenderer::fill(float x0, float x1, float y0, float x2, float x3, float y1, std::array<int, 4> shade ) {
      
        float fromY = std::min( y0, y1 );
        float toY = std::max( y0, y1 );
{'fraction_non_alphanumeric': 0.15234230911102914, 'fraction_numerical': 0.01198819623755072, 'mean_word_length': 3.1779661016949152, 'pattern_counts': {'":': 0, '<': 97, '<?xml version=': 0, '>': 82, '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': '5688500', 'n_tokens_mistral': 2038, 'n_tokens_neox': 1955, 'n_words': 484}