Skip to content

Commit

Permalink
Main: add optimized PF_R8 scaling & conversion
Browse files Browse the repository at this point in the history
based on patch by @darksylinc
  • Loading branch information
paroj committed Jun 13, 2019
1 parent 9e676a9 commit b975cfe
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
2 changes: 1 addition & 1 deletion OgreMain/src/OgreImage.cpp
Expand Up @@ -561,7 +561,7 @@ namespace Ogre {
case FILTER_BILINEAR:
switch (src.format)
{
case PF_L8: case PF_A8: case PF_BYTE_LA:
case PF_L8: case PF_R8: case PF_A8: case PF_BYTE_LA:
case PF_R8G8B8: case PF_B8G8R8:
case PF_R8G8B8A8: case PF_B8G8R8A8:
case PF_A8B8G8R8: case PF_A8R8G8B8:
Expand Down
54 changes: 54 additions & 0 deletions OgreMain/src/OgrePixelConversions.h
Expand Up @@ -201,6 +201,54 @@ struct R8G8B8A8toB8G8R8A8: public PixelConverter <Ogre::uint32, Ogre::uint32, FM
}
};

struct A8B8G8R8toR8: public PixelConverter <Ogre::uint32, Ogre::uint8, FMTCONVERTERID(Ogre::PF_A8B8G8R8, Ogre::PF_R8)>
{
inline static DstType pixelConvert(SrcType inp)
{
return (Ogre::uint8)(inp&0x000000FF);
}
};

struct R8toA8B8G8R8: public PixelConverter <Ogre::uint8, Ogre::uint32, FMTCONVERTERID(Ogre::PF_R8, Ogre::PF_A8B8G8R8)>
{
inline static DstType pixelConvert(SrcType inp)
{
return 0xFF000000|((unsigned int)inp);
}
};

struct A8R8G8B8toR8: public PixelConverter <Ogre::uint32, Ogre::uint8, FMTCONVERTERID(Ogre::PF_A8R8G8B8, Ogre::PF_R8)>
{
inline static DstType pixelConvert(SrcType inp)
{
return (Ogre::uint8)((inp&0x00FF0000)>>16);
}
};

struct R8toA8R8G8B8: public PixelConverter <Ogre::uint8, Ogre::uint32, FMTCONVERTERID(Ogre::PF_R8, Ogre::PF_A8R8G8B8)>
{
inline static DstType pixelConvert(SrcType inp)
{
return 0xFF000000|(((unsigned int)inp)<<16);
}
};

struct B8G8R8A8toR8: public PixelConverter <Ogre::uint32, Ogre::uint8, FMTCONVERTERID(Ogre::PF_B8G8R8A8, Ogre::PF_R8)>
{
inline static DstType pixelConvert(SrcType inp)
{
return (Ogre::uint8)((inp&0x0000FF00)>>8);
}
};

struct R8toB8G8R8A8: public PixelConverter <Ogre::uint8, Ogre::uint32, FMTCONVERTERID(Ogre::PF_R8, Ogre::PF_B8G8R8A8)>
{
inline static DstType pixelConvert(SrcType inp)
{
return 0x000000FF|(((unsigned int)inp)<<8);
}
};

struct A8B8G8R8toL8: public PixelConverter <Ogre::uint32, Ogre::uint8, FMTCONVERTERID(Ogre::PF_A8B8G8R8, Ogre::PF_L8)>
{
inline static DstType pixelConvert(SrcType inp)
Expand Down Expand Up @@ -398,6 +446,12 @@ inline int doOptimizedConversion(const Ogre::PixelBox &src, const Ogre::PixelBox
CASECONVERTER(R8G8B8A8toA8R8G8B8);
CASECONVERTER(R8G8B8A8toA8B8G8R8);
CASECONVERTER(R8G8B8A8toB8G8R8A8);
CASECONVERTER(A8B8G8R8toR8);
CASECONVERTER(R8toA8B8G8R8);
CASECONVERTER(A8R8G8B8toR8);
CASECONVERTER(R8toA8R8G8B8);
CASECONVERTER(B8G8R8A8toR8);
CASECONVERTER(R8toB8G8R8A8);
CASECONVERTER(A8B8G8R8toL8);
CASECONVERTER(L8toA8B8G8R8);
CASECONVERTER(A8R8G8B8toL8);
Expand Down
7 changes: 7 additions & 0 deletions Tests/OgreMain/src/PixelFormatTests.cpp
Expand Up @@ -192,6 +192,13 @@ TEST_F(PixelFormatTests,BulkConversion)
testCase(PF_R8G8B8A8,PF_A8B8G8R8);
testCase(PF_R8G8B8A8,PF_B8G8R8A8);

testCase(PF_A8B8G8R8, PF_R8);
testCase(PF_R8, PF_A8B8G8R8);
testCase(PF_A8R8G8B8, PF_R8);
testCase(PF_R8, PF_A8R8G8B8);
testCase(PF_B8G8R8A8, PF_R8);
testCase(PF_R8, PF_B8G8R8A8);

testCase(PF_A8B8G8R8, PF_L8);
testCase(PF_L8, PF_A8B8G8R8);
testCase(PF_A8R8G8B8, PF_L8);
Expand Down

0 comments on commit b975cfe

Please sign in to comment.