admin管理员组

文章数量:1534367

2024年1月17日发(作者:)

string zone( ch_zone ); //towgs84 char ch_wgs84[128]; memset( ch_wgs84 , 0 , 128 ); sprintf( ch_wgs84 , "+towgs84=%f,%f,%f,%f,%f,%f,%f" , _dx , _dy , _dz , _rx , _ry , _rz , _k ); string towgs84( ch_wgs84 ); sprintf ( _sz_source ,"%s%s%s%s" , proj.c_str() , ellps.c_str() , zone.c_str() , towgs84.c_str() ); init_proj( _sz_source ); if ( _coord_sys == 0 ) { longlat_2_xy( left , top ); longlat_2_xy( right , bottom ); } else { xy_2_xy( left , top ); xy_2_xy( right , bottom ); } /*init_proj( _sz_source , coord_wgs84 ); xy_2_latlong( left2 , top2 ); xy_2_latlong( right2 , bottom2 ); init_proj( coord_wgs84 , coord_google ); longlat_2_xy( left2 , top2 ); longlat_2_xy( right2 , bottom2 );*/}void CoordTrans::trans_2_des( double&left , double&top ){ double left2 = left; double top2 = top; string proj ; if ( _coord_sys == 0 ) { proj = "+proj=longlat "; } else if ( _coord_sys == 1 ) { proj = "+proj=tmerc "; } //椭球体 char ch_ellps[128]; memset( ch_ellps , 0 , 128 ); sprintf( ch_ellps , "+a=%f +b=%f " , ellps_list[_ellps].a , ellps_list[_ellps].b ); string ellps( ch_ellps ); //投影带 char ch_zone[512]; memset( ch_zone , 0 , 512 ); sprintf ( ch_zone ,"+x_0=%f +y_0=0.000000 +lat_0=0.000000 +lon_0=%f +units=m +k=1.000000 " , theProj[_maj_zone].pfe , theProj[_maj_zone].pl ); string zone( ch_zone ); //towgs84 char ch_wgs84[128]; memset( ch_wgs84 , 0 , 128 ); sprintf( ch_wgs84 , "+towgs84=%f,%f,%f,%f,%f,%f,%f" , _dx , _dy , _dz , _rx , _ry , _rz , _k ); string towgs84( ch_wgs84 ); sprintf ( _sz_source ,"%s%s%s%s" , proj.c_str() , ellps.c_str() , zone.c_str() , towgs84.c_str() ); init_proj( _sz_source ); if ( _coord_sys == 0 ) { longlat_2_xy( left , top ); } else { xy_2_xy( left , top ); }}void CoordTrans::trans_back_src( double&left , double&top ){ double left2 = left; double top2 = top; string proj ; if ( _coord_sys == 0 ) { proj = "+proj=longlat "; } else if ( _coord_sys == 1 ) { proj = "+proj=tmerc ";

new_y -= ( i_height * _scaleY_des );

double new_x = _geo_rect_; new_x += ( i_width * _scaleX_des ); if ( _coord_type == 0 ) { _coord__2_latlong( new_x , new_y ); } else { _coord__2_xy( new_x , new_y ); } new_x = src_geo_xy( new_x );//添加带号 int pixel_x = 0 , pixel_y = 0 ; point_to_by_geo( new_x , new_y , pixel_x , pixel_y ); //TIFF_UINT8_T* buf = new TIFF_UINT8_T[ _tiff_file->samples_per_pixel ]; //memset( buf , 0 , _tiff_file->samples_per_pixel ); if ( !( pixel_y == -1 || pixel_x == -1 ) ) {

