Пример #1
0
/*
 * Read an image
 */
int RImage::read(char file[100]) {
	if (strstr(file, ".ppm") != NULL) {
		type = PPM;
		readPPM(file);

	} else if (strstr(file, ".pgm") != NULL){
		type = PGM;
		readPGM(file);

	} else if (strstr(file, ".jpeg") != NULL ||
			strstr(file, ".jpg") != NULL) {
		type = JPEG;
		readJPEG(file);

	} else if (strstr(file, ".png") != NULL) {
		fprintf(stderr, "ERROR: Format not supported as yet.\n");
		type = PNG;
		readPNG(file);

	} else {
		fprintf(stderr, "ERROR: Cannot read image %s.\n", file);
		exit(1);
	}

	return 0;
}
Пример #2
0
/**
 * Entry point for the program.
 */
int main(int argc, char **argv)
{
    Color_t *original;
    int width, height;
    int n_polygons           = N_POLYGONS;
    int n_sides              = DEFAULT_POLYGON_POINTS;
    double target_percentage = -1.0f;
    char *filename           = INPUT_IMAGE;

    /* Check for any command-line arguments. */
    process_args(argc, argv, &filename, &n_sides, &n_polygons,
            &target_percentage);

    /* Seed the random number generated with the current time. */
    srand(time(NULL));

    /* Read in the original image. */
    original = readPNG(filename, &width, &height);

    /* Kick off the polygon loop. */
    main_loop(original, width, height, n_sides, n_polygons, target_percentage);

    free(original);
    return 0;
}
Пример #3
0
void textureLoadWithFilename(const char *filename, GLuint *texturename) 
{
	unsigned char *image_data;

	/* FIXME: test mime instead */	
	if(strcasestr(filename, ".png") != NULL) {
		image_data = readPNG(filename);
	} else {
		image_data = readJPEG(filename);
	}

	powerOfTwoScaling(&image_data, &tex_width, &tex_height);
// scale4x(&image_data, tex_width, tex_height);

	if(image_data != NULL) {
		glBindTexture(GL_TEXTURE_2D, (*texturename));
		glTexParameteri(GL_TEXTURE_2D, 
			GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, 
			GL_TEXTURE_MAG_FILTER, GL_LINEAR);

		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex_width, tex_height, 
			0, GL_RGBA, GL_UNSIGNED_BYTE, image_data);

		free(image_data);

		printf("SUCCESS: loadTextureWithFilename():" 
			" %s\n", filename);		
	}
}
Пример #4
0
GLImageStructure readImage(const std::string& FileName, ImageType type_hint)
{
  if (type_hint==itUnknown)
  {
    type_hint = getImageType(FileName);
  }
  switch (type_hint)
  {
    case itJPEG:
         return readJPEG(FileName);
    case itPNG:
         return readPNG(FileName);
    case itGIF:
         return readGIF(FileName);
    case itBitmap:
         return readBMP(FileName);
    case itPPM:
         return readPPM(FileName);
  }

  //no supported image here
  GLImageStructure temp_glis;
  temp_glis.setWidth(0);
  temp_glis.setHeight(0);
  temp_glis.setFormat(0);
  temp_glis.setBuffer(NULL);
  return temp_glis;
}
Пример #5
0
int main(int argc, char* argv[]) {
	// Test with example.png
	//readPNG(PNG_PATH, 1);

	/*
	printf("Arguments:\n\tARGC: %d\n", argc);
	puts("\tARGV: ");
	for (int i = 0; i < argc; i++)
		printf("\t\t%s\n", argv[i]);
	 */

	int verbose = 0;
	int i = 1;

	if (argc > 1)
		verbose = (strcmp(argv[1], "--verbose") == 0);

	if ((! verbose && argc > 1) || (verbose && argc > 2)) {
		if (verbose && argc > 2) i = 2;
		for (; i < argc; i++)
			readPNG(argv[i], verbose);
	}
	else {
		printf("Usage: pngDebugger (--verbose) file1.png file2.png file3.png ...\n");
	}

	return 0;
}
Пример #6
0
static void png2dbl(const char *pngfile, const char *dblfile)
{
	struct pngdata png;
	png = readPNG(fopen(pngfile, "rb"));
	FILE *f = fopen(dblfile, "wb");
	writeDBL(f, png);
	fclose(f);
}
Пример #7
0
int main(int argc,char **argv){
	int width,height;
	int **pixel;
	int **out;
	float **tmp;
	pixel = readPNG(argv[1],&width,&height);
	
	writePNG("res_original.png",pixel,width,height);

	out = histEQ(pixel,width,height);
	writePNG("res_Equalized.png",out,width,height);
	FREE_PIXEL(out);

	out = getNegative(pixel,width,height);
	writePNG("res_Negative.png",out,width,height);
	FREE_PIXEL(out);

	out = halfIntensity(pixel,width,height);
	writePNG("res_HalfI.png",out,width,height);
	FREE_PIXEL(out);
	
	out = IRescale(pixel,width,height,min,max,0,100);
	writePNG("res_scaleto0100.png",out,width,height);
	FREE_PIXEL(out);

	out = IRescale(pixel,width,height,min,max,200,255);
	writePNG("res_scaleto200255.png",out,width,height);
	FREE_PIXEL(out);

	tmp = getExp(pixel,width,height,20,1.01);
	out = Normalize(tmp,width,height);
	writePNG("res_exp.png",out,width,height);
	FREE_PIXEL(out);

	tmp = getLog(pixel,width,height,20.2);
	out = Normalize(tmp,width,height);
	writePNG("res_log.png",out,width,height);
	FREE_PIXEL(out);
	
	tmp = getPower(pixel,width,height,1,0.5);
	out = Normalize(tmp,width,height);
	writePNG("res_powerg05.png",out,width,height);
	FREE_PIXEL(out);
	
	tmp = getPower(pixel,width,height,1,2);
	out = Normalize(tmp,width,height);
	writePNG("res_powerg2.png",out,width,height);
	FREE_PIXEL(out);

	tmp = getPower(pixel,width,height,1,2.5);
	out = Normalize(tmp,width,height);
	writePNG("res_powerg25.png",out,width,height);
	FREE_PIXEL(out);
	//printHist(out,width,height);

	free(pixel);
return 0;
}
Пример #8
0
Image *
readPNG(const char *filename)
{
    std::ifstream is(filename, std::ifstream::binary);
    if (!is) {
        return NULL;
    }
    return readPNG(filename);
}
Пример #9
0
void loadIcons(char* dirPath) {
	
	DIR* dir;
	struct dirent* de;
	int texCount = 0;
	int maxW = 0, maxH = 0;
	BitmapRGBA8* bmp;
	
	dir = opendir(dirPath);
	
	while((de = readdir(dir)) != NULL) {
		if(!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..")) continue;
		
		bmp = readPNG(de->d_name);
		
	}
	
	closedir(dir);
}
Пример #10
0
/**
 * Loads the texture with the tile images.
 */
bool GLTileEngine::loadTexture()
{
	int width, height, allocWidth, allocHeight;

	// read the tile data from a PNG image on the filesystem
	void* textureBuffer = readPNG("images/micropolisEngine/tiles_borders.png", &width, &height, &allocWidth, &allocHeight);
	if(textureBuffer == NULL) return false;

	// actually create the tile map texture
	glGenTextures(1, &this->texture);
	glBindTexture(GL_TEXTURE_2D, this->texture);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, allocWidth, allocHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureBuffer);

	// don't forget to free the buffer allocated by readPNG!
	free(textureBuffer);
	
	return true;
}
Пример #11
0
void BackgroundLayer::initSingleImage(int row, int column) {
	if (_loadedCount == 0) {
		return;
	}
	auto countColumn = _imageColumnEndPos - _imageColumnStartPos + 1;
	auto countRow = _imageRowEndPos - _imageRowStartPos + 1;
	auto flag = true;

	for (auto &bi : _backgroundImages) {
		if (!bi.isShown) {
			flag = false;
		}
		if (row == bi.row && column == bi.column) {
			if (!bi.isShown) {
				--_loadedCount;

				auto *sprite = cocos2d::Sprite::create(bi.backgroundPath);
				sprite->setAnchorPoint(cocos2d::Vec2::ZERO);
				sprite->setPosition(
					cocos2d::Vec2((bi.column - 1) * SINGLE_MAP_WIDTH,
					(bi.row - 1) * SINGLE_MAP_HEIGHT));
				sprite->setTag((bi.row - 1) * countRow + bi.column);
				addChild(sprite);

				auto readPNGThread = [&]() {bi.maskImage = readPNG(bi.maskPath);};
				std::thread th = std::thread(readPNGThread);
				th.detach();

				bi.backgroundImage = sprite;
				bi.isShown = true;

				break;
			}
		}
	}

	return;
}
Пример #12
0
int main (int argc, char * const argv[]) {

#if 0
	FILE *tf;
	tf = fopen(TEST_PVR_FILE, "rb");
	readPvr(tf);
	fclose(tf);
#endif
	
	FILE *wf;
	FILE *rf;
    // insert code here...
    memset(gPNGFileName,0,256);
    memset(gPVRFileName,0,256);
	
	if(parseArgs(argc, argv)){
#if 1		
		char *argv2[MAX_ARGS];
		for(int i=0; i<MAX_ARGS-1; i++){
			argv2[i] = new char[256];
		}
		strcpy(argv2[0],"texturetool");
		strcpy(argv2[1],"-e");
		strcpy(argv2[2],"PVRTC");
		if(gChannelWeight==0){
			strcpy(argv2[3],"--channel-weighting-linear");
		}
		else if(gChannelWeight==1){		
			strcpy(argv2[3],"--channel-weighting-perceptual");
		}
		else{ 
			usage();
			return -1;
		}
		if(gBitsPerPixel==2){
			strcpy(argv2[4],"--bits-per-pixel-2");
		}
		else if(gBitsPerPixel==4){		
			strcpy(argv2[4],"--bits-per-pixel-4");
		}
		else{ 
			usage();
			return -1;
		}

		strcpy(argv2[5],gPNGFileName);

		strcpy(argv2[6],"-o");
		strcpy(argv2[7],TEMP_OUTPUT_FILE);
		
		if(gGenerateMipMaps==1){
			strcpy(argv2[8],"-m");
		}
		else{
			delete argv2[MAX_ARGS-2];
			argv2[MAX_ARGS-2] = NULL;
		}
		argv2[MAX_ARGS-1] = NULL;

		char *newargs = new char[8*1024];
		memset(newargs, 0, 8*1024);
		sprintf(newargs,"./%s",argv2[0]);
		for(int i=1; i<MAX_ARGS-1; i++){
			if(argv2[i]){
				strcat(newargs," ");
				strcat(newargs,argv2[i]);
			}
		}
		
		system(newargs);
		//if(execv("texturetool", argv2)<0){
		//	usage();
		//	return -1;
		//}
		delete newargs;
		//printf("\nHere %d\n",gFsize);

		if(!readPNG(gPNGFileName)){
			usage();
			return -1;
		}
		
		wf = fopen(gPVRFileName, "wb");
		if(!wf){
			printf("\nCannot open file %s\n\n",gPVRFileName);
			return -1;
		}
#endif
		rf = fopen(TEMP_OUTPUT_FILE, "rb");
		if(!rf){
			printf("\nCannot open file %s\n\n",TEMP_OUTPUT_FILE);
			return -1;
		}
		fseek(rf,0,SEEK_END);
		gFsize = ftell(rf);
		//printf("\nHere %d\n",gFsize);
		fseek(rf,0,SEEK_SET);
		char *filedata = new char[gFsize];
		fread(filedata,1,gFsize,rf);
		fclose(rf);

		writePvr(wf);
		fwrite(filedata,1,gFsize,wf);
		fclose(wf);
		delete filedata;

		return 0;

	}
	usage();

    return -1;
}
Пример #13
0
Terrain::
Terrain(string heightMapName):
	COMPONENTS(3),
	width(0),
	height(0),
	heightMap(heightMapName.c_str()),
	_indexCount(0),
	 vertices(),
	 coords(),
	 normals()
{
	width = heightMap.get_width();
	height = heightMap.get_height();

   const unsigned VERTICES_PER_ROW = width;
   const unsigned VERTICES_PER_COL = height;
	
	readPNG();
	
	for(int i =0; i < 20; i++)
	{
		smoothVertices();
	}
	
   _vertexCount = (GLsizei)VERTICES_PER_ROW * (GLsizei)VERTICES_PER_COL;

   const unsigned VERTEX_COMPONENT_COUNT = 3;
   const unsigned VERTEX_ARRAY_SIZE = (unsigned)_vertexCount *
      VERTEX_COMPONENT_COUNT;
   float* vertices = new float[VERTEX_ARRAY_SIZE];
   normals = new float[VERTEX_ARRAY_SIZE];
	
   float* uv = new float [_vertexCount  * 2];

   const unsigned SQUARES = height * width;
   const unsigned TRIANGLES_PER_SQUARE = 2;
   const unsigned VERTICES_PER_TRIANGLE = 3;
   const unsigned VERTICES_PER_SQUARE = TRIANGLES_PER_SQUARE * 
      VERTICES_PER_TRIANGLE;
   _indexCount = (GLsizei)VERTICES_PER_SQUARE * (GLsizei)SQUARES;

   const unsigned INDEX_ARRAY_SIZE = (unsigned)_indexCount;
   GLuint* indices = new GLuint[INDEX_ARRAY_SIZE];
   GLuint* uvIndices = new GLuint[_indexCount];
   
   cout << "width: " << width << endl;
   cout << "height: " << height << endl; 
   int count = 0;

	
   coords = new float[2760 * 3];
   
   unsigned index = 0;
   unsigned index2 = 0;
   unsigned uvIndex = 0;
   for (unsigned z = 0; z < VERTICES_PER_COL; z++)
   {
      const float Z = (float)z * Z_DELTA;

      for (unsigned x = 0; x < VERTICES_PER_ROW; x++)
      {
         const float X = (float)x * X_DELTA;

	vertices[index++] = X;
	//cout << "Height: " << ((float)heightMap.get_pixel(x, z).red / 255.0f) * 250.0f;;
        // vertices[index++] =  ((float)heightMap.get_pixel(x, z).red / width) * 500.0f;
	vertices[index++] =  heights[x][z];
	vertices[index++] = Z;
	
		if(x < 60 && x > 20 && z > 160 && z < 230 && heights[x][z] > 10.0f)
		{
			count ++;
			cout << "(" << X << "," << heights[x][z] << "," << Z << ")" << endl;
			coords[index2++] = X;
			coords[index2++] = heights[x][z];
			coords[index2++] = Z;
		}
	uv[uvIndex++] = 1.0f/width * x;
	uv[uvIndex++] = 1.0f/height * z;
      }
   }
   cout << "Count: " << count << endl;
 //  int size = (sizeof(vertices)/sizeof(*float));
 //  cout << "Size of vertices: " << size << endl;
   
   index = 0;
   uvIndex = 0;
   for (unsigned z = 0; z < VERTICES_PER_COL - 1; z++)
   {
      for (unsigned x = 0; x < VERTICES_PER_ROW - 1; x++)
      {
         unsigned i = z * VERTICES_PER_COL + x;

         /* Top left square. */
         indices[index++] = i;
         indices[index++] = i + VERTICES_PER_ROW;
         indices[index++] = i + 1;

         /* Bottom right square. */
         indices[index++] = i + 1;
         indices[index++] = i + VERTICES_PER_ROW;
         indices[index++] = i + 1 + VERTICES_PER_ROW;
	      
	      /* Top left square. */
	uvIndices[uvIndex++] = i;
	uvIndices[uvIndex++] = i + VERTICES_PER_ROW;
	uvIndices[uvIndex++] = i + 1;

         /* Bottom right square. */
	uvIndices[uvIndex++] = i + 1;
	uvIndices[uvIndex++] = i + VERTICES_PER_ROW;
	uvIndices[uvIndex++] = i + 1 + VERTICES_PER_ROW;
      }
   }

   smoothNormals(vertices);
   
   bind();

   GLuint buffers[6];
   glGenBuffers(6, buffers);

   glBindBuffer(GL_ARRAY_BUFFER, buffers[0]);
   glBufferData(GL_ARRAY_BUFFER, VERTEX_ARRAY_SIZE * (GLsizei)sizeof(float),
         vertices, GL_STATIC_DRAW);

   glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[1]);
   glBufferData(GL_ELEMENT_ARRAY_BUFFER, INDEX_ARRAY_SIZE * (GLsizei)sizeof(GLuint),
         indices, GL_STATIC_DRAW);

   GLuint positionLocation = findAttribute("position");
   glEnableVertexAttribArray(positionLocation);
   glVertexAttribPointer(positionLocation, VERTEX_COMPONENT_COUNT, GL_FLOAT,
         GL_FALSE, 0, 0);
   
   
    glBindBuffer(GL_ARRAY_BUFFER, buffers[2]);
   glBufferData(GL_ARRAY_BUFFER, VERTEX_ARRAY_SIZE * (GLsizei)sizeof(float),
         normals, GL_STATIC_DRAW);

   glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[3]);
   glBufferData(GL_ELEMENT_ARRAY_BUFFER, INDEX_ARRAY_SIZE * (GLsizei)sizeof(GLuint),
         indices, GL_STATIC_DRAW);

   GLuint normalsLocation = findAttribute("normals");
   glEnableVertexAttribArray(normalsLocation);
   glVertexAttribPointer(normalsLocation, VERTEX_COMPONENT_COUNT, GL_FLOAT,
         GL_FALSE, 0, 0);
	 
   glBindBuffer(GL_ARRAY_BUFFER, buffers[4]);
   glBufferData(GL_ARRAY_BUFFER, _vertexCount  * 2 * (GLsizei)sizeof(float),
         uv, GL_STATIC_DRAW);

   glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[5]);
   glBufferData(GL_ELEMENT_ARRAY_BUFFER, INDEX_ARRAY_SIZE * (GLsizei)sizeof(GLuint),
	uvIndices, GL_STATIC_DRAW);

   GLuint uvLocation = findAttribute("uv");
   glEnableVertexAttribArray(uvLocation);
   glVertexAttribPointer(uvLocation, 2, GL_FLOAT,
         GL_FALSE, 0, 0);
}