コード例 #1
0
void ConvertMapBlackToWhiteAndWhiteToBlack(const char* filename) {
	std::vector<unsigned char> image; //the raw pixels
	unsigned width, height;
	unsigned x, y;
	//decode
	unsigned error = lodepng::decode(image, width, height, filename);

	//if there's an error, display it
	if (error)
		std::cout << "decoder error " << error << ": "
				<< lodepng_error_text(error) << std::endl;

	std::vector<unsigned char> navImage; //the raw pixels
	navImage.resize(width * height * 4);
	unsigned char color;
	for (y = 0; y < height; y++)
		for (x = 0; x < width; x++) {
			if (image[y * width * 4 + x * 4 + 0]
					|| image[y * width * 4 + x * 4 + 1]
					|| image[y * width * 4 + x * 4 + 2])
				color = 0;
			else
				color = 255;
			navImage[y * width * 4 + x * 4 + 0] = color;
			navImage[y * width * 4 + x * 4 + 1] = color;
			navImage[y * width * 4 + x * 4 + 2] = color;
			navImage[y * width * 4 + x * 4 + 3] = 255;
		}

	encodeOneStep("newMap.png", navImage, width, height);
}
コード例 #2
0
///////////////////////////////////////////////////////////////////////
//helper for submission
void captureFrame()
{
  unsigned char* pixels = new unsigned char[3 * win_width * win_height];
  glReadPixels(0, 0, win_width, win_height, GL_RGB, GL_UNSIGNED_BYTE, pixels);
  encodeOneStep(pixels, win_width, win_height, std::string("01"));
  delete[] pixels;
}
コード例 #3
0
ファイル: main.cpp プロジェクト: Sopamo/m2p
void encode(const char* inputFile, const char * outputDir) {
    
    // Read the data
    std::ifstream input(inputFile, std::ios::binary);
    std::vector<char> buffer((
                              std::istreambuf_iterator<char>(input)),
                             (std::istreambuf_iterator<char>()));
    
    if(!input) {
        std::cout << "Could not read file \n";
        return;
    }
    
    
    // Write the data to image files
    unsigned maxSize = 4096 * 4096 * 4;
    unsigned extension = 0;
    while(buffer.size() > maxSize*extension) {
        
        // Generate image dimensions
        unsigned width = sqrt(maxSize / 4), height = width;
        
        // Setup the image vector
        std::vector<unsigned char> image;
        image.resize(width * height * 4);
        
        // Iterate over the pixels and fill them with data
        for(unsigned y = 0; y < height; y++) {
            for(unsigned x = 0; x < width; x++) {
                int idx = 4 * width * y + 4 * x;
                for(unsigned p = 0; p <4;p++) {
                    long value;
                    unsigned pos = maxSize * extension + idx + p;
                    
                    if(pos > buffer.size()) {
                        value = 0;
                    } else {
                        value = (long)buffer[pos];
                    }
                    
                    image[idx + p] = value;
                }
            }
        }
        
        // Generate the part's filename
        std::stringstream filenameStream;
        filenameStream << outputDir << "/out" << extension << ".png";
        auto filename = filenameStream.str();
        encodeOneStep(filename.c_str(), image, width, height);
        std::cout << "Saved part " << extension << "\n";
        extension++;
    }
    
    // We are done, close the input file
    input.close();
    
}
コード例 #4
0
ファイル: PngUtil.cpp プロジェクト: OrLavy/robotics
void PngUtil::mapObjectToPng(const char* filename, MapObject& mapObject) {
	// Get the measurements
	unsigned width = mapObject.getWidth();
	unsigned height = mapObject.getHeight();

	// Allocate a vector for the bytes array
	std::vector<unsigned char> rawPixels;
	rawPixels.resize(width * height * 4);

	// Convert the map object to raw pixels
	convertMapObjectToByteVector(mapObject,rawPixels);

	// Make a png from the raw pixels
	encodeOneStep(filename, rawPixels,width, height);
}
コード例 #5
0
ファイル: Map.cpp プロジェクト: Tawel/Robotics-2015
void Map::thickenMap(string filename, int thickenSizeCM) {

	std::vector<unsigned char> image; //the raw pixels
	unsigned width, height;
	int x, y;
	int i, j;
	//decode
	unsigned error = lodepng::decode(image, width, height, filename);

	//if there's an error, display it
	if (error)
		std::cout << "decoder error " << error << ": "
		<< lodepng_error_text(error) << std::endl;

	std::vector<unsigned char> newImage; //the raw pixels

	newImage.resize(width * height * 4);

	// Initializing thick map
	for (y = 0; y < height; y++)
		for (x = 0; x < width; x++) {
			newImage[y * width * 4 + x * 4 + 0] = 255;
			newImage[y * width * 4 + x * 4 + 1] = 255;
			newImage[y * width * 4 + x * 4 + 2] = 255;
			newImage[y * width * 4 + x * 4 + 3] = 255;
		}

	// thickening map
	for (y = 0; y < height; y++)
		for (x = 0; x < width; x++) {
			if (!(image[y * width * 4 + x * 4 + 0]
			            || image[y * width * 4 + x * 4 + 1]
			                     || image[y * width * 4 + x * 4 + 2])){
				for (i = y - thickenSizeCM; i <= y + thickenSizeCM; i++){
					for (j = x - thickenSizeCM; j <= x + thickenSizeCM; j++){
						if ((i>=0)&&(j>=0)&&(i<height)&&(j<width)){
							newImage[i * width * 4 + j * 4 + 0] = 0;
							newImage[i * width * 4 + j * 4 + 1] = 0;
							newImage[i * width * 4 + j * 4 + 2] = 0;
						}
					}
				}
			}
		}

	// saving pic
	encodeOneStep(THICKENED_MAP_NAME, newImage, width, height);
}
コード例 #6
0
ファイル: pngUtil.cpp プロジェクト: aivrit/RoboticsFinalOne
void blowMap(const char* filename, double mapResolution, double robotSize)

