📄 vtc_wavelet_imagebox.cpp
字号:
/* $Id: vtc_wavelet_imagebox.cpp,v 1.1 2005/05/09 21:29:49 wmaycisco Exp $ *//****************************************************************************//* MPEG4 Visual Texture Coding (VTC) Mode Software *//* *//* This software was jointly developed by the following participants: *//* *//* Single-quant, multi-quant and flow control *//* are provided by Sarnoff Corporation *//* Iraj Sodagar (iraj@sarnoff.com) *//* Hung-Ju Lee (hjlee@sarnoff.com) *//* Paul Hatrack (hatrack@sarnoff.com) *//* Shipeng Li (shipeng@sarnoff.com) *//* Bing-Bing Chai (bchai@sarnoff.com) *//* B.S. Srinivas (bsrinivas@sarnoff.com) *//* *//* Bi-level is provided by Texas Instruments *//* Jie Liang (liang@ti.com) *//* *//* Shape Coding is provided by OKI Electric Industry Co., Ltd. *//* Zhixiong Wu (sgo@hlabs.oki.co.jp) *//* Yoshihiro Ueda (yueda@hlabs.oki.co.jp) *//* Toshifumi Kanamaru (kanamaru@hlabs.oki.co.jp) *//* *//* OKI, Sharp, Sarnoff, TI and Microsoft contributed to bitstream *//* exchange and bug fixing. *//* *//* *//* In the course of development of the MPEG-4 standard, this software *//* module is an implementation of a part of one or more MPEG-4 tools as *//* specified by the MPEG-4 standard. *//* *//* The copyright of this software belongs to ISO/IEC. ISO/IEC gives use *//* of the MPEG-4 standard free license to use this software module or *//* modifications thereof for hardware or software products claiming *//* conformance to the MPEG-4 standard. *//* *//* Those intending to use this software module in hardware or software *//* products are advised that use may infringe existing patents. The *//* original developers of this software module and their companies, the *//* subsequent editors and their companies, and ISO/IEC have no liability *//* and ISO/IEC have no liability for use of this software module or *//* modification thereof in an implementation. *//* *//* Permission is granted to MPEG members to use, copy, modify, *//* and distribute the software modules ( or portions thereof ) *//* for standardization activity within ISO/IEC JTC1/SC29/WG11. *//* *//* Copyright 1995, 1996, 1997, 1998 ISO/IEC *//****************************************************************************//************************************************************//* Sarnoff Very Low Bit Rate Still Image Coder *//* Copyright 1995, 1996, 1997, 1998 Sarnoff Corporation *//************************************************************//* imagebox.c -- extend/crop an image to a box of the minimal multiples of 2^Decomposition Level size that contains the object, according to the mask information */#include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>#include <memory.h>#include "basic.hpp"#include "dwt.h"#include "dataStruct.hpp" // FPDAM added by Sharp#ifndef __cplusplusstatic Int LCM(Int x, Int y);static Int GCD(Int x, Int y);#endif/* Function: GetBox() Description: get image object with the bounding box Input: InImage -- Input image data, data type defined by DataType; RealWidth, RealHeight -- the size of the actual image; VirtualWidth, VirtualHeight -- size of the output image; OriginX, OriginY -- origins of the output image relative to the original image DataType -- 0 - UChar 1- UShort for InImage and OutImage Output: OutImage -- Output image within the bounding box (can be cropped or extended version of the InImage) Return: DWT_NOVALID_PIXEL if the mask are all zeros, otherwise DWT_OK if no error; Note: The caller should free the memory OutImage allocated by this program after it finishes using them.*/Int VTCIMAGEBOX::GetBox(Void *InImage, Void **OutImage, Int RealWidth, Int RealHeight, Int VirtualWidth, Int VirtualHeight, Int OriginX, Int OriginY, Int DataType){ Int origin_x, origin_y; Int virtual_width, virtual_height; UChar *data, *indata; Int wordsize = (DataType==DWT_USHORT_ENUM)?2:1; Int i, j; Int real_width, real_height; Int max_x, max_y; Int rows, cols; real_width = RealWidth; real_height = RealHeight; origin_x = OriginX; origin_y = OriginY; virtual_width = VirtualWidth; virtual_height = VirtualHeight; /* allocate proper memory and initialize */ if ((data = (UChar *)malloc(sizeof(UChar)*virtual_width*virtual_height*wordsize)) == NULL) { return(DWT_MEMORY_FAILED); } memset(data, (Char )0, sizeof(UChar)*virtual_width*virtual_height*wordsize); /* calculate clip area */ max_y = origin_y+virtual_height; max_y = (max_y<real_height)?max_y:real_height; rows = max_y - origin_y; max_x = origin_x+virtual_width; max_x = (max_x<real_width)?max_x:real_width; cols = max_x - origin_x; indata = (UChar *)InImage; /* fill out data */ for(i=0, j=origin_y*real_width+origin_x; i< rows*virtual_width; i+=virtual_width, j+=real_width) { memcpy(data+i, indata+j, wordsize*cols); } *OutImage = data; return(DWT_OK);} /* Function: GetMaskBox() Description: get the bounding box of the mask of image object Input: InMask -- Input image mask, can be NULL if Shape == RECTANGULAR; RealWidth, RealHeight -- the size of the actual image; Nx, Ny -- specify that OriginX and OriginY must be multiple of Nx and Ny to accomdate different color compoents configuration: Examples: for 420: Nx Ny Y: 2 2 U,V: 1 1 for 422: Y: 2 1 for 444: Y,U,V: 1 1 for mono: Y: 1 1 for YUV9: Y: 4 4 U,V: 1 1 Shape -- if -1, the SHAPE is rectangular, else arbitary shape and Shape defines the mask value of an object, useful for multiple objects coding nLevels -- levels of decomposition Output: OutMask -- Output image mask, extended area is marked as Don't-care VirtualWidth, VirtualHeight -- size of the output image OriginX, OriginY -- origins of the output image relative to the original image Return: DWT_NOVALID_PIXEL if the mask are all zeros, otherwise DWT_OK if no error; Note: The caller should free the memory OutMask allocated by this program after it finishes using them.*/Int VTCIMAGEBOX:: GetMaskBox(UChar *InMask, UChar **OutMask, Int RealWidth, Int RealHeight, Int Nx, Int Ny, Int *VirtualWidth, Int *VirtualHeight, Int *OriginX, Int *OriginY, Int Shape, Int nLevels){ Int origin_x, origin_y; Int virtual_width, virtual_height; UChar *mask; Int blocksize = 1 << nLevels; Int i, j; Int real_width, real_height; Int max_x, max_y; Int min_x, min_y; Int rows, cols; UChar *a, *b, *f; if(blocksize%Nx!=0) blocksize = LCM(blocksize,Nx); if(blocksize%Ny!=0) blocksize = LCM(blocksize,Ny); real_width = RealWidth; real_height = RealHeight; if(Shape != RECTANGULAR) { /* to search for the upper left corner of the bounding box of arbitrarily shaped object */ min_x = real_width; min_y = real_height; max_x = 0; max_y =0; for(i=0,j=0;j < real_height; j++,i+=real_width){ a=InMask+i; f = InMask+i+real_width; for(; a< f; a++){ if(*a == Shape) { min_y = j; goto minx; } } } minx: for(i=0;i < real_width;i++){ a=InMask+i; f=InMask+i+real_width*real_height; for(; a<f; a+=real_width){ if(*a == Shape) { min_x = i; goto maxy; } } } maxy: for(j=real_height-1,i= (real_height-1)*real_width;j>=0 ;j--, i-=real_width){ a = InMask+i; f = InMask+i+real_width;; for(; a <f; a++) { if(*a == Shape) { max_y = j; goto maxx; } } } maxx: for(i=real_width-1;i >= 0;i--){ a=InMask+i; f = InMask+i+real_width*real_height; for(; a < f; a+=real_width){ if(*a == Shape) { max_x = i; goto next; } } } next: /* quantize the min_x and min_y with Nx and Ny */ if(min_x%Nx!=0) min_x=min_x/Nx*Nx; if(min_y%Ny!=0) min_y=min_y/Ny*Ny; if(min_x>max_x || min_y> max_y) { return(DWT_NOVALID_PIXEL); /* no valid pixel */ } origin_x = min_x; origin_y = min_y; virtual_width = max_x-min_x+1; virtual_height = max_y-min_y+1; /* fprIntf(stderr, "x=%d y=%d w=%d h=%d x2=%d y2=%d\n", min_x, min_y, virtual_width, virtual_height, max_x, max_y); */ } else { /* rectangular region */ origin_x = 0; origin_y = 0; virtual_width = RealWidth; virtual_height = RealHeight; } /* first ajust the dimension to be multiple of blocksize */ virtual_width = (virtual_width+(blocksize)-1)/blocksize*blocksize; virtual_height = (virtual_height+(blocksize)-1)/blocksize*blocksize; if ((mask = (UChar *)malloc(sizeof(UChar)*virtual_width*virtual_height)) == NULL) { return(DWT_MEMORY_FAILED); } memset(mask, (Char )0, sizeof(UChar)*virtual_width*virtual_height); /* calculate clip area */ max_y = origin_y+virtual_height; max_y = (max_y<real_height)?max_y:real_height; rows = max_y - origin_y; max_x = origin_x+virtual_width; max_x = (max_x<real_width)?max_x:real_width; cols = max_x - origin_x; /* fill out data */ for(i=0, j=origin_y*real_width+origin_x; i< rows*virtual_width; i+=virtual_width, j+=real_width) { if(Shape != RECTANGULAR) { f = InMask+j+cols; for(a = InMask+j, b=mask+i; a < f; a++, b++) { if(*a == (UChar) Shape) *b = DWT_IN; } } else memset(mask+i, (Char )DWT_IN, cols); } *VirtualWidth = virtual_width; *VirtualHeight = virtual_height; *OriginX = origin_x; *OriginY = origin_y; *OutMask = mask; return(DWT_OK);}// FPDAM begin: added by SharpInt VTCIMAGEBOX:: GetRealMaskBox(UChar *InMask, UChar **OutMask, Int RealWidth, Int RealHeight, Int Nx, Int Ny, Int *VirtualWidth, Int *VirtualHeight, Int *OriginX, Int *OriginY, Int Shape, Int nLevels){ Int origin_x, origin_y; Int virtual_width, virtual_height; UChar *mask; // Int blocksize = 1 << nLevels; Int i, j; Int real_width, real_height; Int max_x, max_y; Int min_x, min_y; Int rows, cols; UChar *a, *b, *f; real_width = RealWidth; real_height = RealHeight; if(Shape != RECTANGULAR) { /* to search for the upper left corner of the bounding box of arbitrarily shaped object */ min_x = real_width; min_y = real_height; max_x = 0; max_y =0; for(i=0,j=0;j < real_height; j++,i+=real_width){ a=InMask+i; f = InMask+i+real_width; for(; a< f; a++){ if(*a == Shape) { min_y = j; goto minx;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -