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

📄 pngscanlinedecoder.cpp

📁 symbian 开SDK例子!!3RD 是学习的不错实例啊
💻 CPP
📖 第 1 页 / 共 2 页
字号:

			for (TUint mask=0x80; mask!=0; mask>>=1) // iterate with 0x80, 0x40 .. 0x01
				WritePixel(iInfo.iPalette[dataValue & mask],iInfo.iTransparencyValue[dataValue & mask]);
			}
		}
	else
		{
		while (aDataPtr < aDataPtrLimit)
			{
			TInt dataValue = *aDataPtr++;

			for (TUint mask=0x80; mask!=0; mask>>=1) // iterate with 0x80, 0x40 .. 0x01
				WritePixel(iInfo.iPalette[dataValue & mask]);
			}
		}
	}


//
// CBitDepth2Decoder: specialised reader for 2bpp scanlines
//
void CBitDepth2Decoder::DoConstructL()
	{
	if (!(iInfo.iColorType & TPngImageInformation::EPaletteUsed))
		{ // Set up palette to be grayscale values
		iInfo.iPalette[0] = KRgbBlack;
		iInfo.iPalette[1] = KRgbDarkGray;
		iInfo.iPalette[2] = KRgbGray;
		iInfo.iPalette[3] = KRgbWhite;

		if (iInfo.iTransparencyPresent)
			{
			if (iInfo.iTransparentGray <= 3)
				iInfo.iTransparencyValue[iInfo.iTransparentGray] = 0;
			}
		}

	// Replicate values to avoid shifts when decoding
	iInfo.iPalette[4] = iInfo.iPalette[1];
	iInfo.iPalette[8] = iInfo.iPalette[2];
	iInfo.iPalette[12] = iInfo.iPalette[3];

	iInfo.iPalette[16] = iInfo.iPalette[1];
	iInfo.iPalette[32] = iInfo.iPalette[2];
	iInfo.iPalette[48] = iInfo.iPalette[3];

	iInfo.iPalette[64] = iInfo.iPalette[1];
	iInfo.iPalette[128] = iInfo.iPalette[2];
	iInfo.iPalette[192] = iInfo.iPalette[3];

	if (iInfo.iTransparencyPresent)
		{
		iInfo.iTransparencyValue[4] = iInfo.iTransparencyValue[1];
		iInfo.iTransparencyValue[8] = iInfo.iTransparencyValue[2];
		iInfo.iTransparencyValue[12] = iInfo.iTransparencyValue[3];

		iInfo.iTransparencyValue[16] = iInfo.iTransparencyValue[1];
		iInfo.iTransparencyValue[32] = iInfo.iTransparencyValue[2];
		iInfo.iTransparencyValue[48] = iInfo.iTransparencyValue[3];

		iInfo.iTransparencyValue[64] = iInfo.iTransparencyValue[1];
		iInfo.iTransparencyValue[128] = iInfo.iTransparencyValue[2];
		iInfo.iTransparencyValue[192] = iInfo.iTransparencyValue[3];
		}

	iBytesPerPixel = 1;
	if (iInfo.iInterlaceMethod == TPngImageInformation::ENoInterlace)
		{
		TInt pixelPadding = ((iInfo.iSize.iWidth + 3) & ~3) - iInfo.iSize.iWidth;
		iImageProc->SetPixelPadding(pixelPadding);
		if (iMaskProc)
			iMaskProc->SetPixelPadding(pixelPadding);
		}
	}

TInt CBitDepth2Decoder::ScanlineBufferSize(TInt aPixelLength)
	{
	return ((aPixelLength + 3) / 4) + KPngScanlineFilterTypeLength;
	}

