00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "plstdpch.h"
00012 #include "plfiltercrop.h"
00013 #include "plbitmap.h"
00014
00015
00016 PLFilterCrop::PLFilterCrop(int XMin, int YMin, int XMax, int YMax)
00017 : PLFilter(),
00018 m_XMin(XMin),
00019 m_XMax(XMax),
00020 m_YMin(YMin),
00021 m_YMax(YMax)
00022 {
00023 }
00024
00025 PLFilterCrop::~PLFilterCrop()
00026 {
00027
00028 }
00029
00030 void PLFilterCrop::Apply(PLBmp * pBmpSource, PLBmp * pBmpDest) const
00031 {
00032 PLASSERT (m_XMin >= 0);
00033 PLASSERT (m_XMax <= pBmpSource->GetWidth());
00034 PLASSERT (m_YMin >= 0);
00035 PLASSERT (m_YMax <= pBmpSource->GetHeight());
00036 PLASSERT (m_XMin < m_XMax);
00037 PLASSERT (m_YMin < m_YMax);
00038
00039 PLASSERT (pBmpSource->GetBitsPerPixel() == 8 ||
00040 pBmpSource->GetBitsPerPixel() == 24 ||
00041 pBmpSource->GetBitsPerPixel() == 32);
00042
00043 pBmpDest->Create (m_XMax-m_XMin, m_YMax-m_YMin,
00044 pBmpSource->GetBitsPerPixel(), pBmpSource->HasAlpha(),
00045 pBmpSource->GetResolution());
00046 PLBYTE ** pSrcLineArray = pBmpSource->GetLineArray();
00047 PLBYTE ** pDstLineArray = pBmpDest->GetLineArray();
00048
00049 int y;
00050 for (y = m_YMin; y < m_YMax; y++)
00051 {
00052 PLBYTE * pSrcLine = pSrcLineArray[y];
00053 PLBYTE * pDstLine = pDstLineArray[y-m_YMin];
00054 int BytesPerPixel = pBmpSource->GetBitsPerPixel()/8;
00055 memcpy (pDstLine, pSrcLine + m_XMin*BytesPerPixel, (m_XMax-m_XMin)*BytesPerPixel);
00056 }
00057 if (pBmpSource->GetBitsPerPixel() == 8)
00058 {
00059 pBmpDest->SetPalette(pBmpSource->GetPalette());
00060 }
00061 }
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115