summaryrefslogtreecommitdiff
path: root/libopie2
authoralwin <alwin>2005-03-24 21:13:40 (UTC)
committer alwin <alwin>2005-03-24 21:13:40 (UTC)
commitb6fc9840f4fe9bad392167c49dbcfa2acda9ed21 (patch) (side-by-side diff)
tree1d7d1225a9c440f5d0608d8901dfd151db8a6f1c /libopie2
parent1e6c3181dcc7ec4edbe99db0d886ce7a9c483056 (diff)
downloadopie-b6fc9840f4fe9bad392167c49dbcfa2acda9ed21.zip
opie-b6fc9840f4fe9bad392167c49dbcfa2acda9ed21.tar.gz
opie-b6fc9840f4fe9bad392167c49dbcfa2acda9ed21.tar.bz2
last bugfixes on opie-eye an imagescrollview. Seems that now all is working
as it should.
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiemm/oimagescrollview.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/libopie2/opiemm/oimagescrollview.cpp b/libopie2/opiemm/oimagescrollview.cpp
index 10da823..76f50e1 100644
--- a/libopie2/opiemm/oimagescrollview.cpp
+++ b/libopie2/opiemm/oimagescrollview.cpp
@@ -160,96 +160,97 @@ void OImageScrollView::init()
_zoomer, (SLOT(setVisiblePoint(int,int))) );
connect(this,SIGNAL(imageSizeChanged(const QSize&)),
_zoomer, SLOT(setImageSize(const QSize&)) );
connect(this,SIGNAL(viewportSizeChanged(const QSize&)),
_zoomer, SLOT(setViewPortSize(const QSize&)) );
setBackgroundColor(white);
setFocusPolicy(QWidget::StrongFocus);
setImageScaledLoaded(false);
setImageIsJpeg(false);
if (FirstResizeDone()) {
m_last_rot = Rotate0;
generateImage();
} else if (_original_data.size().isValid()) {
if (image_fit_into(_original_data.size()) || !ShowZoomer()) _zoomer->hide();
resizeContents(_original_data.width(),_original_data.height());
}
_intensity = 0;
}
void OImageScrollView::setAutoRotate(bool how)
{
/* to avoid double repaints */
if (AutoRotate() != how) {
m_states.setBit(AUTO_ROTATE,how);
_image_data = QImage();
generateImage();
}
}
bool OImageScrollView::AutoRotate()const
{
return m_states.testBit(AUTO_ROTATE);
}
void OImageScrollView::setAutoScaleRotate(bool scale, bool rotate)
{
m_states.setBit(AUTO_ROTATE,rotate);
setAutoScale(scale);
}
void OImageScrollView::setAutoScale(bool how)
{
m_states.setBit(AUTO_SCALE,how);
_image_data = QImage();
if (ImageIsJpeg() && how == false && ImageScaledLoaded()==true) {
loadJpeg(true);
}
+ _newImage = true;
generateImage();
}
bool OImageScrollView::AutoScale()const
{
return m_states.testBit(AUTO_SCALE);
}
OImageScrollView::~OImageScrollView()
{
}
void OImageScrollView::rescaleImage(int w, int h)
{
if (_image_data.width()==w && _image_data.height()==h) {
return;
}
double hs = (double)h / (double)_image_data.height() ;
double ws = (double)w / (double)_image_data.width() ;
double scaleFactor = (hs > ws) ? ws : hs;
int smoothW = (int)(scaleFactor * _image_data.width());
int smoothH = (int)(scaleFactor * _image_data.height());
_image_data = _image_data.smoothScale(smoothW,smoothH);
}
void OImageScrollView::rotate_into_data(Rotation r)
{
/* realy - we must do this that way, 'cause when acting direct on _image_data the app will
segfault :( */
QImage dest;
int x, y;
if ( _original_data.depth() > 8 )
{
unsigned int *srcData, *destData;
switch ( r )
{
case Rotate90:
dest.create(_original_data.height(), _original_data.width(), _original_data.depth());
for ( y=0; y < _original_data.height(); ++y )
{
srcData = (unsigned int *)_original_data.scanLine(y);
for ( x=0; x < _original_data.width(); ++x )
{
destData = (unsigned int *)dest.scanLine(x);
destData[_original_data.height()-y-1] = srcData[x];
}
}
break;
@@ -303,98 +304,100 @@ void OImageScrollView::rotate_into_data(Rotation r)
}
}
break;
case Rotate180:
dest.create(_original_data.width(), _original_data.height(), _original_data.depth());
dest.setNumColors(_original_data.numColors());
srcTable = (unsigned int *)_original_data.colorTable();
destTable = (unsigned int *)dest.colorTable();
for ( x=0; x < _original_data.numColors(); ++x )
destTable[x] = srcTable[x];
for ( y=0; y < _original_data.height(); ++y )
{
srcData = (unsigned char *)_original_data.scanLine(y);
destData = (unsigned char *)dest.scanLine(_original_data.height()-y-1);
for ( x=0; x < _original_data.width(); ++x )
destData[_original_data.width()-x-1] = srcData[x];
}
break;
case Rotate270:
dest.create(_original_data.height(), _original_data.width(), _original_data.depth());
dest.setNumColors(_original_data.numColors());
srcTable = (unsigned int *)_original_data.colorTable();
destTable = (unsigned int *)dest.colorTable();
for ( x=0; x < _original_data.numColors(); ++x )
destTable[x] = srcTable[x];
for ( y=0; y < _original_data.height(); ++y )
{
srcData = (unsigned char *)_original_data.scanLine(y);
for ( x=0; x < _original_data.width(); ++x )
{
destData = (unsigned char *)dest.scanLine(_original_data.width()-x-1);
destData[y] = srcData[x];
}
}
break;
default:
dest = _original_data;
break;
}
}
_newImage = true;
_image_data = dest;
}
// yes - sorry - it is NOT gamma it is just BRIGHTNESS. Alwin
void OImageScrollView::apply_gamma(int aValue)
{
- if (!_image_data.size().isValid()) return;
+ if (aValue==0 || !_image_data.size().isValid()) return;
float percent = ((float)aValue/100.0);
+ /* make sure working on a copy */
+ _image_data.detach();
int segColors = _image_data.depth() > 8 ? 256 : _image_data.numColors();
/* must be - otherwise it displays some ... strange colors */
if (segColors<256) segColors=256;
unsigned char *segTbl = new unsigned char[segColors];
int pixels = _image_data.depth()>8?_image_data.width()*_image_data.height() : _image_data.numColors();
bool brighten = (percent >= 0);
if ( percent < 0 ) {
percent = -percent;
}
unsigned int *data = _image_data.depth() > 8 ? (unsigned int *)_image_data.bits() :
(unsigned int *)_image_data.colorTable();
int tmp = 0;
if (brighten) {
for ( int i=0; i < segColors; ++i )
{
tmp = (int)(i*percent);
if ( tmp > 255 )
tmp = 255;
segTbl[i] = tmp;
}
} else {
for ( int i=0; i < segColors; ++i )
{
tmp = (int)(i*percent);
if ( tmp < 0 )
tmp = 0;
segTbl[i] = tmp;
}
}
if (brighten) {
for ( int i=0; i < pixels; ++i )
{
int r = qRed(data[i]);
int g = qGreen(data[i]);
int b = qBlue(data[i]);
int a = qAlpha(data[i]);
r = r + segTbl[r] > 255 ? 255 : r + segTbl[r];
g = g + segTbl[g] > 255 ? 255 : g + segTbl[g];
b = b + segTbl[b] > 255 ? 255 : b + segTbl[b];
data[i] = qRgba(r, g, b,a);
}