void CBitDepth2Decoder::DoDecode(TUint8* aDataPtr,const TUint8* aDataPtrLimit)
	{
	if (iMaskProc && iInfo.iTransparencyPresent)
		{
		while (aDataPtr < aDataPtrLimit)
			{
			TInt dataValue = *aDataPtr++;

			for (TInt mask=0xc0; mask!=0; mask>>=2) // iterate through 0xc0, 0x30, 0x0c and 0x03
				WritePixel(iInfo.iPalette[dataValue & mask],iInfo.iTransparencyValue[dataValue & mask]);
			}
		}
	else
		{
		while (aDataPtr < aDataPtrLimit)
			{
			TInt dataValue = *aDataPtr++;

			for (TInt mask=0xc0; mask!=0; mask>>=2) // iterate through 0xc0, 0x30, 0x0c and 0x03
				WritePixel(iInfo.iPalette[dataValue & mask]);
			}
		}
	}


//
// CBitDepth4Decoder: specialised reader for 4bpp scanlines
//

void CBitDepth4Decoder::DoConstructL()
	{
	if (!(iInfo.iColorType & TPngImageInformation::EPaletteUsed))
		{ // Set up palette to be grayscale values
		for (TInt index = 0; index < 16; index++)
			iInfo.iPalette[index] = TRgb::Gray16(index);

		if (iInfo.iTransparencyPresent)
			{
			if (iInfo.iTransparentGray <= 15)
				iInfo.iTransparencyValue[iInfo.iTransparentGray] = 0;
			}
		}

	iBytesPerPixel = 1;
	if (iInfo.iInterlaceMethod == TPngImageInformation::ENoInterlace)
		{
		TInt pixelPadding = ((iInfo.iSize.iWidth + 1) & ~1) - iInfo.iSize.iWidth;
		iImageProc->SetPixelPadding(pixelPadding);
		if (iMaskProc)
			iMaskProc->SetPixelPadding(pixelPadding);
		}
	}

TInt CBitDepth4Decoder::ScanlineBufferSize(TInt aPixelLength)
	{
	return ((aPixelLength + 1) / 2) + KPngScanlineFilterTypeLength;
	}

void CBitDepth4Decoder::DoDecode(TUint8* aDataPtr,const TUint8* aDataPtrLimit)
	{
	if (iMaskProc && iInfo.iTransparencyPresent)
		{
		while (aDataPtr < aDataPtrLimit)
			{
			TInt dataValue = *aDataPtr++;

			WritePixel(iInfo.iPalette[dataValue >> 4],iInfo.iTransparencyValue[dataValue >> 4]);
			WritePixel(iInfo.iPalette[dataValue & 0x0f],iInfo.iTransparencyValue[dataValue & 0x0f]);
			}
		}
	else
		{
		while (aDataPtr < aDataPtrLimit)
			{
			TInt dataValue = *aDataPtr++;

			WritePixel(iInfo.iPalette[dataValue >> 4]);
			WritePixel(iInfo.iPalette[dataValue & 0x0f]);
			}
		}
	}


//
// CBitDepth8Decoder: specialised reader for 8bpp scanlines
//

void CBitDepth8Decoder::DoConstructL()
	{
	if (!(iInfo.iColorType & TPngImageInformation::EPaletteUsed))
		{ // Set up palette to be grayscale values
		for (TInt index = 0; index < 256; index++)
			iInfo.iPalette[index] = TRgb::Gray256(index);

		if (iInfo.iTransparencyPresent)
			{
			if (iInfo.iTransparentGray <= 255)
				iInfo.iTransparencyValue[iInfo.iTransparentGray] = 0;
			}
		}

	iBytesPerPixel = 1;
	}

TInt CBitDepth8Decoder::ScanlineBufferSize(TInt aPixelLength)
	{
	return aPixelLength + KPngScanlineFilterTypeLength;
	}

void CBitDepth8Decoder::DoDecode(TUint8* aDataPtr,const TUint8* aDataPtrLimit)
	{
	if (iMaskProc && iInfo.iTransparencyPresent)
		{
		while (aDataPtr < aDataPtrLimit)
			{
			WritePixel(iInfo.iPalette[aDataPtr[0]],iInfo.iTransparencyValue[aDataPtr[0]]);
			aDataPtr++;
			}
		}
	else
		{
		while (aDataPtr < aDataPtrLimit)
			WritePixel(iInfo.iPalette[*aDataPtr++]);
		}
	}


//
// CBitDepth8ColorType2Decoder: specialised reader for 8bpp scanlines, direct colour
//