{
	std::vector<unsigned char> image;
	unsigned width, height;
	unsigned x, y;
	unsigned error = lodepng::decode(image, width, height, filename);

	//if there's an error, display it
	if (error)
	{
		std::cout << "decoder error " << error << ": "
				<< lodepng_error_text(error) << std::endl;
	}

	double blowPixelFactor = (robotSize / mapResolution) / 4;
	std::vector<unsigned char> navImage;
	navImage.resize(width * height * 4);
		for (y = 0; y < height; y++)
			for (x = 0; x < width; x++) {
				if (image[y * width * 4 + x * 4 + 0]
						|| image[y * width * 4 + x * 4 + 1]
						|| image[y * width * 4 + x * 4 + 2])
				{
					setPixelColor(navImage, y, x, 255);
				}
			}
		for (y = 0; y < height; y++) {
			for (x = 0; x < width; x++) {
				if (!(image[y * width * 4 + x * 4 + 0]
						|| image[y * width * 4 + x * 4 + 1]
						|| image[y * width * 4 + x * 4 + 2]))
				{
					for (int i = -blowPixelFactor; i < blowPixelFactor; i++)
					{
						for (int j = -blowPixelFactor; j < blowPixelFactor; j++)
						{
							setPixelColor(navImage, y+i, x+j, 0);
						}
					}
				}
			}
		}

		encodeOneStep("newMap.png", navImage, width, height);
}
コード例 #7
0
//saves image to filename given as argument. Warning, this overwrites the file without warning!
int main(int argc, char *argv[])
{
  //NOTE: this sample will overwrite the file or test.png without warning!
  const char* filename = argc > 1 ? argv[1] : "test.png";

  //generate some image
  unsigned width = 512, height = 512;
  std::vector<unsigned char> image;
  image.resize(width * height * 4);
  for(unsigned y = 0; y < height; y++)
  for(unsigned x = 0; x < width; x++)
  {
    image[4 * width * y + 4 * x + 0] = 255 * !(x & y);
    image[4 * width * y + 4 * x + 1] = x ^ y;
    image[4 * width * y + 4 * x + 2] = x | y;
    image[4 * width * y + 4 * x + 3] = 255;
  }

  encodeOneStep(filename, image, width, height);
}
コード例 #8
0
ファイル: main.cpp プロジェクト: destine/slimshadies
int main(int argc, char *argv[])
{
    signal(SIGSEGV, handler);
    FILE* pStream;
    if (argc == 1) {
      pStream = stdin;
    } else if (argc == 2 && (pStream = fopen(argv[1], "r"))) {
    } else {
      usage();
    }
    // initialization
    RayTracer app;
    app.init(pStream);
    app.run();

    // encode raytracer image
    encodeOneStep("output.png", app.getFilm()->getBuffer(), OUTPUT_IMAGE_WIDTH, OUTPUT_IMAGE_HEIGHT);

    // clean up
    app.halt();
    fclose(pStream);
    return 0;
}
コード例 #9
0
ファイル: example_encode.c プロジェクト: Aidan-zhang/lodepng
int main(int argc, char *argv[])
{
  const char* filename = argc > 1 ? argv[1] : "test.png";

  /*generate some image*/
  unsigned width = 512, height = 512;
  unsigned char* image = malloc(width * height * 4);
  unsigned x, y;
  for(y = 0; y < height; y++)
  for(x = 0; x < width; x++)
  {
    image[4 * width * y + 4 * x + 0] = 255 * !(x & y);
    image[4 * width * y + 4 * x + 1] = x ^ y;
    image[4 * width * y + 4 * x + 2] = x | y;
    image[4 * width * y + 4 * x + 3] = 255;
  }

  /*run an example*/
  encodeOneStep(filename, image, width, height);

  free(image);
  return 0;
}