TIFF_UINT32_T pos = height_start[pixel_y] + pixel_x*_tiff_file->samples_per_pixel; fseek( _tiff_file->pfile , height_start[pixel_y] + pixel_x*_tiff_file->samples_per_pixel , SEEK_SET ); fread( temp_buf , _tiff_file->samples_per_pixel , 1 , _tiff_file->pfile ); //fwrite( buf , _tiff_file->samples_per_pixel , 1 , _line_tiff ); temp_buf += _tiff_file->samples_per_pixel ; } else { //fwrite( buf , _tiff_file->samples_per_pixel , 1 , _line_tiff ); temp_buf += _tiff_file->samples_per_pixel ; } //delete[] buf; //buf = NULL; } fwrite( buf , _tiff_file->samples_per_pixel * _new_tiff_width , 1 , _line_tiff ); delete[] buf; buf = NULL; } printf( "转换完成! n" );}void tiffDeform::to_src_proj_first( geoRECT&des_geo , bool b , double&first_x , double&first_y ){/* (1) (2) +-----+ | | | | +-----+ (3) (4)

*/ //_coord__proj( coord_google , _proj4_str.c_str() ); double x1,y1,x2,y2,x3,y3,x4,y4; x1 = des_; y1 = des_; x2 = des_; y2 = des_; x3 = des_ ; y3 = des_; x4 = des_; y4 = des_; if ( _coord_type == 0 ) { _coord__2_latlong( x1 , y1 ); } else { _coord__2_xy( x1 , y1 ); } first_x = x1 ; first_y = y1 ; if ( _coord_type == 0 ) { _coord__2_latlong( x2 , y2 ); } else { _coord__2_xy( x2 , y2 ); } if ( _coord_type == 0 ) { _coord__2_latlong( x3 , y3 ); } else { _coord__2_xy( x3 , y3 ); } if ( _coord_type == 0 ) { _coord__2_latlong( x4 , y4 );

} else { _coord__2_xy( x4 , y4 ); } if ( b ) { des_ = x1 < x3 ? x3 : x1; des_ = y1 > y2 ? y2 : y1; des_ = x2 > x4 ? x4 : x2; des_ = y3 < y4 ? y4 : y3; } else { des_ = x1 > x3 ? x3 : x1; des_ = y1 < y2 ? y2 : y1; des_ = x2 < x4 ? x4 : x2; des_ = y3 > y4 ? y4 : y3; }}void tiffDeform::to_src_proj( geoRECT&des_geo , bool b ){ /* (1) (2) +-----+ | | | | +-----+ (3) (4)

*/ //_coord__proj( coord_google , _proj4_str.c_str() ); double x1,y1,x2,y2,x3,y3,x4,y4; x1 = des_; y1 = des_; x2 = des_; y2 = des_; x3 = des_ ; y3 = des_; x4 = des_; y4 = des_; if ( _coord_type == 0 ) { _coord__2_latlong( x1 , y1 ); } else { _coord__2_xy( x1 , y1 ); } if ( _coord_type == 0 ) { _coord__2_latlong( x2 , y2 ); } else { _coord__2_xy( x2 , y2 ); } if ( _coord_type == 0 ) { _coord__2_latlong( x3 , y3 ); } else { _coord__2_xy( x3 , y3 ); } if ( _coord_type == 0 ) { _coord__2_latlong( x4 , y4 ); } else { _coord__2_xy( x4 , y4 ); } if ( b ) { des_ = x1 < x3 ? x3 : x1; des_ = y1 > y2 ? y2 : y1; des_ = x2 > x4 ? x4 : x2; des_ = y3 < y4 ? y4 : y3; } else { des_ = x1 > x3 ? x3 : x1; des_ = y1 < y2 ? y2 : y1; des_ = x2 < x4 ? x4 : x2; des_ = y3 > y4 ? y4 : y3; }}void tiffDeform::des_geo_to_src_range( geoRECT des_geo , geoRECT&src_range ){ to_src_proj( des_geo , false ); src_ = ( des_ - _geo_rect_ ) / _scaleX_src - 0.5 ;

{ diff3[0].diff_x = 0 ; diff3[0].diff_y = 0 ; first3_x = pixel_x ; first3_y = pixel_y ; } else { diff3[ i_new_w ].diff_x = pixel_x - first3_x ; diff3[ i_new_w ].diff_y = pixel_y - first3_y ; } //第四部分 new_y = temp_; new_x = _geo_rect_; new_x += ( i_new_w * _scaleX_des ); if ( _coord_type == 0 ) { _coord__2_latlong( new_x , new_y ); } else { _coord__2_xy( new_x , new_y ); } new_x = src_geo_xy( new_x );//添加带号 pixel_x = 0 , pixel_y = 0 ; point_to_by_geo( new_x , new_y , pixel_x , pixel_y ); if ( i_new_w == 0 ) { diff4[0].diff_x = 0 ; diff4[0].diff_y = 0 ; first4_x = pixel_x ; first4_y = pixel_y ; } else { diff4[ i_new_w ].diff_x = pixel_x - first4_x ; diff4[ i_new_w ].diff_y = pixel_y - first4_y ; }*/ } geoRECT new_line_rect ; memset( &new_line_rect , 0 , sizeof( geoRECT ) ); new_line_ = _geo_rect_ ; new_line_ = _geo_rect_ ; TIFF_UINT8_T* buf = new TIFF_UINT8_T[ _tiff_file->samples_per_pixel * _new_tiff_width ]; memset( buf , 0 , _tiff_file->samples_per_pixel * _new_tiff_width ); for ( int i_height = 0 ; i_height < _new_tiff_height ; i_height++ ) { double line_y = _geo_rect_; line_y -= ( i_height * _scaleY_des );

new_line_ = line_y ; new_line_ = line_y ; geoRECT src_range; des_geo_to_src_range( new_line_rect , src_range ); int src_top = ( int )src_; int src_bottom = ( int )src_; TIFF_UINT32_T src_buf_size = LineBytes * ( src_bottom - src_top + 1 );

TIFF_UINT8_T* src_buf = new TIFF_UINT8_T[ src_buf_size ]; memset( src_buf , 0 , src_buf_size ); fseek( _tiff_file->pfile , height_start[src_top] , SEEK_SET ); fread( src_buf ,src_buf_size , 1 , _tiff_file->pfile ); TIFF_UINT8_T* temp_buf = buf ; DiffValue* ptemp = NULL ; for(bc=0; bc= block_interval * (bc)) { ptemp = diff[bc]; } } if(!ptemp) break;/* if ( i_height <= block_interval ) { ptemp = diff1; } else if ( i_height > block_interval && i_height <= _new_tiff_height/2 ) { ptemp = diff2; } else if ( i_height > _new_tiff_height/2 && i_height < ( _new_tiff_height/2 + block_interval ) )

}void tiffDeform::to_web_mector( geoRECT&rect , bool b ){ /* (1) (2) +-----+ | | | | +-----+ (3) (4)

*/ _coord__proj( _proj4_str.c_str() ); double x1 ,y1,x2 ,y2,x3 ,y3,x4 ,y4; x1 = ; y1 = ; if ( _coord_type == 0 ) { _coord_t_2_xy( x1 , y1 ); } else { _coord__2_xy( x1 , y1 ); } x2 = ; y2 = ; if ( _coord_type == 0 ) { _coord_t_2_xy( x2 , y2 ); } else { _coord__2_xy( x2 , y2 ); } x3 = ; y3 = ; if ( _coord_type == 0 ) { _coord_t_2_xy( x3 , y3 ); } else { _coord__2_xy( x3 , y3 ); } x4 = ; y4 = ; if ( _coord_type == 0 ) { _coord_t_2_xy( x4 , y4 ); } else { _coord__2_xy( x4 , y4 ); } if ( b ) { = x1 < x3 ? x3 : x1; = y1 > y2 ? y2 : y1; = x2 > x4 ? x4 : x2; = y3 < y4 ? y4 : y3; } else { = x1 > x3 ? x3 : x1; = y1 < y2 ? y2 : y1; = x2 < x4 ? x4 : x2; = y3 > y4 ? y4 : y3; }}void tiffDeform::to_web_mector( geoRECT&rect , bool b , double&x1 , double&y1, double&x2 , double&y2, double&x3 , double&y3, double&x4 , double&y4){ /* (1) (2) +-----+ | | | | +-----+ (3) (4)

*/ _coord__proj( _proj4_str.c_str() ); //double x1 ,y1,x2 ,y2,x3 ,y3,x4 ,y4; x1 = ; y1 = ; if ( _coord_type == 0 ) { _coord_t_2_xy( x1 , y1 ); } else

} } print_tag_info_list(); return _de_num ;}void tiffDeform::print_tag_info_list(){ printf( "n" ); for ( int i = 0 ; i < _de_num ; i++ ) { char outStr[1024]; memset( outStr , 0 , 1024 * sizeof( char ) ); sprintf( outStr , "0x%04x[ %5d %-26s ] , 0x%02x , 0x%04x( %5d ) , 0x%08x , %d n"

, de_list[i].

, de_list[i]. , tag_text( de_list[i]. ) , de_list[i].

, de_list[i]. , de_list[i]. , de_list[i].

, de_list[i].data_source ) ; printf( outStr ); }}const char* tiffDeform::tag_text( int i_tag ){ int i = 0 ; while ( tag_text_list[i].i_tag != -1 ) { if ( tag_text_list[i].i_tag == i_tag ) { return tag_text_list[i].text; } i++; } return "";}deInfo* tiffDeform::cts_strip_offsets(){ deInfo* temp_de = new deInfo; temp_de-> = 273; temp_de-> = 4;//long temp_de-> = _new_tiff_height; temp_de-> = 0; temp_de->data_source = 2; TIFF_UINT32_T* mem = new TIFF_UINT32_T[_new_tiff_height]; memset( mem , 0 , sizeof(TIFF_UINT32_T)*_new_tiff_height ); temp_de->mem_data = (TIFF_UINT8_T*)mem; return temp_de;}deInfo* tiffDeform::cts_rows_per_strip(){ deInfo* temp_de = new deInfo; temp_de-> = 278; temp_de-> = 3;//short temp_de-> = 1; temp_de-> = 1; temp_de->data_source = 0; temp_de->mem_data = NULL; return temp_de;}deInfo* tiffDeform::cts_strip_byte_counts(){ deInfo* temp_de = new deInfo; temp_de-> = 279; temp_de-> = 4;//short temp_de-> = _new_tiff_height; temp_de-> = 0; temp_de->data_source = 2; TIFF_UINT32_T* mem = new TIFF_UINT32_T[_new_tiff_height]; memset( mem , 0 , sizeof(TIFF_UINT32_T)*_new_tiff_height ); for ( int i = 0 ; i < _new_tiff_height ; i++ ) { mem[i] = _new_tiff_width * _tiff_file->samples_per_pixel; } temp_de->mem_data = (TIFF_UINT8_T*)mem; return temp_de;}deInfo* tiffDeform::cts_line_tag(){ deInfo* temp_line_tag_list = new deInfo[3]; memset( temp_line_tag_list , 0 , sizeof(deInfo) * 3 ); deInfo* temp = cts_strip_offsets(); memcpy( temp_line_tag_list , temp , sizeof(deInfo) ) ; delete temp; temp = cts_rows_per_strip(); memcpy( temp_line_tag_list + 1 , temp , sizeof(deInfo));

delete temp; temp = cts_strip_byte_counts(); memcpy( temp_line_tag_list + 2 , temp , sizeof(deInfo)); delete temp; temp = NULL; return temp_line_tag_list;}int tiffDeform::cts_new_tag_list( ){ deInfo* temp_line = cts_line_tag(); deInfo* temp_de_list = new deInfo[ _de_num ];//tile 4个标签 line 只需要3个标签 memset( temp_de_list , 0 , sizeof(deInfo)*( _de_num ) ); int tag_num = 0; int j = 0 , k = 0 ; for ( int i = 0 ; i < _de_num ; i++ ) { if ( de_list[i]. == 33550

|| de_list[i]. == 33922 || de_list[i]. == 34735 || de_list[i]. == 34736 || de_list[i]. == 34737) { continue; } tag_num ++; if ( k < 3 )//line只有三个标签 { if ( de_list[i]. < temp_line[k]. ) { memcpy( temp_de_list + j , de_list + i , sizeof( deInfo ) ); j++; } else { memcpy( temp_de_list + j , temp_line + k , sizeof( deInfo ) ); j++; k++; //i--; } } else { memcpy( temp_de_list + j , de_list + i , sizeof( deInfo ) ); j++; } int n = j - 1; if ( temp_de_list[n]. == 256 )//ImageWidth { temp_de_list[n]. = _new_tiff_width; } if ( temp_de_list[n]. == 257 )//ImageHeight { temp_de_list[n]. = _new_tiff_height; } } delete[] de_list; de_list = NULL; de_list = temp_de_list; _de_num = tag_num; cs_pixel_scale( _scaleX_des , _scaleY_des ); cs_tie_point( _geo_rect_ , _geo_rect_ ); deInfo geo_coord_list[5]; memset( geo_coord_list , 0 , 5 * sizeof( deInfo ) ); cs_coord( geo_coord_list ); mix_proj_de_list( geo_coord_list ); print_tag_info_list(); return _de_num;}void tiffDeform::mix_proj_de_list( deInfo* coord_list ){ deInfo* new_de_list = new deInfo[ _de_num + 5 ]; memset( new_de_list , 0 , sizeof( deInfo ) * ( _de_num + 5 ) ); int i_des = 0 ;

