1e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen/* 2e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen * Copyright (C) 2011 The Android Open Source Project 3e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen * 4e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen * Licensed under the Apache License, Version 2.0 (the "License"); 5e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen * you may not use this file except in compliance with the License. 6e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen * You may obtain a copy of the License at 7e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen * 8e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen * http://www.apache.org/licenses/LICENSE-2.0 9e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen * 10e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen * Unless required by applicable law or agreed to in writing, software 11e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen * distributed under the License is distributed on an "AS IS" BASIS, 12e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen * See the License for the specific language governing permissions and 14e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen * limitations under the License. 15e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen */ 16e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen 17e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen/////////////////////////////////////////////////// 18e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen// Blend.h 19e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen// $Id: Blend.h,v 1.23 2011/06/24 04:22:14 mbansal Exp $ 20e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen 21e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen#ifndef BLEND_H 22e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen#define BLEND_H 23e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen 24e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen#include "MosaicTypes.h" 25e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen#include "Pyramid.h" 26e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen#include "Delaunay.h" 27e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen 28e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen#define BLEND_RANGE_DEFAULT 6 29e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen#define BORDER 8 30e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen 3150b3c890986aadb3780b4da8c0b8dbb0f1422ebambansal// Percent of total mosaicing time spent on each of the following operations 3250b3c890986aadb3780b4da8c0b8dbb0f1422ebambansalconst float TIME_PERCENT_ALIGN = 20.0; 3350b3c890986aadb3780b4da8c0b8dbb0f1422ebambansalconst float TIME_PERCENT_BLEND = 75.0; 3450b3c890986aadb3780b4da8c0b8dbb0f1422ebambansalconst float TIME_PERCENT_FINAL = 5.0; 3550b3c890986aadb3780b4da8c0b8dbb0f1422ebambansal 36b28b9c0fa991bc97e8aa11da83d27f71fdfef6dambansal// This threshold determines the minimum separation between the image centers 37b28b9c0fa991bc97e8aa11da83d27f71fdfef6dambansal// of the input image frames for them to be accepted for blending in the 388252bf716c798a1007e7869569b35815d2df3c6cmbansal// STRIP_TYPE_WIDE mode. 398252bf716c798a1007e7869569b35815d2df3c6cmbansalconst float STRIP_SEPARATION_THRESHOLD_PXLS = 10; 40b28b9c0fa991bc97e8aa11da83d27f71fdfef6dambansal 41b28b9c0fa991bc97e8aa11da83d27f71fdfef6dambansal// This threshold determines the number of pixels on either side of the strip 428252bf716c798a1007e7869569b35815d2df3c6cmbansal// to cross-fade using the images contributing to each seam. 438252bf716c798a1007e7869569b35815d2df3c6cmbansalconst float STRIP_CROSS_FADE_WIDTH_PXLS = 2; 448252bf716c798a1007e7869569b35815d2df3c6cmbansal// This specifies the maximum pyramid level to which cross-fading is applied. 458252bf716c798a1007e7869569b35815d2df3c6cmbansal// The original image resolution is Level-0, half of that size is Level-1 and 468252bf716c798a1007e7869569b35815d2df3c6cmbansal// so on. BLEND_RANGE_DEFAULT specifies the number of pyramid levels used by 478252bf716c798a1007e7869569b35815d2df3c6cmbansal// the blending algorithm. 488252bf716c798a1007e7869569b35815d2df3c6cmbansalconst int STRIP_CROSS_FADE_MAX_PYR_LEVEL = 2; 498252bf716c798a1007e7869569b35815d2df3c6cmbansal 50e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen/** 51e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen * Class for pyramid blending a mosaic. 52e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen */ 53e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chenclass Blend { 54e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen 55e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chenpublic: 56e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen 57e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen static const int BLEND_TYPE_NONE = -1; 58e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen static const int BLEND_TYPE_FULL = 0; 59e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen static const int BLEND_TYPE_PAN = 1; 60e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen static const int BLEND_TYPE_CYLPAN = 2; 61e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen static const int BLEND_TYPE_HORZ = 3; 62e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen 63b28b9c0fa991bc97e8aa11da83d27f71fdfef6dambansal static const int STRIP_TYPE_THIN = 0; 64b28b9c0fa991bc97e8aa11da83d27f71fdfef6dambansal static const int STRIP_TYPE_WIDE = 1; 65b28b9c0fa991bc97e8aa11da83d27f71fdfef6dambansal 66e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen static const int BLEND_RET_ERROR = -1; 67e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen static const int BLEND_RET_OK = 0; 68e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen static const int BLEND_RET_ERROR_MEMORY = 1; 69e1178a73fd5756771d25d0b8375452450f509e99mbansal static const int BLEND_RET_CANCELLED = -2; 70e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen 71e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen Blend(); 72e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen ~Blend(); 73e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen 74b28b9c0fa991bc97e8aa11da83d27f71fdfef6dambansal int initialize(int blendingType, int stripType, int frame_width, int frame_height); 75e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen 76b28b9c0fa991bc97e8aa11da83d27f71fdfef6dambansal int runBlend(MosaicFrame **frames, MosaicFrame **rframes, int frames_size, ImageType &imageMosaicYVU, 77e1178a73fd5756771d25d0b8375452450f509e99mbansal int &mosaicWidth, int &mosaicHeight, float &progress, bool &cancelComputation); 78e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen 79e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chenprotected: 80e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen 81e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen PyramidShort *m_pFrameYPyr; 82e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen PyramidShort *m_pFrameUPyr; 83e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen PyramidShort *m_pFrameVPyr; 84e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen 85e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen PyramidShort *m_pMosaicYPyr; 86e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen PyramidShort *m_pMosaicUPyr; 87e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen PyramidShort *m_pMosaicVPyr; 88e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen 89e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen CDelaunay m_Triangulator; 90e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen CSite *m_AllSites; 91e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen 92e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen BlendParams m_wb; 93e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen 94e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen // Height and width of individual frames 95e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen int width, height; 96e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen 97e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen // Height and width of mosaic 98e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen unsigned short Mwidth, Mheight; 99e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen 100e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen // Helper functions 101e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen void FrameToMosaic(double trs[3][3], double x, double y, double &wx, double &wy); 102e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen void MosaicToFrame(double trs[3][3], double x, double y, double &wx, double &wy); 103e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen void FrameToMosaicRect(int width, int height, double trs[3][3], BlendRect &brect); 104e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen void ClipBlendRect(CSite *csite, BlendRect &brect); 1051e762b1f935c9d4a06af6dd56121590ca81d48b1mbansal void AlignToMiddleFrame(MosaicFrame **frames, int frames_size); 106e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen 107e1178a73fd5756771d25d0b8375452450f509e99mbansal int DoMergeAndBlend(MosaicFrame **frames, int nsite, int width, int height, YUVinfo &imgMos, MosaicRect &rect, MosaicRect &cropping_rect, float &progress, bool &cancelComputation); 108e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen void ComputeMask(CSite *csite, BlendRect &vcrect, BlendRect &brect, MosaicRect &rect, YUVinfo &imgMos, int site_idx); 109e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen void ProcessPyramidForThisFrame(CSite *csite, BlendRect &vcrect, BlendRect &brect, MosaicRect &rect, YUVinfo &imgMos, double trs[3][3], int site_idx); 110e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen 111e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen int FillFramePyramid(MosaicFrame *mb); 112fa45108679c51623e716acbc3301b1e4535c3267Wei-Ta Chen 113fa45108679c51623e716acbc3301b1e4535c3267Wei-Ta Chen // TODO: need to add documentation about the parameters 114e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen void ComputeBlendParameters(MosaicFrame **frames, int frames_size, int is360); 115b28b9c0fa991bc97e8aa11da83d27f71fdfef6dambansal void SelectRelevantFrames(MosaicFrame **frames, int frames_size, 116b28b9c0fa991bc97e8aa11da83d27f71fdfef6dambansal MosaicFrame **relevant_frames, int &relevant_frames_size); 117e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen 118e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen int PerformFinalBlending(YUVinfo &imgMos, MosaicRect &cropping_rect); 119e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen void CropFinalMosaic(YUVinfo &imgMos, MosaicRect &cropping_rect); 1200a039136e8e46ddbcb45b55e92d80ddb2ddfc2c2Wei-Ta Chen 1210a039136e8e46ddbcb45b55e92d80ddb2ddfc2c2Wei-Ta Chenprivate: 1220a039136e8e46ddbcb45b55e92d80ddb2ddfc2c2Wei-Ta Chen static const float LIMIT_SIZE_MULTIPLIER = 5.0f * 2.0f; 1230a039136e8e46ddbcb45b55e92d80ddb2ddfc2c2Wei-Ta Chen static const float LIMIT_HEIGHT_MULTIPLIER = 2.5f; 1240a039136e8e46ddbcb45b55e92d80ddb2ddfc2c2Wei-Ta Chen int MosaicSizeCheck(float sizeMultiplier, float heightMultiplier); 125d05569f2b8ff7fafc7b7b6547adf62431a2011b8Wei-Ta Chen void RoundingCroppingSizeToMultipleOf8(MosaicRect& rect); 126e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen}; 127e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen 128e295e32b68cf04f0d99138bf4a6d25555f3aef99Wei-Ta Chen#endif 129