void CBitDepth8ColorType2Decoder::DoConstructL()
	{
	iBytesPerPixel = 3;
	}

TInt CBitDepth8ColorType2Decoder::ScanlineBufferSize(TInt aPixelLength)
	{
	return (aPixelLength * 3) + KPngScanlineFilterTypeLength;
	}

void CBitDepth8ColorType2Decoder::DoDecode(TUint8* aDataPtr,const TUint8* aDataPtrLimit)
	{
	if (iMaskProc && iInfo.iTransparencyPresent)
		{
		while (aDataPtr < aDataPtrLimit)
			{
			TInt red = aDataPtr[0];
			TInt green = aDataPtr[1];
			TInt blue = aDataPtr[2];
			TRgb pixelColor(red,green,blue);
			if (red == iInfo.iTransparentRed && green == iInfo.iTransparentGreen && blue == iInfo.iTransparentBlue)
				WritePixel(pixelColor,0);
			else
				WritePixel(pixelColor,255);
			aDataPtr += 3;
			}
		}
	else
		{
		while (aDataPtr < aDataPtrLimit)
			{
			WritePixel(TRgb(aDataPtr[0],aDataPtr[1],aDataPtr[2]));
			aDataPtr += 3;
			}
		}
	}


//
// CBitDepth8ColorType4Decoder: specialised reader for 8bpp scanlines, alpha greyscale
//

void CBitDepth8ColorType4Decoder::DoConstructL()
	{
	iBytesPerPixel = 2;
	}

TInt CBitDepth8ColorType4Decoder::ScanlineBufferSize(TInt aPixelLength)
	{
	return (aPixelLength * 2) + KPngScanlineFilterTypeLength;
	}

void CBitDepth8ColorType4Decoder::DoDecode(TUint8* aDataPtr,const TUint8* aDataPtrLimit)
	{
	if (iMaskProc)
		{
		while (aDataPtr < aDataPtrLimit)
			{
			WritePixel(TRgb::Gray256(aDataPtr[0]),aDataPtr[1]);
			aDataPtr += 2;
			}
		}
	else
		{
		while (aDataPtr < aDataPtrLimit)
			{
			WritePixel(TRgb::Gray256(aDataPtr[0]));
			aDataPtr += 2;
			}
		}
	}


//
// CBitDepth8ColorType4Decoder: specialised reader for 8bpp scanlines, alpha colour
//

void CBitDepth8ColorType6Decoder::DoConstructL()
	{
	iBytesPerPixel = 4;
	}

TInt CBitDepth8ColorType6Decoder::ScanlineBufferSize(TInt aPixelLength)
	{
	return (aPixelLength * 4) + KPngScanlineFilterTypeLength;
	}

void CBitDepth8ColorType6Decoder::DoDecode(TUint8* aDataPtr,const TUint8* aDataPtrLimit)
	{
	if (iMaskProc)
		{
		while (aDataPtr < aDataPtrLimit)
			{
			WritePixel(TRgb(aDataPtr[0],aDataPtr[1],aDataPtr[2]),aDataPtr[3]);
			aDataPtr += 4;
			}
		}
	else
		{
		while (aDataPtr < aDataPtrLimit)
			{
			WritePixel(TRgb(aDataPtr[0],aDataPtr[1],aDataPtr[2]));
			aDataPtr += 4;
			}
		}
	}


//
// CBitDepth16ColorType0Decoder: specialised reader for 16bpp scanlines, greyscale
//

void CBitDepth16ColorType0Decoder::DoConstructL()
	{
	iBytesPerPixel = 2;
	}

TInt CBitDepth16ColorType0Decoder::ScanlineBufferSize(TInt aPixelLength)
	{
	return (aPixelLength * 2) + KPngScanlineFilterTypeLength;
	}

