Instrument Neutral Distributed Interface INDI 2.2.5
rawencoder.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2017 by Jasem Mutlaq <[email protected]>
3
4 INDI Raw Encoder
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) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
20*/
21
22#include "rawencoder.h"
24#include "indiccd.h"
25
26#include <zlib.h>
27
28namespace INDI
29{
30
32{
33 name = "RAW";
34}
35
39
40const char *RawEncoder::getDeviceName()
41{
43}
44
45bool RawEncoder::upload(INDI::WidgetViewBlob *bp, const uint8_t *buffer, uint32_t nbytes, bool isCompressed)
46{
47 // Do we want to compress ?
48 if (isCompressed)
49 {
50 // Compress frame
51 compressedFrame.resize(nbytes + nbytes / 64 + 16 + 3);
52 uLongf compressedBytes = compressedFrame.size();
53
54 int ret = compress2(compressedFrame.data(), &compressedBytes, buffer, nbytes, 4);
55 if (ret != Z_OK)
56 {
57 // this should NEVER happen
58 LOGF_ERROR("internal error - compression failed: %d", ret);
59 return false;
60 }
61
62 // Send it compressed
63 bp->setBlob(compressedFrame.data());
64 bp->setBlobLen(compressedBytes);
65 bp->setSize(nbytes);
66 bp->setFormat(".stream.z");
67 }
68 else
69 {
70 // Send it uncompressed
71 bp->setBlob((const_cast<uint8_t *>(buffer)));
72 bp->setBlobLen(nbytes);
73 bp->setSize(nbytes);
74 bp->setFormat(".stream");
75 }
76
77 return true;
78}
79}
const char * getDeviceName() const
INDI::DefaultDevice * currentDevice
virtual bool upload(INDI::WidgetViewBlob *bp, const uint8_t *buffer, uint32_t nbytes, bool isCompressed=false) override
#define LOGF_ERROR(fmt,...)
Definition indilogger.h:80
Namespace to encapsulate INDI client, drivers, and mediator classes.
void setFormat(const char *format)