#@brief:检查是否为闰年
#@param1:YYYY格式的年份
check_leap()
{
    #http://baike.baidu.com/view/29649.htm
    #四年一闰,百年不闰,四百年再闰
    mod4=$(( 10#$1 % 4 ));
    mod100=$(( 10#$1 % 100 ));
    mod400=$(( 10#$1 % 400 ));
    if [ $mod400 -eq 0 -o $mod100 -ne 0 -a $mod4 -eq 0 ] ; then
        return 0;
    fi;

    return 1;
}

#@brief:获取指定月的天数
#@param1:YYYYMM格式的月份
get_days()
{
    YYYY=`echo $1 | awk '{print substr($1,1,4)}'`;
    MM=`echo $1 | awk '{print substr($1,5,2)}'`;

    MM=$(( 10#$MM ));

    days=0;
    case "$MM" in
        1|3|5|7|8|10|12)
            days=31;
        ;;
        2)
            check_leap $YYYY;
            if [ $? -eq 0 ] ; then
                days=29;
            else
                days=28;
            fi;
        ;;
        4|6|9|11)
            days=30;
        ;;
        *)
            days=0;
        ;;
    esac;

    echo $days;
}

#@brief:Yesterday
#@param1:YYYYMMDD格式的日期
Yesterday()
{
    YYYY=`echo $1 | awk '{print substr($1,1,4)}'`;
    MM=`echo $1 | awk '{print substr($1,5,2)}'`;
    MM=$(( 10#$MM ));

    DD=`echo $1 | awk '{print substr($1,7,2)}'`;
    DD=$(( 10#$DD-1 ));

    if [ $DD -eq 0 ] ; then
        MM=$(( 10#$MM-1 ));
        if [ $MM -eq 0 ] ; then
            MM=12;
            YYYY=$(( 10#$YYYY-1 ));
        fi;
       
  if [ $MM -lt 10 ] ; then
   MM="0${MM}";
  fi;
   
  DD=`get_days ${YYYY}${MM}`;
    fi;

 MM=$(( 10#$MM ));
    if [ $MM -lt 10 ] ; then
  MM="0${MM}";
    fi;

 DD=$(( 10#$DD ));
    if [ $DD -lt 10 ] ; then
  DD="0${DD}";
    fi;

    echo "${YYYY}${MM}${DD}";
}

#@brief:检查日期是否合法
#@param1:YYYYMMDD格式的日期
check_date()
{
    if [ $# -lt 1 ] ; then
        return 1;
    fi;
   
    numberstr=`echo $1 | grep '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'`;
    if [ -z "${numberstr}" ] ; then
        return 1;
    fi;
   
    length=`echo $1 | awk '{print length($1)}'`;
    if [ $length -ne 8 ] ; then
        return 1;
    fi;
   
    YYYY=`echo $1 | awk '{print substr($1,1,4)}'`;
    MM=`echo $1 | awk '{print substr($1,5,2)}'`;
    DD=`echo $1 | awk '{print substr($1,7,2)}'`;
    if [ $YYYY -lt 1000 -o $YYYY -gt 9999 ] ; then
        return 1;
    fi;
   
    if [ $MM -lt 1 -o $MM -gt 12 ] ; then
        return 1;
    fi;
   
    days_in_mm=`get_days ${YYYY}${MM}`;
   
    if [ $DD -lt 1 -o $DD -gt $days_in_mm ] ; then
        return 1;
    fi;
   
    return 0;
}

#@brief:检查月份是否合法
#@param1:YYYYMM格式的月份
check_month()
{
    if [ $# -lt 1 ] ; then
        return 1;
    fi;
   
    numberstr=`echo $1 | grep '[0-9][0-9][0-9][0-9][0-9][0-9]'`;
    if [ -z "${numberstr}" ] ; then
        return 1;
    fi;
   
    length=`echo $1 | awk '{print length($1)}'`;
    if [ $length -ne 6 ] ; then
        return 1;
    fi;
   
    YYYY=`echo $1 | awk '{print substr($1,1,4)}'`;
    MM=`echo $1 | awk '{print substr($1,5,2)}'`;
   
    if [ $YYYY -lt 1000 -o $YYYY -gt 9999 ] ; then
        return 1;
    fi;
   
    if [ $MM -lt 1 -o $MM -gt 12 ] ; then
        return 1;
    fi;
   
    return 0;
}

#@brief:LastMonth
#@param1:YYYYMM格式的月份
LastMonth()
{
    YYYY=`echo $1 | awk '{print substr($1,1,4)}'`;
    MM=`echo $1 | awk '{print substr($1,5,2)}'`;
   
    MM=$(( 10#$MM ));
   
    if [ $MM -eq 1 ] ; then
        MM=12;
        YYYY=$(( 10#$YYYY-1 ));
    else
        MM=$(( 10#$MM-1 ));
    fi;
   
    if [ $MM -lt 10 ] ; then
        MM="0${MM}";
    fi;
   
    echo "${YYYY}${MM}";
}

以上代码在HP-UX和MSYS上测试通过(2012年3月29日)。


本文链接地址: 几个日期相关的Shell脚本
https://blog.qingfengju.com/index.asp?id=278

分类:Linux 查看次数:8510 发布时间:2012/1/30 15:36:28

//YV12和I420格式只是U和V的位置不同
//参见:《浅述YUV颜色格式.pdf》
void RotateRightYV12(int _rows,int _cols,unsigned char* _pdata,unsigned char* _new_pdata)
{
 int yv12_size=(_rows*_cols)*3/2;
 int y_size=(yv12_size*2)/3;
 int v_size=yv12_size/6;
 int u_size=yv12_size/6;

 unsigned char* y_data=_pdata;
 unsigned char* v_data=_pdata+y_size;
 unsigned char* u_data=_pdata+y_size+v_size;

 unsigned char* y2_data=_new_pdata;
 unsigned char* v2_data=_new_pdata+y_size;
 unsigned char* u2_data=_new_pdata+y_size+v_size;

 //YVU三个分量单独旋转
 RotateRight(_rows,_cols,y_data,y2_data);
 RotateRight(_rows/2,_cols/2,v_data,v2_data);
 RotateRight(_rows/2,_cols/2,u_data,u2_data);
}

RotateRight函数参见:
http://www.qingfengju.com/article.asp?id=265
 


本文链接地址: YV12/I410图像的旋转算法
https://blog.qingfengju.com/index.asp?id=292

分类:Win32/C++ 查看次数:7808 发布时间:2012/1/2 16:16:01