00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "Bitmap.h"
00023 #include "Visible.h"
00024 #include "Presentable.h"
00025 #include "Ingredients.h"
00026 #include "Root.h"
00027 #include "BaseClasses.h"
00028 #include "ParseNode.h"
00029 #include "ASN1Codes.h"
00030 #include "Engine.h"
00031 #include "Logging.h"
00032 #include "freemheg.h"
00033
00034 #include "inttypes.h"
00035
00036
00037
00038
00039
00040 MHBitmap::MHBitmap()
00041 {
00042 m_fTiling = false;
00043 m_nOrigTransparency = 0;
00044 m_nTransparency = 0;
00045 m_nXDecodeOffset = 0;
00046 m_nYDecodeOffset = 0;
00047 m_pContent = NULL;
00048 }
00049
00050 MHBitmap::MHBitmap(const MHBitmap &ref): MHVisible(ref)
00051 {
00052 m_fTiling = ref.m_fTiling;
00053 m_nOrigTransparency = ref.m_nOrigTransparency;
00054 m_nTransparency = 0;
00055 m_nXDecodeOffset = 0;
00056 m_nYDecodeOffset = 0;
00057 m_pContent = NULL;
00058 }
00059
00060 MHBitmap::~MHBitmap()
00061 {
00062 delete(m_pContent);
00063 }
00064
00065 void MHBitmap::Initialise(MHParseNode *p, MHEngine *engine)
00066 {
00067 MHVisible::Initialise(p, engine);
00068
00069 MHParseNode *pTiling = p->GetNamedArg(C_TILING);
00070
00071 if (pTiling)
00072 {
00073 m_fTiling = pTiling->GetArgN(0)->GetBoolValue();
00074 }
00075
00076
00077 MHParseNode *pTransparency = p->GetNamedArg(C_ORIGINAL_TRANSPARENCY);
00078
00079 if (pTransparency)
00080 {
00081 m_nOrigTransparency = pTransparency->GetArgN(0)->GetIntValue();
00082 }
00083
00084 m_pContent = engine->GetContext()->CreateBitmap(m_fTiling);
00085 }
00086
00087 void MHBitmap::PrintMe(FILE *fd, int nTabs) const
00088 {
00089 PrintTabs(fd, nTabs);
00090 fprintf(fd, "{:Bitmap ");
00091 MHVisible::PrintMe(fd, nTabs + 1);
00092
00093 if (m_fTiling)
00094 {
00095 PrintTabs(fd, nTabs + 1);
00096 fprintf(fd, ":Tiling true\n");
00097 }
00098
00099 if (m_nOrigTransparency != 0)
00100 {
00101 PrintTabs(fd, nTabs + 1);
00102 fprintf(fd, ":OrigTransparency %d\n", m_nOrigTransparency);
00103 }
00104
00105 PrintTabs(fd, nTabs);
00106 fprintf(fd, "}\n");
00107 }
00108
00109 void MHBitmap::Preparation(MHEngine *engine)
00110 {
00111 if (m_fAvailable)
00112 {
00113 return;
00114 }
00115
00116 m_nTransparency = m_nOrigTransparency;
00117 MHVisible::Preparation(engine);
00118 }
00119
00120
00121 void MHBitmap::ContentPreparation(MHEngine *engine)
00122 {
00123 MHVisible::ContentPreparation(engine);
00124
00125 if (m_ContentType == IN_NoContent)
00126 {
00127 MHERROR("Bitmap must contain a content");
00128 }
00129
00130 if (m_ContentType == IN_IncludedContent)
00131 {
00132 MHERROR("Included content in bitmap is not implemented");
00133 }
00134 }
00135
00136
00137 void MHBitmap::ContentArrived(const unsigned char *data, int length, MHEngine *engine)
00138 {
00139 QRegion updateArea = GetVisibleArea();
00140
00141 if (! m_pContent)
00142 {
00143 return;
00144 }
00145
00146 int nCHook = m_nContentHook;
00147
00148 if (nCHook == 0)
00149 {
00150 nCHook = engine->GetDefaultBitmapCHook();
00151 }
00152
00153
00154 if (nCHook == 4)
00155 {
00156 m_pContent->CreateFromPNG(data, length);
00157 }
00158
00159
00160
00161 else if (nCHook == 2 )
00162 {
00163 m_pContent->CreateFromMPEG(data, length);
00164 }
00165
00166 else
00167 {
00168 MHERROR(QString("Unknown bitmap content hook %1").arg(nCHook));
00169 }
00170
00171 updateArea += GetVisibleArea();
00172 engine->Redraw(updateArea);
00173
00174
00175 engine->EventTriggered(this, EventContentAvailable);
00176 }
00177
00178
00179
00180
00181 void MHBitmap::SetTransparency(int nTransPerCent, MHEngine *)
00182 {
00183
00184
00185 if (nTransPerCent < 0)
00186 {
00187 nTransPerCent = 0;
00188 }
00189
00190 if (nTransPerCent > 100)
00191 {
00192 nTransPerCent = 100;
00193 }
00194
00195 m_nTransparency = ((nTransPerCent * 255) + 50) / 100;
00196 }
00197
00198
00199 void MHBitmap::ScaleBitmap(int xScale, int yScale, MHEngine *engine)
00200 {
00201 QRegion updateArea = GetVisibleArea();
00202 m_pContent->ScaleImage(xScale, yScale);
00203 updateArea += GetVisibleArea();
00204 engine->Redraw(updateArea);
00205 }
00206
00207
00208 void MHBitmap::SetBitmapDecodeOffset(int newXOffset, int newYOffset, MHEngine *engine)
00209 {
00210 QRegion updateArea = GetVisibleArea();
00211 m_nXDecodeOffset = newXOffset;
00212 m_nYDecodeOffset = newYOffset;
00213 updateArea += GetVisibleArea();
00214 engine->Redraw(updateArea);
00215 }
00216
00217
00218 void MHBitmap::GetBitmapDecodeOffset(MHRoot *pXOffset, MHRoot *pYOffset)
00219 {
00220 pXOffset->SetVariableValue(m_nXDecodeOffset);
00221 pYOffset->SetVariableValue(m_nYDecodeOffset);
00222 }
00223
00224 void MHBitmap::Display(MHEngine *)
00225 {
00226 if (! m_fRunning || ! m_pContent || m_nBoxWidth == 0 || m_nBoxHeight == 0)
00227 {
00228 return;
00229 }
00230
00231 m_pContent->Draw(m_nPosX + m_nXDecodeOffset, m_nPosY + m_nYDecodeOffset,
00232 QRect(m_nPosX, m_nPosY, m_nBoxWidth, m_nBoxHeight), m_fTiling);
00233 }
00234
00235
00236 QRegion MHBitmap::GetVisibleArea()
00237 {
00238 if (! m_fRunning || m_pContent == NULL)
00239 {
00240 return QRegion();
00241 }
00242
00243
00244
00245 QSize imageSize = m_pContent->GetSize();
00246 QRegion boxRegion = QRegion(m_nPosX, m_nPosY, m_nBoxWidth, m_nBoxHeight);
00247 QRegion bitmapRegion = QRegion(m_nPosX + m_nXDecodeOffset, m_nPosY + m_nYDecodeOffset,
00248 imageSize.width(), imageSize.height());
00249 return boxRegion & bitmapRegion;
00250 }
00251
00252
00253 QRegion MHBitmap::GetOpaqueArea()
00254 {
00255
00256 if (! m_fRunning || m_pContent == NULL || ! m_pContent->IsOpaque())
00257 {
00258 return QRegion();
00259 }
00260 else
00261 {
00262 return GetVisibleArea();
00263 }
00264 }
00265