int i_coord = 0 ; if ( _de_num < 5 ) { return ; } int count = 0; for( int i = 0 ; i < _de_num ; i++ ) {

if ( de_list[i]. < coord_list[i_coord]. ) { new_de_list[i_des] = de_list[i]; i_des ++; count ++; } else if ( de_list[i]. >= coord_list[i_coord]. ) { new_de_list[i_des] = coord_list[i_coord]; i_des++; i_coord++; count++; } } if ( i_coord < 5 ) { int temp = i_coord; for ( int i = temp ; i < 5 ; i++ ) { new_de_list[ i_des ] = coord_list[ i_coord ]; i_des ++; i_coord ++; count++; } } delete[] de_list; de_list = NULL; de_list = new_de_list; _de_num = count;}TIFF_UINT64_T tiffDeform::double_to_long( double d_ ){ union { TIFF_UINT64_T i; double f; } u; u.f = d_ ; return u.i ;}void tiffDeform::cs_pixel_scale( double cx , double cy ){ pixel_scale[0] = double_to_long ( cx ); pixel_scale[1] = double_to_long ( cy ); pixel_scale[2] = 0 ;}void tiffDeform::cs_tie_point( double x , double y ){ tie_point[0] = 0; tie_point[1] = 0; tie_point[2] = 0; tie_point[3] = double_to_long( x ) ; tie_point[4] = double_to_long( y ) ; tie_point[5] = 0;}void tiffDeform::cs_coord( deInfo* coord_list ){ coord_list[0]. = 33550;//GeoTagPixelScale coord_list[0]. = 12;//double coord_list[0]. = 3 ; coord_list[0].data_source = 2;//内存数据 coord_list[0].mem_data = ( TIFF_UINT8_T* )pixel_scale; coord_list[1]. = 33922;//GeoTagTiePoint coord_list[1]. = 12;//double coord_list[1]. = 6 ; coord_list[1].data_source = 2;//内存数据 coord_list[1].mem_data = ( TIFF_UINT8_T* )tie_point; coord_list[2]. = 34735;//GeoTagDirectory coord_list[2]. = 3;//short coord_list[2]. = 80; coord_list[2].data_source = 2;//内存数据 coord_list[2].mem_data = ( TIFF_UINT8_T* )geotiff_web_mercator_tag_dir; coord_list[3]. = 34736;//GeoDoubleParamsTag coord_list[3]. = 12;//double coord_list[3]. = 7; coord_list[3].data_source = 2;//内存数据 coord_list[3].mem_data = ( TIFF_UINT8_T* )geotiff_double_param; coord_list[4]. = 34737;//GeoAsciiParamsTag coord_list[4]. = 2;//ascii coord_list[4]. = 64; coord_list[4].data_source = 2;//内存数据 coord_list[4].mem_data = ( TIFF_UINT8_T* )geotiff_ascii_param;}main#include

本文标签: 详解转换需要数据图像