Set reader position to given position, * either absolute or relative to the * current one: */
| 1030 | * current one: |
| 1031 | */ |
| 1032 | CV_IMPL void |
| 1033 | cvSetSeqReaderPos( CvSeqReader* reader, int index, int is_relative ) |
| 1034 | { |
| 1035 | CvSeqBlock *block; |
| 1036 | int elem_size, count, total; |
| 1037 | |
| 1038 | if( !reader || !reader->seq ) |
| 1039 | CV_Error( CV_StsNullPtr, "" ); |
| 1040 | |
| 1041 | total = reader->seq->total; |
| 1042 | elem_size = reader->seq->elem_size; |
| 1043 | |
| 1044 | if( !is_relative ) |
| 1045 | { |
| 1046 | if( index < 0 ) |
| 1047 | { |
| 1048 | if( index < -total ) |
| 1049 | CV_Error( CV_StsOutOfRange, "" ); |
| 1050 | index += total; |
| 1051 | } |
| 1052 | else if( index >= total ) |
| 1053 | { |
| 1054 | index -= total; |
| 1055 | if( index >= total ) |
| 1056 | CV_Error( CV_StsOutOfRange, "" ); |
| 1057 | } |
| 1058 | |
| 1059 | block = reader->seq->first; |
| 1060 | if( index >= (count = block->count) ) |
| 1061 | { |
| 1062 | if( index + index <= total ) |
| 1063 | { |
| 1064 | do |
| 1065 | { |
| 1066 | block = block->next; |
| 1067 | index -= count; |
| 1068 | } |
| 1069 | while( index >= (count = block->count) ); |
| 1070 | } |
| 1071 | else |
| 1072 | { |
| 1073 | do |
| 1074 | { |
| 1075 | block = block->prev; |
| 1076 | total -= block->count; |
| 1077 | } |
| 1078 | while( index < total ); |
| 1079 | index -= total; |
| 1080 | } |
| 1081 | } |
| 1082 | reader->ptr = block->data + index * elem_size; |
| 1083 | if( reader->block != block ) |
| 1084 | { |
| 1085 | reader->block = block; |
| 1086 | reader->block_min = block->data; |
| 1087 | reader->block_max = block->data + block->count * elem_size; |
| 1088 | } |
| 1089 | } |
no outgoing calls
no test coverage detected