Translate

improved it by doubling the horizontal resolution and enabling the display of RGB images in Termux.

Referring to a project on GitHub that implements similar functionality using RUST (https://github.com/nabijaczleweli/termimage), I have improved it by doubling the horizontal resolution and enabling the display of RGB images in Termux.


	void printMatrixC()
	{
		// Allocate memory for the output buffer
		char *output = (char *)malloc((getWidth() + 1) * getHeight() * 16 * sizeof(char)); // Width + 1 to include the newline character

		// Build the output buffer
		char *p = output;
			for (int y = 0; y < getHeight(); y+=2)
		{
			for (int x = 0; x < getWidth(); x++)
			{
				//Point2D point = {(double)x, (double)y};
				unsigned char value = get(x, y);

				// Choose the background color based on the value
				int backgroundColor = (int)value;

				// Set the background color and print a space
				p += sprintf(p, "\033[48;5;%dm ", backgroundColor);
			}
			p += sprintf(p, "\033[0m\n");
		}

		// Print the output buffer and free memory
		printf("%s", output);
		free(output);
	}
	

	void printMatrix()
	{
		float avg=0;
		float maxC=0;
		float minC=256;
		for (int i=0;i<height*width;i++) {
			int c=array[i];
		//	float rgb=colorMap[c][0]+colorMap[c][1]+colorMap[c][2];
		float rgb=colorMap[c][0]*0.299+colorMap[c][1]*0.587+colorMap[c][2]*0.114;
			avg+=rgb;
			if (rgb>=maxC) maxC=rgb;
			if (rgb<=minC) minC=rgb;
			
		}
		   avg=avg/height/width;
		   maxC=maxC-minC;
		   //maxC=232*3;
			for (int y = 0; y < getHeight(); y+=2)
		{
			for (int x = 0; x < getWidth(); x++)
			{
				//Point2D point = {(double)x, (double)y};
				unsigned char value = get(x, y);
				//Y = 0.299 R + 0.587 G + 0.114 B
			//	float rgb=colorMap[value][0]+colorMap[value][1]+colorMap[value][2];
		float rgb=16+colorMap[value][0]*0.299+colorMap[value][1]*0.587+colorMap[value][2]*0.114;
				
			//	if (value>=avg*3)printf("@@");
if (value>=minC+maxC*30/32)printf("§");
else if (value>=minC+maxC*29/32)printf("€");
else if (value>=minC+maxC*29/32)printf("¥");
else if (value>=minC+maxC*28/32)printf("@");
else if (value>=minC+maxC*27/32)printf("&");
else if (value>=minC+maxC*27/32)printf("¥");
else if (value>=minC+maxC*26/32)printf("$");
else if (value>=minC+maxC*25/32)printf("#");
else if (value>=minC+maxC*24/32)printf("W");
else if (value>=minC+maxC*23/32)printf("B");
else if (value>=minC+maxC*22/32)printf("G");
else if (value>=minC+maxC*21/32)printf("R");
else if (value>=minC+maxC*20/32)printf("N");
else if (value>=minC+maxC*19/32)printf("F");
else if (value>=minC+maxC*18/32)printf("H");
else if (value>=minC+maxC*17/32)printf("K");
else if (value>=minC+maxC*16/32)printf("N");
else if (value>=minC+maxC*15/32)printf("U");
else if (value>=minC+maxC*14/32)printf("V");
else if (value>=minC+maxC*13/32)printf("L");
else if (value>=minC+maxC*12/32)printf("J");
else if (value>=minC+maxC*11/32)printf("O");
else if (value>=minC+maxC*10/32)printf("C");
else if (value>=minC+maxC*9/32)printf("I");
else if (value>=minC+maxC*8/32)printf("i");
else if (value>=minC+maxC*7/32)printf("-");
else if (value>=minC+maxC*6/32)printf(";");
else if (value>=minC+maxC*5/32)printf(":");
else if (value>=minC+maxC*4/32)printf(".");
else if (value>=minC+maxC*3/32)printf(" ");
else if (value>=minC+maxC*2/32)printf(" ");
else printf(" ");
			}
			printf("\n");
		}
		return;
	}


//RGB:



void printMatrixC()
	{
		// Allocate memory for the output buffer
		char *output = (char *)malloc((getWidth() + 1) * getHeight() * 24 * sizeof(char)); // Width + 1 to include the newline character

		// Build the output buffer
		char *p = output;
		for (int y = 0; y < getHeight(); y+=2)
		{
			for (int x = 0; x < getWidth(); x++)
			{
				//Point2D point = {(double)x, (double)y};
				Color bg = getPoint({(double)x,(double)y});

				// Choose the background color based on the value

				// Set the background color and print a space
				p += sprintf(p, "\033[48;2;%d;%d;%dm ", bg.r,bg.g,bg.b);
			}
			p += sprintf(p, "\033[0m\n");
		}

		// Print the output buffer and free memory
		printf("%s", output);
		free(output);
	}

沒有留言:

發佈留言