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
|
//
// C++ Implementation: k9saveimage
//
// Description:
//
//
// Author: Jean-Michel PETIT <k9copy@free.fr>, (C) 2007
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include "k9saveimage.h"
#include "kdecmpeg2.h"
#include <stdio.h>
#include <tqimage.h>
#include <kstandarddirs.h>
void k9SaveImage::drawImage(TQImage *_image) {
m_cpt++;
if (m_cpt ==20) {
m_image=*_image;
m_decoder->pause();
}
}
k9SaveImage::k9SaveImage()
: TQObject(),TQThread()
{
m_tempFile= new KTempFile(locateLocal("tmp", "k9copy/k9p"), "");
m_tempFile->setAutoDelete(true);
m_decoder=new kDecMPEG2();
connect(m_decoder, TQT_SIGNAL(pixmapReady(TQImage *)), this, TQT_SLOT(drawImage(TQImage *)));
}
k9SaveImage::~k9SaveImage()
{
delete m_decoder;
delete m_tempFile;
}
void k9SaveImage::play() {
m_cpt=0;
m_stop=false;
m_timer.start();
m_decoder->start();
}
void k9SaveImage::stop() {
m_stop=true;
wait();
m_decoder->stop();
}
void k9SaveImage::addData(uchar *_buffer, uint32_t _size) {
if (m_timer.elapsed() >=7000 ) {
if (m_mutex.tryLock()) {
m_size=_size;
m_buffer=new uchar[m_size];
tc_memcpy(m_buffer,_buffer,m_size);
m_mutex.unlock();
start(LowestPriority);
}
m_timer.restart();
}
}
void k9SaveImage::run() {
m_mutex.lock();
m_cpt=0;
m_decoder->decode(m_buffer ,m_buffer+m_size,0);
delete m_buffer;
TQString sFileName=m_tempFile->name();
m_image.save(sFileName,"PNG");
sFileName="\rINFOIMAGE:"+sFileName;
fprintf(stderr,sFileName.utf8());
m_mutex.unlock();
}
#include "k9saveimage.moc"
|