RectangleT QuadNode::unionRect( QuadNode* n ) { if (n == NULL) { return RectangleT::Zero; } RectangleT rc; QuadNode* m = NULL; m = n->children_[eQuadNode_LeftBottom]; if (m) { rc = calculateRect(m); } m = n->children_[eQuadNode_RightBottom]; if (m) { RectangleT t = calculateRect(m); rc.right_ += (t.right_ - t.left_); } m = n->children_[eQuadNode_LeftTop]; if (m) { RectangleT t = calculateRect(m); rc.top_ += (t.top_ - t.bottom_); } m = n->children_[eQuadNode_RightTop]; if (m) { RectangleT t = calculateRect(m); // rc.top_ += (t.top_ - t.bottom_); } n->rect_ = rc; return rc; }
void Rectangle::calculatePoints(const SbVec3f& initPos, const SbVec3f& curPos, SoCoordinate3& coord) { int deltaWidth = abs(initPos[0] - curPos[0]) * 2; int deltaHeight = abs(initPos[1] - curPos[1]) * 2; SbVec3f leftTop, rightTop, leftBottom, rightBottom; calculateRect(initPos, leftTop, rightTop, leftBottom, rightBottom, initWidth + deltaWidth, initHeight + deltaHeight); coord.point.set1Value(0, leftTop); coord.point.set1Value(1, rightTop); coord.point.set1Value(2, rightBottom); coord.point.set1Value(3, leftBottom); coord.point.set1Value(4, leftTop); }
LPRImage* ImageSynthesis::synthesis(LPRImage *pRawImages[], const EventImageSynthesis &synthesisParam, const VSDRect &vsrRect) { //LPRMutexLocker locker(&mMutex); // 加锁,多线程安全 assert(synthesisParam.mNumberofImage > 0); // TODO 检查图像宽高一致 需要保证输入的图像是一致的 // 先解码JPG流得到BGR24的图像 LPRImage *pImage = mImageDecoder.decode(pRawImages[0]); LPRImage *pFocusImage = genFocusImage(pImage, vsrRect); ////////////////////////////////////////////////////////////////////////// // 取得局部图像之后,图像的张数 int imageCount = synthesisParam.mNumberofImage + 1; int littleImgWidth = pImage->width; int littleImgHeight = pImage->height; int littleImgDepth = pImage->depth; int littleImgChannels = pImage->nChannels; int largeImgWidth = 0; int largeImgHeight = 0; LPRImage *pLargeImg = NULL; switch (synthesisParam.mPicOrientation) { case EVENT_APP_PIC_VERTICAL: { largeImgWidth = littleImgWidth; largeImgHeight = imageCount * littleImgHeight; pLargeImg = LPRCreateImage(largeImgWidth, largeImgHeight, littleImgDepth, littleImgChannels); } break; case EVENT_APP_PIC_HORIZONTAL: { largeImgWidth = imageCount * littleImgWidth; largeImgHeight = littleImgHeight; pLargeImg = LPRCreateImage(largeImgWidth, largeImgHeight, littleImgDepth, littleImgChannels); } break; case EVENT_APP_PIC_GRID: { if (imageCount % 2 == 0) { largeImgWidth = 2 * littleImgWidth; largeImgHeight = imageCount/2 * littleImgHeight; pLargeImg = LPRCreateImage(largeImgWidth, largeImgHeight, littleImgDepth, littleImgChannels); } else { printf("Unsupported synthesis option grid with the odd number of images.\n"); return NULL; } } break; default: printf("Unsupported image orientation.\n"); return NULL; } // 大图和参数设置位置,开始生成 // 第一张图像已经解压过了 int i = 0; RECT r; calculateRect(r, synthesisParam.mPicOrientation, littleImgWidth, littleImgHeight, i); LPRCopySubImageToLarge(pImage, pLargeImg, r); ++ i; // 第二张到最后一张rawImage for (; i < imageCount - 1; ++ i) { calculateRect(r, synthesisParam.mPicOrientation, littleImgWidth, littleImgHeight, i); pImage = mImageDecoder.decode(pRawImages[i]); LPRCopySubImageToLarge(pImage, pLargeImg, r); } // focusImage calculateRect(r, synthesisParam.mPicOrientation, littleImgWidth, littleImgHeight, i); LPRCopySubImageToLarge(pFocusImage, pLargeImg, r); /*char savePath[256]; _snprintf(savePath, 256, "d:\\syn_image_g.jpg"); LPRSaveImage(pLargeImg, savePath);*/ // 如果生成了大图,并且需要进行缩放 if (NULL != pLargeImg && synthesisParam.mZoomRatio != 100) { int nTargetWidth = (int)((float)pLargeImg->width * synthesisParam.mZoomRatio / 100 + 0.5f); int nTargetHeight = (int)((float)pLargeImg->height * synthesisParam.mZoomRatio / 100 + 0.5f); LPRImage* pImTextResized = LPRCreateImage(nTargetWidth, nTargetHeight, pLargeImg->depth, pLargeImg->nChannels); LPRResizeImage(pLargeImg, pImTextResized); LPRReleaseImage(pLargeImg); pLargeImg = pImTextResized; } // 释放focusImage LPRReleaseImage(pFocusImage); return pLargeImg; }