1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 /////////////////////////////////////////////////// 18 // Blend.h 19 // $Id: Blend.h,v 1.23 2011/06/24 04:22:14 mbansal Exp $ 20 21 #ifndef BLEND_H 22 #define BLEND_H 23 24 #include "MosaicTypes.h" 25 #include "Pyramid.h" 26 #include "Delaunay.h" 27 28 #define BLEND_RANGE_DEFAULT 6 29 #define BORDER 8 30 31 // Percent of total mosaicing time spent on each of the following operations 32 const float TIME_PERCENT_ALIGN = 20.0; 33 const float TIME_PERCENT_BLEND = 75.0; 34 const float TIME_PERCENT_FINAL = 5.0; 35 36 // This threshold determines the minimum separation between the image centers 37 // of the input image frames for them to be accepted for blending in the 38 // STRIP_TYPE_WIDE mode. This threshold is specified as a fraction of the 39 // input image frame width. 40 const float STRIP_SEPARATION_THRESHOLD = 0.10; 41 42 // This threshold determines the number of pixels on either side of the strip 43 // to cross-fade using the images contributing to each seam. This threshold 44 // is specified as a fraction of the input image frame width. 45 const float STRIP_CROSS_FADE_WIDTH = 0.002; 46 /** 47 * Class for pyramid blending a mosaic. 48 */ 49 class Blend { 50 51 public: 52 53 static const int BLEND_TYPE_NONE = -1; 54 static const int BLEND_TYPE_FULL = 0; 55 static const int BLEND_TYPE_PAN = 1; 56 static const int BLEND_TYPE_CYLPAN = 2; 57 static const int BLEND_TYPE_HORZ = 3; 58 59 static const int STRIP_TYPE_THIN = 0; 60 static const int STRIP_TYPE_WIDE = 1; 61 62 static const int BLEND_RET_ERROR = -1; 63 static const int BLEND_RET_OK = 0; 64 static const int BLEND_RET_ERROR_MEMORY = 1; 65 static const int BLEND_RET_CANCELLED = -2; 66 67 Blend(); 68 ~Blend(); 69 70 int initialize(int blendingType, int stripType, int frame_width, int frame_height); 71 72 int runBlend(MosaicFrame **frames, MosaicFrame **rframes, int frames_size, ImageType &imageMosaicYVU, 73 int &mosaicWidth, int &mosaicHeight, float &progress, bool &cancelComputation); 74 75 protected: 76 77 PyramidShort *m_pFrameYPyr; 78 PyramidShort *m_pFrameUPyr; 79 PyramidShort *m_pFrameVPyr; 80 81 PyramidShort *m_pMosaicYPyr; 82 PyramidShort *m_pMosaicUPyr; 83 PyramidShort *m_pMosaicVPyr; 84 85 CDelaunay m_Triangulator; 86 CSite *m_AllSites; 87 88 BlendParams m_wb; 89 90 // Height and width of individual frames 91 int width, height; 92 93 // Height and width of mosaic 94 unsigned short Mwidth, Mheight; 95 96 // Helper functions 97 void FrameToMosaic(double trs[3][3], double x, double y, double &wx, double &wy); 98 void MosaicToFrame(double trs[3][3], double x, double y, double &wx, double &wy); 99 void FrameToMosaicRect(int width, int height, double trs[3][3], BlendRect &brect); 100 void ClipBlendRect(CSite *csite, BlendRect &brect); 101 void AlignToMiddleFrame(MosaicFrame **frames, int frames_size); 102 103 int DoMergeAndBlend(MosaicFrame **frames, int nsite, int width, int height, YUVinfo &imgMos, MosaicRect &rect, MosaicRect &cropping_rect, float &progress, bool &cancelComputation); 104 void ComputeMask(CSite *csite, BlendRect &vcrect, BlendRect &brect, MosaicRect &rect, YUVinfo &imgMos, int site_idx); 105 void ProcessPyramidForThisFrame(CSite *csite, BlendRect &vcrect, BlendRect &brect, MosaicRect &rect, YUVinfo &imgMos, double trs[3][3], int site_idx); 106 107 int FillFramePyramid(MosaicFrame *mb); 108 109 // TODO: need to add documentation about the parameters 110 void ComputeBlendParameters(MosaicFrame **frames, int frames_size, int is360); 111 void SelectRelevantFrames(MosaicFrame **frames, int frames_size, 112 MosaicFrame **relevant_frames, int &relevant_frames_size); 113 114 int PerformFinalBlending(YUVinfo &imgMos, MosaicRect &cropping_rect); 115 void CropFinalMosaic(YUVinfo &imgMos, MosaicRect &cropping_rect); 116 }; 117 118 #endif 119