⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dvbsubpicture.java

📁 优秀的MPEG2-TS流分析软件
💻 JAVA
📖 第 1 页 / 共 3 页
字号:

			int character_code;
			String str = "";

			for (int i=0; i < number_of_codes; i++)
				str += (char)(character_code = getBits(16));

			addBigMessage("chars: " + str);

			paintStringObjects(region.getX(0), region.getY(), str);
		}
	}

	private void pixel_block()
	{
		int data_type = getBits(8);

		if (data_type == 0x10)
		{
			while (pixel_code_string_2bit() > 0)
			{}

			alignToByte(); // flush 2 bits if not aligned
		}

		else if (data_type == 0x11)
		{
			while (pixel_code_string_4bit() > 0)
			{}

			alignToByte(); //flush 4 bits if not aligned
		}

		else if (data_type == 0x12)
		{
			while (pixel_code_string_8bit() > 0)
			{}
		}

		else if (data_type == 0x20)
			for (int a=0; a<4; a++) //getBits(16) = 4 entries
				object.setMapTable_2to4bit( a, getBits(4));

		else if (data_type == 0x21)
			for (int a=0; a<4; a++) //getBits(32) = 4 entries
				object.setMapTable_2to8bit( a, getBits(8));

		else if (data_type == 0x22)
			for (int a=0; a<16; a++)  //getBits(128) = 16 entries
				object.setMapTable_4to8bit( a, getBits(8));

		else if (data_type == 0xF0)
		{
			if (object.getCopyTopFieldFlag())
				paintCopiedField(region.getX(0), region.getY() + 1, region.getWidth());

			region.nextLine();
		}
	}

	private int pixel_code_string_2bit()
	{
		if (nextBits(2) != 0)
			paintPixelLine(region.getX(1), region.getY(), 1, getBits(2), 2);

		else
		{
			flushBits(2);

			if (getBits(1) == 1)  //switch_1
			{
				int run_length_3to10 = getBits(3) + 3; //pixel_len + 3
				paintPixelLine(region.getX(run_length_3to10), region.getY(), run_length_3to10, getBits(2), 2);
			}
			else
			{
				int switch_2 = getBits(1);

				if (switch_2 == 1)
					paintPixelLine(region.getX(1), region.getY(), 1, 0, 2);

				else if (switch_2 == 0)
				{
					int switch_3 = getBits(2);

					if (switch_3 == 0)
					 	return 0; // end_of_string_signal = 0

					else if (switch_3 == 1)
						paintPixelLine(region.getX(2), region.getY(), 2, 0, 2);

					else if (switch_3 == 2)
					{
						int run_length_12to27 = getBits(4) + 12; //pixel_len + 29
						paintPixelLine(region.getX(run_length_12to27), region.getY(), run_length_12to27, getBits(2), 2);
					}

					else if (switch_3 == 3)
					{
						int run_length_29to284 = getBits(8) + 29;  //pixel_len + 29
						paintPixelLine(region.getX(run_length_29to284), region.getY(), run_length_29to284, getBits(2), 2);
					}
				}
			}
		}

		return 1;
	}


	private int pixel_code_string_4bit()
	{
		if (nextBits(4) != 0) //1 pixel of color enry 1..15
			paintPixelLine(region.getX(1), region.getY(), 1, getBits(4), 4);

		else
		{
			flushBits(4);

			if (getBits(1) == 0)  //switch_1
			{
				if (nextBits(3) != 0)
				{
					int run_length_3to9 = getBits(3) + 2; //pixel_len + 2
					paintPixelLine(region.getX(run_length_3to9), region.getY(), run_length_3to9, 0, 4);
				}
				else
					return getBits(3); // end_of_string_signal = 0
			}
			else
			{
				if (getBits(1) == 0) //switch_2
				{
					int run_length_4to7 = getBits(2) + 4; //pixel_len + 4
					paintPixelLine(region.getX(run_length_4to7), region.getY(), run_length_4to7, getBits(4), 4);
				}
				else
				{
					int switch_3 = getBits(2);

					if (switch_3 < 2)
					{
						int run_length_1to2 = switch_3 + 1; //pixel_len (1 or 2)
						paintPixelLine(region.getX(run_length_1to2), region.getY(), run_length_1to2, 0, 4);
					}

					else if (switch_3 == 2)
					{
						int run_length_9to24 = getBits(4) + 9; //pixel_len + 9
						paintPixelLine(region.getX(run_length_9to24), region.getY(), run_length_9to24, getBits(4), 4);
					}

					else if (switch_3 == 3)
					{
						int run_length_25to280 = getBits(8) + 25; //pixel_len + 25
						paintPixelLine(region.getX(run_length_25to280), region.getY(), run_length_25to280, getBits(4), 4);
					}
				}
			}
		}

		return 1;
	}

	private int pixel_code_string_8bit()
	{
		int pixel_code_8bit;

		if (nextBits(8) != 0)
			paintPixelLine(region.getX(1), region.getY(), 1, getBits(8), 8);

		else
		{
			flushBits(8);

			if (getBits(1) == 0) //switch_1
			{
				if (nextBits(7) != 0)
				{
					int run_length_1to127 = getBits(7); //pixel_len 
					paintPixelLine(region.getX(run_length_1to127), region.getY(), run_length_1to127, 0, 8);
				}
				else
					return getBits(7); //end_of_string_signal = 0
			}
			else
			{
				int run_length_3to127 = getBits(7); //pixel_len with colorindex in next 8bits
				paintPixelLine(region.getX(run_length_3to127), region.getY(), run_length_3to127, getBits(8), 8);
			}
		}

		return 1;
	}

	private int YUVtoRGB(int Y, int Cr, int Cb, int T)
	{
		if (Y == 0)
			return 0;

		int R = (int)((float)Y +1.402f * (Cr-128));
		int G = (int)((float)Y -0.34414 * (Cb-128) -0.71414 * (Cr-128));
		int B = (int)((float)Y +1.722 * (Cb-128));
		R = R < 0 ? 0 : (R > 0xFF ? 0xFF : R);
		G = G < 0 ? 0 : (G > 0xFF ? 0xFF : G);
		B = B < 0 ? 0 : (B > 0xFF ? 0xFF : B);
		T = 0xFF - (T < 0 ? 0 : (T > 0xFF ? 0xFF : T));

		return (T<<24 | R<<16 | G<<8 | B);
	}

	private int[] generateDefaultCLUT_8Bits()
	{
		int table[] = new int[256];

		for (int i=0; i<256; i++)
			table[i] = generateClutEntry_8Bits(i);

		return table;
	}

	private int generateClutEntry_4Bits(int i)
	{
		int T, R, G, B;

		if ((i & 8) == 0)
		{
			if ((i & 7) == 0)
				T = R = G = B = 0;

			else
			{
				R = (i & 1) != 0 ? 0xFF : 0;
				G = (i & 2) != 0 ? 0xFF : 0;
				B = (i & 4) != 0 ? 0xFF : 0;
				T = 0xFF;
			}
		}
		else
		{
			R = (i & 1) != 0 ? 0x80 : 0;
			G = (i & 2) != 0 ? 0x80 : 0;
			B = (i & 4) != 0 ? 0x80 : 0;
			T = 0xFF;
		}

		return (T<<24 | R<<16 | G<<8 | B);
	}

	private int generateClutEntry_8Bits(int i)
	{
		int T=0, R=0, G=0, B=0;

		if ((i & 0x88) == 0)
		{
			if ((i & 0x70) == 0)
			{
				if ((i & 7) == 0)
					T = R = G = B = 0;

				else
				{
					R = (i & 1) != 0 ? 0xFF : 0;
					G = (i & 2) != 0 ? 0xFF : 0;
					B = (i & 4) != 0 ? 0xFF : 0;
					T = 0x40;
				}
			}
			else
			{
				R = ((i & 1) != 0 ? 0x55 : 0) + ((i & 0x10) != 0 ? 0xAA : 0);
				G = ((i & 2) != 0 ? 0x55 : 0) + ((i & 0x20) != 0 ? 0xAA : 0);
				B = ((i & 4) != 0 ? 0x55 : 0) + ((i & 0x40) != 0 ? 0xAA : 0);
				T = 0xFF;
			}
		}

		else if ((i & 0x88) == 8)
		{
			R = ((i & 1) != 0 ? 0x55 : 0) + ((i & 0x10) != 0 ? 0xAA : 0);
			G = ((i & 2) != 0 ? 0x55 : 0) + ((i & 0x20) != 0 ? 0xAA : 0);
			B = ((i & 4) != 0 ? 0x55 : 0) + ((i & 0x40) != 0 ? 0xAA : 0);
			T = 0x80;
		}

		else if ((i & 0x88) == 0x80)
		{
			R = ((i & 1) != 0 ? 0x2A : 0) + ((i & 0x10) != 0 ? 0x55 : 0) + 0x80;
			G = ((i & 2) != 0 ? 0x2A : 0) + ((i & 0x20) != 0 ? 0x55 : 0) + 0x80;
			B = ((i & 4) != 0 ? 0x2A : 0) + ((i & 0x40) != 0 ? 0x55 : 0) + 0x80;
			T = 0xFF;
		}

		else if ((i & 0x88) == 0x88)
		{
			R = ((i & 1) != 0 ? 0x2A : 0) + ((i & 0x10) != 0 ? 0x55 : 0);
			G = ((i & 2) != 0 ? 0x2A : 0) + ((i & 0x20) != 0 ? 0x55 : 0);
			B = ((i & 4) != 0 ? 0x2A : 0) + ((i & 0x40) != 0 ? 0x55 : 0);
			T = 0xFF;
		}

		return (T<<24 | R<<16 | G<<8 | B);
	}

	private void paintRegionBackground()
	{
		if (!region.isActive() || !region.getFillFlag())
			return;

		int color;

		if (IRD == 2)
			color = clut.getCLUT_2bit()[mapColorIndex(region.getPixelCode_2bit(), 2, IRD)];

		else if (IRD == 4)
			color = clut.getCLUT_4bit()[mapColorIndex(region.getPixelCode_4bit(), 4, IRD)];

		else
			color = clut.getCLUT_8bit()[mapColorIndex(region.getPixelCode_8bit(), 8, IRD)];

		color = scaleRGB(color);

		java.util.Arrays.fill(pixel_data, color);
	}

	// 
	private void paintRegionBorder(int x, int y, int w, int h)
	{
		big.setColor(Color.white);
		big.drawRect( x -1, y -1, w +2, h +1);
		big.drawString("x" + x + ", y" + y + " / " + w + "*" + h, x , y - 6);
	}

	// only for painted preview picture, else not necessary
	private void clearBackground()
	{
		java.util.Arrays.fill(preview_pixel_data, 0x60);

		big.setColor( new Color(0, 0, 0x60));   //deep blue to see full transparency
		big.fillRect( bimg.getMinX(), bimg.getMinY(), bimg.getWidth(), bimg.getHeight());
	}

	private void paintPixelLine(int x, int y, int w, int color_index, int depth)
	{
		x += object.getHorizontalPosition();
		y += object.getVerticalPosition();

		int color = 0, color_model = IRD;

		color_index = mapColorIndex(color_index, depth, IRD);

		if (clut.getModifyFlags() > 0 && (clut.getModifyFlags() & IRD) == 0) //remap if no alternative color def.
		{
			color_index = mapColorIndex(color_index, IRD, depth);
			color_model = depth;
		}

		if (color_model == 2)
			color = clut.getCLUT_2bit()[color_index];

		else if (color_model == 4)
			color = clut.getCLUT_4bit()[color_index];

		else
			color = clut.getCLUT_8bit()[color_index];

		color = scaleRGB(color);

		if ((0xFF000000 & color) == 0) //keep underlying pixel if new pixel is full transparent
			return;

		//DM23062004 081.7 int05 add
		if (x > region.getWidth() - 1 || y > region.getHeight() - 1)
		{
			region.setError(2);
			return;
		}

		from_index = x + y * region.getWidth();
		to_index = from_index + w;

		//DM23062004 081.7 int05 add
		if (x + w > region.getWidth())
		{
			to_index = from_index + region.getWidth() - x;
			region.setError(1);
		}

		java.util.Arrays.fill(pixel_data, from_index, to_index, color);
	}

	// not yet exported, only info for existence
	private void paintStringObjects(int x, int y, String str)
	{
		x += object.getHorizontalPosition();
		y += object.getVerticalPosition();

		big.setColor(Color.cyan);
		big.drawString(str, x , y + 26);
	}

	private void paintCopiedField(int x, int y, int w)
	{
		System.arraycopy(pixel_data, x + y * w, pixel_data, x + (y + 1) * w, w);
	}

	private int scaleRGB(int ARGB)
	{
		if ((ARGB & 0xFF000000) == 0)  //deep blue to see full transparency
			return 0x60;

		int R = 15 + (0xFF & ARGB>>>16);
		int G = 15 + (0xFF & ARGB>>>8);
		int B = 15 + (0xFF & ARGB);

		R = R > 0xEB ? 0xEB : R;
		G = G > 0xEB ? 0xEB : G;
		B = B > 0xEB ? 0xEB : B;

		// color float scale 16..235 for RGB
		//int R = 16 + (int)(0.85546875f * (0xFF & ARGB>>>16));
		//int G = 16 + (int)(0.85546875f * (0xFF & ARGB>>>8));
		//int B = 16 + (int)(0.85546875f * (0xFF & ARGB));

		int T = 0xFF & ARGB>>>24;

		return (T<<24 | R<<16 | G<<8 | B);
	}	

	private int mapColorIndex(int color_index, int depth, int new_depth)  // depth is 2,4,8!
	{
		switch (new_depth)
		{
		case 2:
			if (depth == 8)
				color_index >>>= 4;

			if (depth > 2)
				color_index = (2 & color_index>>>2) | (1 & color_index>>>2) | (1 & color_index>>>1) | (1 & color_index);

			break;

		case 4:
			if (depth == 2)
				color_index = (object != null) ? object.getMapTable_2to4bit()[color_index] : color_index;

			else if (depth == 8)
				color_index >>>= 4;

			break;

		case 8:
			if (depth == 2)
				color_index = (object != null) ? object.getMapTable_2to8bit()[color_index] : color_index;

			else if (depth == 4)
				color_index = (object != null) ? object.getMapTable_4to8bit()[color_index] : color_index;
		}

		return color_index;
	}

	//DM13062004 081.7 int04 add
	private void setUserClut()
	{
		int model = Integer.parseInt(user_table.get("model").toString().trim());
		int max_indices = model > 2 ? (model > 4 ? 256 : 16) : 4;

		if (region.getDepth() < model)
			max_indices = region.getDepth();

		for (int i = 0; i < max_indices; i++)
		{
			if (user_table.containsKey("" + i))
			{
				addBigMessage("addUserClut: " + i + " /ARGB " + user_table.get("" + i));

				clut.setClutEntry(mapColorIndex(i, region.getDepth(), model), model, (int)Long.parseLong(user_table.get("" + i).toString().trim(), 16));
			}
		}
	}


	private Epoch setEpoch(int epoch_id)
	{
		String epoch_id_str = "" + epoch_id;

		if ( !epoches.containsKey(epoch_id_str) )
			epoches.put(epoch_id_str, new Epoch(epoch_id) );

		return (Epoch)epoches.get(epoch_id_str);
	}


	class Epoch
	{
		private int id;

		private Hashtable pages = new Hashtable();
		private Hashtable cluts = new Hashtable();
		private Hashtable regions = new Hashtable();
		private Hashtable objects = new Hashtable();

		private Epoch()
		{}

		private Epoch(int val)
		{
			id = val;
		}

		private void setId(int val)
		{
			id = val;
		}

		private int getId()
		{
			return id;
		}

		private Page setPage(int page_id)
		{
			String page_id_str = "" + page_id;

			if ( !pages.containsKey(page_id_str) )
				pages.put(page_id_str, new Page(page_id) );

			return (Page)pages.get(page_id_str);
		}

		private Page newPage(int page_id)
		{
			String page_id_str = "" + page_id;

			pages.put(page_id_str, new Page(page_id) );

			return (Page)pages.get(page_id_str);
		}

		private Region setRegion(int region_id)
		{
			String region_id_str = "" + region_id;

			if (!regions.containsKey(region_id_str) )
				regions.put(region_id_str, new Region(region_id) );

			return (Region)regions.get(region_id_str);
		}

		private CLUT setCLUT(int CLUT_id)
		{
			String CLUT_id_str = "" + CLUT_id;

			if ( !cluts.containsKey(CLUT_id_str) )
				cluts.put(CLUT_id_str, new CLUT(CLUT_id) );

			return (CLUT)cluts.get(CLUT_id_str);
		}

		private OBJECT setObject(int object_id)
		{
			String object_id_str = "" + object_id;

			if ( !objects.containsKey(object_id_str) )
				objects.put(object_id_str, new OBJECT(object_id) );

			return (OBJECT)objects.get(object_id_str);
		}

		private void clearRegions()
		{
			for (Enumeration e = regions.keys(); e.hasMoreElements() ; )
				((Region)regions.get(e.nextElement().toString())).setActive(false);
		}

		private Enumeration getRegions()
		{
			return regions.keys();
		}

		private void clearObjects()
		{
				objects.clear();
		}
	}


	class Page
	{
		private int id;
		private int version_number = -1;
		private long time_in = 0;
		private int time_out = 0;
		private int state;
		private int minX = 720, minY = 576, maxX = 0, maxY = 0;
		private int pixel[];
		private boolean write = false;

		private Page()
		{}

		private Page(int val)
		{
			id = val;
		}

		private void setId(int val)
		{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -