• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

okteta

  • sources
  • kde-4.12
  • kdesdk
  • okteta
  • kasten
  • controllers
  • view
  • libbytearrayfilter
  • filter
rotatebytearrayfilter.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the Okteta Kasten module, made within the KDE community.
3 
4  Copyright 2008 Friedrich W. H. Kossebau <kossebau@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) version 3, or any
10  later version accepted by the membership of KDE e.V. (or its
11  successor approved by the membership of KDE e.V.), which shall
12  act as a proxy defined in Section 6 of version 3 of the license.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 #include "rotatebytearrayfilter.h"
24 
25 // Okteta core
26 #include <abstractbytearraymodel.h>
27 // KDE
28 #include <KLocale>
29 // Qt
30 #include <QtCore/QtGlobal>
31 
32 static const int RotateBitsPerByte = 8;
33 
34 RotateByteArrayFilter::RotateByteArrayFilter()
35  : AbstractByteArrayFilter(
36  i18nc("name of the filter; it moves the bits and pushes the ones over the end to the begin again",
37  "ROTATE data") )
38 {}
39 
40 AbstractByteArrayFilterParameterSet *RotateByteArrayFilter::parameterSet() { return &mParameterSet; }
41 
42 bool RotateByteArrayFilter::filter( Okteta::Byte* result,
43  Okteta::AbstractByteArrayModel *model, const Okteta::AddressRange& range ) const
44 {
45  const int groupSize = mParameterSet.groupSize();
46  const int groupBitCount = (groupSize * RotateBitsPerByte );
47  const int groupShiftBitWidth = qAbs( mParameterSet.moveBitWidth() ) % groupBitCount;
48 
49  const int shiftByteWidth = groupShiftBitWidth / RotateBitsPerByte;
50  const int shiftBitWidth = groupShiftBitWidth - shiftByteWidth * RotateBitsPerByte;
51  const int otherShiftBitWidth = RotateBitsPerByte - shiftBitWidth;
52  int filteredBytesCount = 0;
53 
54  const bool toRight = ( mParameterSet.moveBitWidth() > 0 );
55  if( toRight )
56  {
57  int r = 0;
58  Okteta::Address m = range.start();
59  while( m <= range.end() )
60  {
61  int g = 0;
62  // round the edge byte layer shift
63  while( g < shiftByteWidth && m+groupSize <= range.end() )
64  {
65  result[r++] = model->byte( (m++)+groupSize-shiftByteWidth );
66  ++g;
67  }
68  // normal byte layer shift
69  while( g < groupSize && m <= range.end() )
70  {
71  result[r++] = model->byte( (m++)-shiftByteWidth );
72  ++g;
73  }
74 
75  // bit layer shift
76  const unsigned char last = (unsigned char) result[r-1];
77  for( int b=1; b<=g; ++b )
78  {
79  result[r-b] = (unsigned char)result[r-b]>>shiftBitWidth;
80  if( b < g )
81  result[r-b] |= (unsigned char)result[r-b-1]<<otherShiftBitWidth;
82  else if( g == groupSize )
83  result[r-b] |= last<<otherShiftBitWidth;
84  }
85 
86  filteredBytesCount += g;
87  if( filteredBytesCount >= FilteredByteCountSignalLimit )
88  {
89  filteredBytesCount = 0;
90  emit filteredBytes( m-range.start() );
91  }
92  }
93  }
94  else
95  {
96  int r = 0;
97  Okteta::Address m = range.start();
98  while( m <= range.end() )
99  {
100  int g = 0;
101  // normal byte layer shift
102  while( g+shiftByteWidth < groupSize && m+shiftByteWidth <= range.end() )
103  {
104  result[r++] = model->byte( (m++)-shiftByteWidth );
105  ++g;
106  }
107  // round the edge byte layer shift
108  while( g < groupSize && m <= range.end() )
109  {
110  result[r++] = model->byte( (m++)+shiftByteWidth-groupSize );
111  ++g;
112  }
113 
114  // bit layer shift
115  const unsigned char first = result[r-g];
116  for( int b=g; b>0; --b )
117  {
118  result[r-b] = (unsigned char)result[r-b] << shiftBitWidth;
119  if( b > 1 )
120  result[r-b] |= (unsigned char)result[r-b+1] >> otherShiftBitWidth;
121  else if( g == groupSize )
122  result[r-b] |= first >> otherShiftBitWidth;
123  }
124 
125  filteredBytesCount += g;
126  if( filteredBytesCount >= FilteredByteCountSignalLimit )
127  {
128  filteredBytesCount = 0;
129  emit filteredBytes( m-range.start() );
130  }
131  }
132  }
133 
134  return true;
135 }
136 
137 RotateByteArrayFilter::~RotateByteArrayFilter() {}
Okteta::Address
qint32 Address
Definition: address.h:34
Okteta::AbstractByteArrayModel
could it be useful to hide the data access behind an iterator? * class KDataBufferIterator { public: ...
Definition: abstractbytearraymodel.h:79
abstractbytearraymodel.h
RotateByteArrayFilterParameterSet::moveBitWidth
int moveBitWidth() const
Definition: rotatebytearrayfilterparameterset.cpp:32
rotatebytearrayfilter.h
RotateBitsPerByte
static const int RotateBitsPerByte
Definition: rotatebytearrayfilter.cpp:32
KDE::NumberRange< Address, Size >
KDE::Range::start
T start() const
Definition: range.h:86
Okteta::Byte
unsigned char Byte
Definition: byte.h:29
AbstractByteArrayFilter
Definition: abstractbytearrayfilter.h:39
RotateByteArrayFilter::filter
virtual bool filter(Okteta::Byte *result, Okteta::AbstractByteArrayModel *model, const Okteta::AddressRange &range) const
Definition: rotatebytearrayfilter.cpp:42
RotateByteArrayFilterParameterSet::groupSize
int groupSize() const
Definition: rotatebytearrayfilterparameterset.cpp:31
RotateByteArrayFilter::mParameterSet
RotateByteArrayFilterParameterSet mParameterSet
Definition: rotatebytearrayfilter.h:44
RotateByteArrayFilter::~RotateByteArrayFilter
virtual ~RotateByteArrayFilter()
Definition: rotatebytearrayfilter.cpp:137
KDE::Range::end
T end() const
Definition: range.h:88
Okteta::AbstractByteArrayModel::byte
virtual Byte byte(Address offset) const =0
locates working range The idea behind is to tell buffer which range will be requested in the followin...
AbstractByteArrayFilter::FilteredByteCountSignalLimit
static const int FilteredByteCountSignalLimit
Definition: abstractbytearrayfilter.h:44
AbstractByteArrayFilter::filteredBytes
void filteredBytes(int bytes) const
RotateByteArrayFilter::parameterSet
virtual AbstractByteArrayFilterParameterSet * parameterSet()
used by the editor to get write access to the parameters
Definition: rotatebytearrayfilter.cpp:40
AbstractByteArrayFilterParameterSet
Definition: abstractbytearrayfilterparameterset.h:27
char
RotateByteArrayFilter::RotateByteArrayFilter
RotateByteArrayFilter()
Definition: rotatebytearrayfilter.cpp:34
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:09 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

okteta

Skip menu "okteta"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal