forked from Vorago/iwb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpresentation.cpp
More file actions
211 lines (172 loc) · 7.69 KB
/
presentation.cpp
File metadata and controls
211 lines (172 loc) · 7.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/*
* File: presentation.cpp
* Author: vorago
*
* Created on December 29, 2010, 11:42 PM
*/
#include "include/presentation.hpp"
#include <stdio.h>
#include <QtGui/QApplication>
#include <QtGui/QDesktopWidget>
namespace iwb {
Presentation::Presentation() {
this->screenHeight = QApplication::desktop()->height();
this->screenWidth = QApplication::desktop()->width();
this->window = new MainWindow;
this->window->show();
this->window->showFullScreen();
buffer = cvCreateImage(cvSize(screenWidth, screenHeight), IPL_DEPTH_8U, 3);
slide = cvCreateImage(cvSize(screenWidth, screenHeight), IPL_DEPTH_8U, 3);
qImageBuffer = (uchar *) malloc (screenWidth *screenHeight* 5 * sizeof (uchar));
// this->leftOffset = 10;
// this->rightOffset = 10;
// this->topOffset = 10;
// this->bottomOffset = 10;
}
Presentation::~Presentation() {
cvReleaseImage(&buffer);
cvReleaseImage(&slide);
free(qImageBuffer);
delete (this->window);
}
/* TODO: Check that the image really fits after calculating the new position */
void Presentation::putImage(CvPoint upperLeft, CvPoint lowerRight,
CvPoint *OutupperLeft, CvPoint *OutlowerRight, IplImage* image) {
//calculations of new images coodrinates with respect to offset
int width = (lowerRight.x - upperLeft.x);
// (int) ((double) (leftOffset+rightOffset)*(double)(this->screenWidth)/(double)(image->width));
int height = (lowerRight.y - upperLeft.y);
// (int) ((double) (topOffset+bottomOffset)*(double)(this->screenHeight)/(double)image->height);
// int width = (lowerRight.x - upperLeft.x) -
// (int) ((double) (leftOffset+rightOffset)*(double)(this->screenWidth)/(double)(image->width));
// int height = (lowerRight.y - upperLeft.y) -
// (int) ((double) (topOffset+bottomOffset)*(double)(this->screenHeight)/(double)image->height);
/* Point = OldPoint + (oldsize-newsize)/2 + offset */
// upperLeft.x = upperLeft.x + leftOffset;
// upperLeft.y = upperLeft.y + bottomOffset;
/*
* TODO:
* To shrink a photo, it will generally look best with CV_INTER_AREA
* interpolation, whereas to enlarge an image, it will generally look
* best with CV_INTER_CUBIC (slow) or CV_INTER_LINEAR (faster but still
* looks OK).
*/
IplImage* resizedImage = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3);
cvResize(image, resizedImage, CV_INTER_CUBIC);
//Setting area for new image
cvSetImageROI(buffer, cvRect(upperLeft.x, upperLeft.y, width, height));
cvZero(buffer);
cvCopyImage(resizedImage, buffer);
cvResetImageROI(buffer);
cvReleaseImage(&resizedImage);
if (OutupperLeft != NULL){
OutupperLeft->x = upperLeft.x;
OutupperLeft->y = upperLeft.y;
}
if (OutlowerRight != NULL){
OutlowerRight->x = upperLeft.x + width;
OutlowerRight->y = upperLeft.y + height;
}
}
/* It doesn't take in account the offsets */
void Presentation::clearArea(CvPoint upperLeft, CvPoint lowerRight) {
CvScalar color = CV_RGB(0, 0, 0);
cvRectangle(buffer, upperLeft, lowerRight, color, CV_FILLED, 0, 0);
}
void Presentation::applyBuffer() {
cvCopy(buffer, slide);
/* WARNING:
* I've considered that we'll always use the same settings
* to capture the image (from above):
* IPL_DEPTH_8U with 3 channels
* If not: look for a good way to calculate here:
* http://www.qtcentre.org/threads/11655-OpenCV-integration
*/
uchar *QImagePtr = qImageBuffer;
const uchar *iplImagePtr = (const uchar *)this->slide->imageData;
for (int y = 0; y < slide->height; ++y){
for (int x = 0; x < slide->width; ++x){
// We cannot help but copy manually.
QImagePtr[0] = iplImagePtr[0];
QImagePtr[1] = iplImagePtr[1];
QImagePtr[2] = iplImagePtr[2];
QImagePtr[3] = 0;
QImagePtr += 4;
iplImagePtr += 3;
}
iplImagePtr += slide->widthStep - 3 * slide->width;
}
QImage *qImage = new QImage (qImageBuffer, slide->width, slide->height, QImage::Format_RGB32);
//free(qImageBuffer);
delete (this->window->qimage);
this->window->qimage = qImage;
this->window->update();
// free(qImageBuffer);
}
int Presentation::getScreenWidth(){
return screenWidth;
}
int Presentation::getScreenHeight(){
return screenHeight;
}
// void Presentation::drawScroller(const char *image1, const char *image2,
// const char *image3, IplImage* leftArrow, IplImage *rightArrow){
// char filepath[80];
// snprintf(filepath, sizeof(filepath), "tmp/1/%s", image1);
// IplImage *img1 = cvLoadImage(filepath, CV_LOAD_IMAGE_UNCHANGED);
// snprintf(filepath, sizeof(filepath), "tmp/1/%s", image2);
// IplImage *img2 = cvLoadImage(filepath, CV_LOAD_IMAGE_UNCHANGED);
// snprintf(filepath, sizeof(filepath), "tmp/1/%s", image3);
// IplImage *img3 = cvLoadImage(filepath, CV_LOAD_IMAGE_UNCHANGED);
// /* Each image occupies 17% of scroller height and 67% of scroller lenght
// * Each arrow occupies 7% of scroller height and 50% of scroller lenght
// * Space between images and images and arrows - 7%
// */
// //calculations of relative coordinates
// putImage(this->scrollerUL[0],this->scrollerBR[0], NULL, NULL, leftArrow);
// putImage(this->scrollerUL[1],this->scrollerBR[1], NULL, NULL, img1);
// putImage(this->scrollerUL[2],this->scrollerBR[2], NULL, NULL, img2);
// putImage(this->scrollerUL[3],this->scrollerBR[3], NULL, NULL, img3);
// putImage(this->scrollerUL[4],this->scrollerBR[4], NULL, NULL, rightArrow);
//
// applyBuffer();
// }
// void Presentation::drawConfirmation() {
//
// IplImage *yesButton = cvLoadImage("res/left.jpg", CV_LOAD_IMAGE_UNCHANGED);
// IplImage *noButton = cvLoadImage("res/right.jpg", CV_LOAD_IMAGE_UNCHANGED);
//
//// putImage(cvPoint(10, 10), cvPoint(50, 50), yesButton);
//// putImage(cvPoint(60, 10), cvPoint(110, 50), noButton);
//// putImage(cvPoint(scrollerUL[0].x, scrollerUL[0].y), cvPoint(scrollerBR[0].x, scrollerBR[0].y), yesButton);
//// putImage(cvPoint(scrollerUL[1].x, scrollerUL[1].y), cvPoint(scrollerBR[1].x, scrollerBR[1].y), noButton);
// printf("ul: %d,%d , br: %d,%d", confirmationUL[0].x, confirmationUL[0].y, confirmationBR[0].x, confirmationBR[0].y);
//
// putImage(confirmationUL[0],confirmationBR[0], NULL, NULL, yesButton);
// putImage(confirmationUL[1], confirmationBR[1], NULL, NULL, noButton);
//
//
// applyBuffer();
// }
void Presentation::drawComponents() {
for (std::list<Drawable*>::iterator component = components.begin(); component != components.end(); component++) {
(*component)->draw(this);
}
applyBuffer();
}
void Presentation::addComponent(Drawable* component) {
components.push_back(component);
}
void Presentation::removeComponent(Drawable* component) {
components.remove(component);
}
void Presentation::drawDiff(IplImage* diff) {
CvPoint o, p;
o.x = 0;
o.y = 0;
p.x = screenWidth;
p.y = screenHeight;
putImage(o,p, 0, 0, diff);
applyBuffer();
}
}