void CBitDepth16ColorType0Decoder::DoDecode(TUint8* aDataPtr,const TUint8* aDataPtrLimit)
	{
	if (iMaskProc && iInfo.iTransparencyPresent)
		{
		while (aDataPtr < aDataPtrLimit)
			{
			TInt gray = (aDataPtr[0] << 8) | aDataPtr[1];
			TRgb pixelColor(TRgb::Gray256(aDataPtr[0]));
			if (gray == iInfo.iTransparentGray)
				WritePixel(pixelColor,0);
			else
				WritePixel(pixelColor,255);
			aDataPtr += 2;
			}
		}
	else
		{
		while (aDataPtr < aDataPtrLimit)
			{
			WritePixel(TRgb::Gray256(aDataPtr[0]));
			aDataPtr += 2;
			}
		}
	}


//
// CBitDepth16ColorType2Decoder: specialised reader for 16bpp scanlines, RGB colour
//

void CBitDepth16ColorType2Decoder::DoConstructL()
	{
	iBytesPerPixel = 6;
	}

TInt CBitDepth16ColorType2Decoder::ScanlineBufferSize(TInt aPixelLength)
	{
	return (aPixelLength * 6) + KPngScanlineFilterTypeLength;
	}

void CBitDepth16ColorType2Decoder::DoDecode(TUint8* aDataPtr,const TUint8* aDataPtrLimit)
	{
	if (iMaskProc && iInfo.iTransparencyPresent)
		{
		while (aDataPtr < aDataPtrLimit)
			{
			TInt red = (aDataPtr[0] << 8) | aDataPtr[1];
			TInt green = (aDataPtr[2] << 8) | aDataPtr[3];
			TInt blue = (aDataPtr[4] << 8) | aDataPtr[5];
			TRgb pixelColor(aDataPtr[0],aDataPtr[2],aDataPtr[4]);
			if (red == iInfo.iTransparentRed && green == iInfo.iTransparentGreen && blue == iInfo.iTransparentBlue)
				WritePixel(pixelColor,0);
			else
				WritePixel(pixelColor,255);
			aDataPtr += 6;
			}
		}
	else
		{
		while (aDataPtr < aDataPtrLimit)
			{
			WritePixel(TRgb(aDataPtr[0],aDataPtr[2],aDataPtr[4]));
			aDataPtr += 6;
			}
		}
	}


//
// CBitDepth16ColorType4Decoder: specialised reader for 16bpp scanlines, alpha greyscale
//

void CBitDepth16ColorType4Decoder::DoConstructL()
	{
	iBytesPerPixel = 4;
	}

TInt CBitDepth16ColorType4Decoder::ScanlineBufferSize(TInt aPixelLength)
	{
	return (aPixelLength * 4) + KPngScanlineFilterTypeLength;
	}

void CBitDepth16ColorType4Decoder::DoDecode(TUint8* aDataPtr,const TUint8* aDataPtrLimit)
	{
	if (iMaskProc)
		{
		while (aDataPtr < aDataPtrLimit)
			{
			WritePixel(TRgb::Gray256(aDataPtr[0]),aDataPtr[2]);
			aDataPtr += 4;
			}
		}
	else
		{
		while (aDataPtr < aDataPtrLimit)
			{
			WritePixel(TRgb::Gray256(aDataPtr[0]));
			aDataPtr += 4;
			}
		}
	}


//
// CBitDepth16ColorType6Decoder: specialised reader for 16bpp scanlines, alpha colour
//

void CBitDepth16ColorType6Decoder::DoConstructL()
	{
	iBytesPerPixel = 8;
	}

TInt CBitDepth16ColorType6Decoder::ScanlineBufferSize(TInt aPixelLength)
	{
	return (aPixelLength * 8) + KPngScanlineFilterTypeLength;
	}

void CBitDepth16ColorType6Decoder::DoDecode(TUint8* aDataPtr,const TUint8* aDataPtrLimit)
	{
	if (iMaskProc)
		{
		while (aDataPtr < aDataPtrLimit)
			{
			WritePixel(TRgb(aDataPtr[0],aDataPtr[2],aDataPtr[4]),aDataPtr[6]);
			aDataPtr += 8;
			}
		}
	else
		{
		while (aDataPtr < aDataPtrLimit)
			{
			WritePixel(TRgb(aDataPtr[0],aDataPtr[2],aDataPtr[4]));
			aDataPtr += 8;
			}
		}
	}

⌨️ 快捷键说明

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