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

📄 jpegfileformat.java

📁 源码为Eclipse开源开发平台桌面开发工具SWT的源代码,
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
	for (int row = 0; row < 8; row++) {		int rIndex = row * DCTSIZE;		int tmp0 = dataUnit[rIndex] + dataUnit[rIndex + 7];		int tmp7 = dataUnit[rIndex] - dataUnit[rIndex + 7];		int tmp1 = dataUnit[rIndex + 1] + dataUnit[rIndex + 6];		int tmp6 = dataUnit[rIndex + 1] - dataUnit[rIndex + 6];		int tmp2 = dataUnit[rIndex + 2] + dataUnit[rIndex + 5];		int tmp5 = dataUnit[rIndex + 2] - dataUnit[rIndex + 5];		int tmp3 = dataUnit[rIndex + 3] + dataUnit[rIndex + 4];		int tmp4 = dataUnit[rIndex + 3] - dataUnit[rIndex + 4];		/**		 * Even part per LL&M figure 1 --- note that published figure 		 * is faulty; rotator 'sqrt(2)*c1' should be 'sqrt(2)*c6'.		 */		int tmp10 = tmp0 + tmp3;		int tmp13 = tmp0 - tmp3;		int tmp11 = tmp1 + tmp2;		int tmp12 = tmp1 - tmp2;		dataUnit[rIndex] = (tmp10 + tmp11) * 4;		dataUnit[rIndex + 4]  = (tmp10 - tmp11) * 4;		int z1 = (tmp12 + tmp13) * FIX_0_541196100;		int scaleFactor1 = ExtendTest[11];		int scaleFactor2 = ExtendTest[12];		int n = z1 + (tmp13 * FIX_0_765366865) + scaleFactor1;		dataUnit[rIndex + 2] = n / scaleFactor2;		if ((n < 0) && (n % scaleFactor2 != 0)) dataUnit[rIndex + 2]--;		n = z1 + (tmp12 * (0 - FIX_1_847759065)) + scaleFactor1; 		dataUnit[rIndex + 6] = n / scaleFactor2;		if ((n < 0) && (n % scaleFactor2 != 0)) dataUnit[rIndex + 6]--;		/**		 * Odd part per figure 8 --- note paper omits factor of sqrt(2).		 * cK represents cos(K*pi/16).		 * i0..i3 in the paper are tmp4..tmp7 here.		 */		z1 = tmp4 + tmp7;		int z2 = tmp5 + tmp6;		int z3 = tmp4 + tmp6;		int z4 = tmp5 + tmp7;		int z5 = (z3 + z4) * FIX_1_175875602;	// sqrt(2) * c3		tmp4 = tmp4 * FIX_0_298631336;	// sqrt(2) * (-c1+c3+c5-c7)		tmp5 = tmp5 * FIX_2_053119869;	// sqrt(2) * ( c1+c3-c5+c7)		tmp6 = tmp6 * FIX_3_072711026;	// sqrt(2) * ( c1+c3+c5-c7)		tmp7 = tmp7 * FIX_1_501321110;	// sqrt(2) * ( c1+c3-c5-c7)		z1 = z1 * (0 - FIX_0_899976223);	// sqrt(2) * (c7-c3)		z2 = z2 * (0 - FIX_2_562915447);	// sqrt(2) * (-c1-c3)		z3 = z3 * (0 - FIX_1_961570560);	// sqrt(2) * (-c3-c5)		z4 = z4 * (0 - FIX_0_390180644);	// sqrt(2) * (c5-c3)		z3 = z3 + z5;		z4 = z4 + z5;		n = tmp4 + z1 + z3 + scaleFactor1;		dataUnit[rIndex + 7] = n / scaleFactor2;		if ((n < 0) && (n % scaleFactor2 != 0)) dataUnit[rIndex + 7]--;		n = tmp5 + z2 + z4 + scaleFactor1;		dataUnit[rIndex + 5] = n / scaleFactor2;		if ((n < 0) && (n % scaleFactor2 != 0)) dataUnit[rIndex + 5]--;		n = tmp6 + z2 + z3 + scaleFactor1;		dataUnit[rIndex + 3] = n / scaleFactor2;		if ((n < 0) && (n % scaleFactor2 != 0)) dataUnit[rIndex + 3]--;		n = tmp7 + z1 + z4 + scaleFactor1;		dataUnit[rIndex + 1] = n / scaleFactor2;		if ((n < 0) && (n % scaleFactor2 != 0)) dataUnit[rIndex + 1]--;	}	/**	 * Pass 2: process columns.	 * Note that we must descale the results by a factor of 8 == 2**3,	 * and also undo the PASS1_BITS scaling.	 */	for (int col = 0; col < 8; col++) {		int c0 = col;		int c1 = col + 8;		int c2 = col + 16;		int c3 = col + 24;		int c4 = col + 32;		int c5 = col + 40;		int c6 = col + 48;		int c7 = col + 56;		int tmp0 = dataUnit[c0] + dataUnit[c7];		int tmp7 = dataUnit[c0] - dataUnit[c7];		int tmp1 = dataUnit[c1] + dataUnit[c6];		int tmp6 = dataUnit[c1] - dataUnit[c6];		int tmp2 = dataUnit[c2] + dataUnit[c5];		int tmp5 = dataUnit[c2] - dataUnit[c5];		int tmp3 = dataUnit[c3] + dataUnit[c4];		int tmp4 = dataUnit[c3] - dataUnit[c4];		/**		 * Even part per LL&M figure 1 --- note that published figure 		 * is faulty; rotator 'sqrt(2)*c1' should be 'sqrt(2)*c6'.		 */		int tmp10 = tmp0 + tmp3;		int tmp13 = tmp0 - tmp3;		int tmp11 = tmp1 + tmp2;		int tmp12 = tmp1 - tmp2;		int scaleFactor1 = ExtendTest[5];		int scaleFactor2 = ExtendTest[6];		int n = tmp10 + tmp11 + scaleFactor1;		dataUnit[c0] = n / scaleFactor2;		if ((n < 0) && (n % scaleFactor2 != 0)) dataUnit[c0]--;		n = tmp10 - tmp11 + scaleFactor1;		dataUnit[c4] = n / scaleFactor2;		if ((n < 0) && (n % scaleFactor2 != 0)) dataUnit[c4]--;		int z1 = (tmp12 + tmp13) * FIX_0_541196100;		scaleFactor1 = ExtendTest[18];		scaleFactor2 = ExtendTest[19];		n = z1 + (tmp13 * FIX_0_765366865) + scaleFactor1;		dataUnit[c2] = n / scaleFactor2;		if ((n < 0) && (n % scaleFactor2 != 0)) dataUnit[c2]--;		n = z1 + (tmp12 * (0 - FIX_1_847759065)) + scaleFactor1;		dataUnit[c6] = n / scaleFactor2;		if ((n < 0) && (n % scaleFactor2 != 0)) dataUnit[c6]--;		/**		 * Odd part per figure 8 --- note paper omits factor of sqrt(2).		 * cK represents cos(K*pi/16).		 * i0..i3 in the paper are tmp4..tmp7 here.		 */		z1 = tmp4 + tmp7;		int z2 = tmp5 + tmp6;		int z3 = tmp4 + tmp6;		int z4 = tmp5 + tmp7;		int z5 = (z3 + z4) * FIX_1_175875602;	// sqrt(2) * c3		tmp4 = tmp4 * FIX_0_298631336;	// sqrt(2) * (-c1+c3+c5-c7)		tmp5 = tmp5 * FIX_2_053119869;	// sqrt(2) * ( c1+c3-c5+c7)		tmp6 = tmp6 * FIX_3_072711026;	// sqrt(2) * ( c1+c3+c5-c7)		tmp7 = tmp7 * FIX_1_501321110;	// sqrt(2) * ( c1+c3-c5-c7)		z1 = z1 * (0 - FIX_0_899976223);	// sqrt(2) * (c7-c3)		z2 = z2 * (0 - FIX_2_562915447);	// sqrt(2) * (-c1-c3)		z3 = z3 * (0 - FIX_1_961570560);	// sqrt(2) * (-c3-c5)		z4 = z4 * (0 - FIX_0_390180644);	// sqrt(2) * (c5-c3)		z3 = z3 + z5;		z4 = z4 + z5;		n = tmp4 + z1 + z3 + scaleFactor1;		dataUnit[c7] = n / scaleFactor2;		if ((n < 0) && (n % scaleFactor2 != 0)) dataUnit[c7]--;		n = tmp5 + z2 + z4 + scaleFactor1;		dataUnit[c5] = n / scaleFactor2;		if ((n < 0) && (n % scaleFactor2 != 0)) dataUnit[c5]--;		n = tmp6 + z2 + z3 + scaleFactor1;		dataUnit[c3] = n / scaleFactor2;		if ((n < 0) && (n % scaleFactor2 != 0)) dataUnit[c3]--;		n = tmp7 + z1 + z4 + scaleFactor1;		dataUnit[c1] = n / scaleFactor2;		if ((n < 0) && (n % scaleFactor2 != 0)) dataUnit[c1]--;	}}void getAPP0() {	JPEGAppn appn = new JPEGAppn(inputStream);	if (!appn.verify()) {		SWT.error(SWT.ERROR_INVALID_IMAGE);	}}void getCOM() {	new JPEGComment(inputStream);}void getDAC() {	JPEGArithmeticConditioningTable dac = new JPEGArithmeticConditioningTable(inputStream);	arithmeticTables = dac;}void getDHT() {	JPEGHuffmanTable dht = new JPEGHuffmanTable(inputStream);	if (!dht.verify()) {		SWT.error(SWT.ERROR_INVALID_IMAGE);	}	if (acHuffmanTables == null) {		acHuffmanTables = new JPEGHuffmanTable[4];	}	if (dcHuffmanTables == null) {		dcHuffmanTables = new JPEGHuffmanTable[4];	}	JPEGHuffmanTable[] dhtTables = dht.getAllTables();	for (int i = 0; i < dhtTables.length; i++) {		JPEGHuffmanTable dhtTable = dhtTables[i];		if (dhtTable.getTableClass() == 0) {			dcHuffmanTables[dhtTable.getTableIdentifier()] = dhtTable;		} else {			acHuffmanTables[dhtTable.getTableIdentifier()] = dhtTable;		}	}}void getDNL() {	new JPEGRestartInterval(inputStream);}void getDQT() {	JPEGQuantizationTable dqt = new JPEGQuantizationTable(inputStream);	int[][] currentTables = quantizationTables;	if (currentTables == null) {		currentTables = new int[4][];	}	int[] dqtTablesKeys = dqt.getQuantizationTablesKeys();	int[][] dqtTablesValues = dqt.getQuantizationTablesValues();	for (int i = 0; i < dqtTablesKeys.length; i++) {		int index = dqtTablesKeys[i];		currentTables[index] = dqtTablesValues[i];	}	quantizationTables = currentTables;}void getDRI() {	JPEGRestartInterval dri = new JPEGRestartInterval(inputStream);	if (!dri.verify()) {		SWT.error(SWT.ERROR_INVALID_IMAGE);	}	restartInterval = dri.getRestartInterval();}static void initialize() {	initializeRGBYCbCrTables();	initializeYCbCrRGBTables();	initializeBitCountTable();}static void initializeBitCountTable() {	int nBits = 1;	int power2 = 2;	NBitsTable = new int[2048];	NBitsTable[0] = 0;	for (int i = 1; i < NBitsTable.length; i++) {		if (!(i < power2)) {			nBits++;			power2 *= 2;		}		NBitsTable[i] = nBits;	}}static void initializeRGBYCbCrTables() {	RYTable = new int[256];	GYTable = new int[256];	BYTable = new int[256];	RCbTable = new int[256];	GCbTable = new int[256];	BCbTable = new int[256];	RCrTable = BCbTable;	GCrTable = new int[256];	BCrTable = new int[256];	for (int i = 0; i < 256; i++) {		RYTable[i] = i * 19595;		GYTable[i] = i * 38470;		BYTable[i] = i * 7471 + 32768;		RCbTable[i] = i * -11059;		GCbTable[i] = i * -21709;		BCbTable[i] = i * 32768 + 8388608;		GCrTable[i] = i * -27439;		BCrTable[i] = i * -5329;	}}static void initializeYCbCrRGBTables() {	CrRTable = new int[256];	CbBTable = new int[256];	CrGTable = new int[256];	CbGTable = new int[256];	for (int i = 0; i < 256; i++) {		int x2 = 2 * i - 255;		CrRTable[i] = (45941 * x2 + 32768) / 65536;		CbBTable[i] = (58065 * x2 + 32768) / 65536;		CrGTable[i] = -23401 * x2;		CbGTable[i] = -11277 * x2 + 32768;	}}void inverseDCT(int[] dataUnit) {	for (int row = 0; row < 8; row++) {		int rIndex = row * DCTSIZE;		/**		 * Due to quantization, we will usually find that many of the input		 * coefficients are zero, especially the AC terms.  We can exploit this		 * by short-circuiting the IDCT calculation for any row in which all		 * the AC terms are zero.  In that case each output is equal to the		 * DC coefficient (with scale factor as needed).		 * With typical images and quantization tables, half or more of the		 * row DCT calculations can be simplified this way.		 */		if (isZeroInRow(dataUnit, rIndex)) {			int dcVal = dataUnit[rIndex] * 4;			for (int i = rIndex; i < rIndex + 8; i++) {				dataUnit[i] = dcVal;			}		} else {			/**			 * Even part: reverse the even part of the forward DCT.			 * The rotator is sqrt(2)*c(-6).			 */			int z2 = dataUnit[rIndex + 2];			int z3 = dataUnit[rIndex + 6];			int z1 = (z2 + z3) * FIX_0_541196100;			int tmp2 = z1 + (z3 * (0 - FIX_1_847759065));			int tmp3 = z1 + (z2 * FIX_0_765366865);			int tmp0 = (dataUnit[rIndex] + dataUnit[rIndex + 4]) * 8192;			int tmp1 = (dataUnit[rIndex] - dataUnit[rIndex + 4]) * 8192;			int tmp10 = tmp0 + tmp3;			int tmp13 = tmp0 - tmp3;			int tmp11 = tmp1 + tmp2;			int tmp12 = tmp1 - tmp2;			/**			 * Odd part per figure 8; the matrix is unitary and hence its			 * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively.			 */			tmp0 = dataUnit[rIndex + 7];			tmp1 = dataUnit[rIndex + 5];			tmp2 = dataUnit[rIndex + 3];			tmp3 = dataUnit[rIndex + 1];			z1 = tmp0 + tmp3;			z2 = tmp1 + tmp2;			z3 = tmp0 + tmp2;			int z4 = tmp1 + tmp3;			int z5 = (z3 + z4)* FIX_1_175875602; /* sqrt(2) * c3 */			  			tmp0 = tmp0 * FIX_0_298631336;		/* sqrt(2) * (-c1+c3+c5-c7) */			tmp1 = tmp1 * FIX_2_053119869;		/* sqrt(2) * ( c1+c3-c5+c7) */			tmp2 = tmp2 * FIX_3_072711026;		/* sqrt(2) * ( c1+c3+c5-c7) */			tmp3 = tmp3 * FIX_1_501321110;		/* sqrt(2) * ( c1+c3-c5-c7) */			z1 = z1 * (0 - FIX_0_899976223);	/* sqrt(2) * (c7-c3) */			z2 = z2 * (0 - FIX_2_562915447);	/* sqrt(2) * (-c1-c3) */			z3 = z3 * (0 - FIX_1_961570560);	/* sqrt(2) * (-c3-c5) */			z4 = z4 * (0 - FIX_0_390180644);	/* sqrt(2) * (c5-c3) */			z3 = z3 + z5;			z4 = z4 + z5;			tmp0 = tmp0 + z1 + z3;			tmp1 = tmp1 + z2 + z4;			tmp2 = tmp2 + z2 + z3;			tmp3 = tmp3 + z1 + z4;			int descaleFactor1 = ExtendTest[11];			int descaleFactor2 = ExtendTest[12];			dataUnit[rIndex] = (tmp10 + tmp3 + descaleFactor1) / descaleFactor2;			dataUnit[rIndex + 7] = (tmp10 - tmp3 + descaleFactor1) / descaleFactor2;			dataUnit[rIndex + 1] = (tmp11 + tmp2 + descaleFactor1) / descaleFactor2;			dataUnit[rIndex + 6] = (tmp11 - tmp2 + descaleFactor1) / descaleFactor2;			dataUnit[rIndex + 2] = (tmp12 + tmp1 + descaleFactor1) / descaleFactor2;			dataUnit[rIndex + 5] = (tmp12 - tmp1 + descaleFactor1) / descaleFactor2;			dataUnit[rIndex + 3] = (tmp13 + tmp0 + descaleFactor1) / descaleFactor2;			dataUnit[rIndex + 4] = (tmp13 - tmp0 + descaleFactor1) / descaleFactor2;		 }	}	/**	 * Pass 2: process columns.	 * Note that we must descale the results by a factor of 8 == 2**3,	 * and also undo the PASS1_BITS scaling.	 */	for (int col = 0; col < 8; col++) {		int c0 = col;		int c1 = col + 8;		int c2 = col + 16;		int c3 = col + 24;		int c4 = col + 32;		int c5 = col + 40;		int c6 = col + 48;		int c7 = col + 56;		if (isZeroInColumn(dataUnit, col)) {			int dcVal = (dataUnit[c0] + 16) / 32;			dataUnit[c0] = dcVal;			dataUnit[c1] = dcVal;			dataUnit[c2] = dcVal;			dataUnit[c3] = dcVal;			dataUnit[c4] = dcVal;			dataUnit[c5] = dcVal;			dataUnit[c6] = dcVal;			dataUnit[c7] = dcVal;		} else {			/**			 * Even part: reverse the even part of the forward DCT.			 * The rotator is sqrt(2)*c(-6).			 */			int z2 = dataUnit[c2];			int z3 = dataUnit[c6];			int z1 = (z2 + z3) * FIX_0_541196100;			int tmp2 = z1 + (z3 * (0 - FIX_1_847759065));			int tmp3 = z1 + (z2 * FIX_0_765366865);			int tmp0 = (dataUnit[c0] + dataUnit[c4]) * 8192;			int tmp1 = (dataUnit[c0] - dataUnit[c4]) * 8192;			int tmp10 = tmp0 + tmp3;			int tmp13 = tmp0 - tmp3;			int tmp11 = tmp1 + tmp2;			int tmp12 = tmp1 - tmp2;			/**			 * Odd part per figure 8; the matrix is unitary and hence its			 * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively.			 */			tmp0 = dataUnit[c7];			tmp1 = dataUnit[c5];			tmp2 = dataUnit[c3];			tmp3 = dataUnit[c1];			z1 = tmp0 + tmp3;			z2 = tmp1 + tmp2;			z3 = tmp0 + tmp2;			int z4 = tmp1 + tmp3;			int z5 = (z3 + z4) * FIX_1_175875602;	/* sqrt(2) * c3 */						tmp0 = tmp0 * FIX_0_298631336;		/* sqrt(2) * (-c1+c3+c5-c7) */			tmp1 = tmp1 * FIX_2_053119869;		/* sqrt(2) * ( c1+c3-c5+c7) */			tmp2 = tmp2 * FIX_3_072711026;		/* sqrt(2) * ( c1+c3+c5-c7) */			tmp3 = tmp3 * FIX_1_501321110;		/* sqrt(2) * ( c1+c3-c5-c7) */			z1 = z1 * (0 - FIX_0_899976223);	/* sqrt(2) * (c7-c3) */			z2 = z2 * (0 - FIX_2_562915447);	/* sqrt(2) * (-c1-c3) */			z3 = z3 * (0 - FIX_1_961570560);	/* sqrt(2) * (-c3-c5) */			z4 = z4 * (0 - FIX_0_390180644);	/* sqrt(2) * (c5-c3) */						z3 = z3 + z5;			z4 = z4 + z5;						tmp0 = tmp0 + z1 + z3;			tmp1 = tmp1 + z2 + z4;			tmp2 = tmp2 + z2 + z3;			tmp3 = tmp3 + z1 + z4;			/* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */			int descaleFactor1 = ExtendTest[18];			int descaleFactor2 = ExtendTest[19];			dataUnit[c0] = (tmp10 + tmp3 + descaleFactor1) / descaleFactor2;			dataUnit[c7] = (tmp10 - tmp3 + descaleFactor1) / descaleFactor2;			dataUnit[c1] = (tmp11 + tmp2 + descaleFactor1) / descaleFactor2;			dataUnit[c6] = (tmp11 - tmp2 + descaleFactor1) / descaleFactor2;			dataUnit[c2] = (tmp12 + tmp1 + descaleFactor1) / descaleFactor2;			dataUnit[c5] = (tmp12 - tmp1 + descaleFactor1) / descaleFactor2;			dataUnit[c3] = (tmp13 + tmp0 + descaleFactor1) / descaleFactor2;			dataUnit[c4] = (tmp13 - tmp0 + descaleFactor1) / descaleFactor2;		}	}}boolean isFileFormat(LEDataInputStream stream) {	try {		JPEGStartOfImage soi = new JPEGStartOfImage(stream);		stream.unread(soi.reference);		return soi.verify();  // we no longer check for appN	} catch (Exception e) {		return false;	}}boolean isZeroInColumn(int[] dataUnit, int col) {	return (dataUnit[col + 8] + dataUnit[col + 16] +		dataUnit[col + 24] + dataUnit[col + 32] +		dataUnit[col + 40] + dataUnit[col + 48] +		dataUnit[col + 56]) == 0;}boolean isZeroInRow(int[] dataUnit, int rIndex) {	return (dataUnit[rIndex + 1] + dataUnit[rIndex + 2] +		dataUnit[rIndex + 3] + dataUnit[rIndex + 4] +		dataUnit[rIndex + 5] + dataUnit[rIndex + 6] +		dataUnit[rIndex + 7]) == 0;}ImageData[] loadFromByteStream() {	JPEGStartOfImage soi = new JPEGStartOfImage(inputStream);	if (!soi.verify()) SWT.error(SWT.ERROR_INVALID_IMAGE);	restartInterval = 0;	/* Process the tables preceding the frame header. */	processTables();		/* Start of Frame. */	frameHeader = new JPEGFrameHeader(inputStream);	if (!frameHeader.verify()) SWT.error(SWT.ERROR_INVALID_IMAGE);	imageWidth = frameHeader.getSamplesPerLine();	imageHeight = frameHeader.getNumberOfLines();	maxH = frameHeader.getMaxHFactor();	maxV = frameHeader.getMaxVFactor();	int mcuWidth = maxH * DCTSIZE;	int mcuHeight = maxV * DCTSIZE;	interleavedMcuCols = (imageWidth + mcuWidth - 1) / mcuWidth;	interleavedMcuRows = (imageHeight + mcuHeight - 1) / mcuHeight;	progressive = frameHeader.isProgressive();	samplePrecision = frameHeader.getSamplePrecision();	nComponents = frameHeader.getNumberOfImageComponents();	frameComponents = frameHeader.componentParameters;	componentIds = frameHeader.componentIdentifiers;	imageComponents = new byte[nComponents][];	if (progressive) {

⌨️ 快捷键说明

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