/* ***** BEGIN LICENSE BLOCK ***** * * $Id: overlay.cpp,v 1.8 2006/06/05 14:57:03 asuraparaju Exp $ $Name: Dirac_0_7_0 $ * * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * * The contents of this file are subject to the Mozilla Public License * Version 1.1 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for * the specific language governing rights and limitations under the License. * * The Original Code is BBC Research and Development code. * * The Initial Developer of the Original Code is the British Broadcasting * Corporation. * Portions created by the Initial Developer are Copyright (C) 2004. * All Rights Reserved. * * Contributor(s): Chris Bowley (Original Author) * * Alternatively, the contents of this file may be used under the terms of * the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser * Public License Version 2.1 (the "LGPL"), in which case the provisions of * the GPL or the LGPL are applicable instead of those above. If you wish to * allow use of your version of this file only under the terms of the either * the GPL or LGPL and not to allow others to use your version of this file * under the MPL, indicate your decision by deleting the provisions above * and replace them with the notice and other provisions required by the GPL * or LGPL. If you do not delete the provisions above, a recipient may use * your version of this file under the terms of any one of the MPL, the GPL * or the LGPL. * ***** END LICENSE BLOCK ***** */ #include using namespace dirac_instr; // using namespace dirac; // constructor Overlay::Overlay (const OverlayParams & overlayparams, Frame & frame) : m_oparams(overlayparams), m_frame(frame) { CalculateFactors(frame.GetFparams().CFormat()); } // destructor - doesn't do anything! Overlay::~Overlay () {} // process intra frame void Overlay::ProcessFrame() { // if a mid-grey background is selected instead of the original luma, do that if (m_oparams.Background()==0) { for (int j=0; j<=m_frame.Ydata().LastY(); ++j) { for (int i=0; i<=m_frame.Ydata().LastX(); ++i) m_frame.Ydata()[j][i]=128; } } // set chroma arrays to zero for (int j=0; jDrawLegend(); draw_overlay_ptr->DrawFrameNumber(m_frame.GetFparams().FrameNum()); draw_overlay_ptr->DrawReferenceNumber(m_oparams.Reference(), m_ref); } // otherwise, loop over motion vector blocks and draw as appropriate to overlay else { // carry out overlay on block by block basis for (int j=0; jDrawBlock(j, i); } } if (m_oparams.Legend()) draw_overlay_ptr->DrawLegend(); draw_overlay_ptr->DrawFrameNumber(m_frame.GetFparams().FrameNum()); if (m_oparams.Option() == pred_mode || m_oparams.Option() == split_mode) draw_overlay_ptr->DrawReferenceNumbers(m_frame.GetFparams().Refs()[0], m_frame.GetFparams().Refs()[1]); else draw_overlay_ptr->DrawReferenceNumber(m_oparams.Reference(), m_ref); } if (draw_overlay_ptr) delete draw_overlay_ptr; } // calculates the resolution factor between chroma and luma samples void Overlay::CalculateFactors(const ChromaFormat & cformat) { if (cformat == format422) { m_draw_params.SetChromaFactorY(1); m_draw_params.SetChromaFactorX(2); } else if (cformat == format420) { m_draw_params.SetChromaFactorY(2); m_draw_params.SetChromaFactorX(2); } else if (cformat == format444) { m_draw_params.SetChromaFactorY(1); m_draw_params.SetChromaFactorX(1); } else { m_draw_params.SetChromaFactorY(1); m_draw_params.SetChromaFactorX(1); } } // calculate if frame requires padding due to requirement of integer number of macroblocks void Overlay::PadFrame(const MEData & me_data) { int frame_x = m_frame.Ydata().LengthX(); int frame_y = m_frame.Ydata().LengthY(); // copy frame components PicArray Ydata(m_frame.Ydata()); PicArray Udata(m_frame.Udata()); PicArray Vdata(m_frame.Vdata()); // if there is not an integer number of macroblocks horizontally, pad until there is if (m_frame.Ydata().LengthX() % me_data.MBSplit().LengthX() != 0) { do { ++frame_x; } while (frame_x % me_data.MBSplit().LengthX() != 0); } // if there is not an integer number of macroblocks vertically, pad until there is if (m_frame.Ydata().LengthX() % me_data.MBSplit().LengthY() != 0) { do { ++frame_y; } while (frame_y % me_data.MBSplit().LengthY() != 0); } // if padding was required in either horizontal or vertical, adjust frame size and reload component data if (m_frame.Ydata().LengthX() % me_data.MBSplit().LengthX() != 0 || m_frame.Ydata().LengthY() % me_data.MBSplit().LengthY() != 0) { m_frame.Ydata().Resize(frame_y, frame_x); m_frame.Udata().Resize(frame_y / m_draw_params.ChromaFactorY(), frame_x / m_draw_params.ChromaFactorX()); m_frame.Vdata().Resize(frame_y / m_draw_params.ChromaFactorY(), frame_x / m_draw_params.ChromaFactorX()); for (int j=0; j