Blend.h revision fa45108679c51623e716acbc3301b1e4535c3267
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
27#include "Delaunay.h"
28
29#define BLEND_RANGE_DEFAULT 6
30#define BORDER 8
31
32// Percent of total mosaicing time spent on each of the following operations
33const float TIME_PERCENT_ALIGN = 20.0;
34const float TIME_PERCENT_BLEND = 75.0;
35const float TIME_PERCENT_FINAL = 5.0;
36
37//#define LINEAR_INTERP
38
39//#define LOGII(...) //
40//#define LOGIE(...) //
41#if 1
42#ifdef ANDROID
43#include <android/log.h>
44#define ANDROID_LOG_VERBOSE ANDROID_LOG_DEBUG
45#define LOG_TAG "CVJNI"
46#define LOGII(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
47#define LOGIE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
48#else
49#define LOGII printf
50#define LOGIE printf
51#endif
52#endif
53
54
55/**
56 *  Class for pyramid blending a mosaic.
57 */
58class Blend {
59
60public:
61
62  static const int BLEND_TYPE_NONE    = -1;
63  static const int BLEND_TYPE_FULL    = 0;
64  static const int BLEND_TYPE_PAN     = 1;
65  static const int BLEND_TYPE_CYLPAN  = 2;
66  static const int BLEND_TYPE_HORZ   = 3;
67
68  static const int BLEND_RET_ERROR        = -1;
69  static const int BLEND_RET_OK           = 0;
70  static const int BLEND_RET_ERROR_MEMORY = 1;
71
72  Blend();
73  ~Blend();
74
75  int initialize(int blendingType, int frame_width, int frame_height);
76
77  int runBlend(MosaicFrame **frames, int frames_size, ImageType &imageMosaicYVU,
78        int &mosaicWidth, int &mosaicHeight, float &progress);
79
80protected:
81
82  PyramidShort *m_pFrameYPyr;
83  PyramidShort *m_pFrameUPyr;
84  PyramidShort *m_pFrameVPyr;
85
86  PyramidShort *m_pMosaicYPyr;
87  PyramidShort *m_pMosaicUPyr;
88  PyramidShort *m_pMosaicVPyr;
89
90  CDelaunay m_Triangulator;
91  CSite *m_AllSites;
92
93  BlendParams m_wb;
94
95  // Height and width of individual frames
96  int width, height;
97
98   // Height and width of mosaic
99  unsigned short Mwidth, Mheight;
100
101  // Helper functions
102  void FrameToMosaic(double trs[3][3], double x, double y, double &wx, double &wy);
103  void MosaicToFrame(double trs[3][3], double x, double y, double &wx, double &wy);
104  void FrameToMosaicRect(int width, int height, double trs[3][3], BlendRect &brect);
105  void ClipBlendRect(CSite *csite, BlendRect &brect);
106  void AlignToMiddleFrame(MosaicFrame **frames, int frames_size);
107
108  int  DoMergeAndBlend(MosaicFrame **frames, int nsite,  int width, int height, YUVinfo &imgMos, MosaicRect &rect, MosaicRect &cropping_rect, float &progress);
109  void ComputeMask(CSite *csite, BlendRect &vcrect, BlendRect &brect, MosaicRect &rect, YUVinfo &imgMos, int site_idx);
110  void ProcessPyramidForThisFrame(CSite *csite, BlendRect &vcrect, BlendRect &brect, MosaicRect &rect, YUVinfo &imgMos, double trs[3][3], int site_idx);
111
112  int  FillFramePyramid(MosaicFrame *mb);
113
114  // TODO: need to add documentation about the parameters
115  void ComputeBlendParameters(MosaicFrame **frames, int frames_size, int is360);
116
117  int  PerformFinalBlending(YUVinfo &imgMos, MosaicRect &cropping_rect);
118  void CropFinalMosaic(YUVinfo &imgMos, MosaicRect &cropping_rect);
119};
120
121#endif
122