Skip to content

Commit bbe0c37

Browse files
committed
Add QOI image format support
Implements ImageSourceFileQoi and ImageTargetFileQoi for loading and saving QOI (Quite OK Image) format images. QOI provides fast, lossless compression as an alternative to PNG, with 20-50x faster encoding and 3-4x faster decoding. Uses the reference implementation (qoi.h) from github.com/phoboslab/qoi. Adds format registration to all platform initialization paths.
1 parent d45007e commit bbe0c37

12 files changed

Lines changed: 995 additions & 1 deletion

File tree

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
Copyright (c) 2025, The Cinder Project, All rights reserved.
3+
4+
This code is intended for use with the Cinder C++ library: http://libcinder.org
5+
6+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that
7+
the following conditions are met:
8+
9+
* Redistributions of source code must retain the above copyright notice, this list of conditions and
10+
the following disclaimer.
11+
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
12+
the following disclaimer in the documentation and/or other materials provided with the distribution.
13+
14+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
15+
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
16+
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
17+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
18+
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
20+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
21+
POSSIBILITY OF SUCH DAMAGE.
22+
*/
23+
24+
#pragma once
25+
26+
#include "cinder/Cinder.h"
27+
#include "cinder/ImageIo.h"
28+
#include "cinder/Exception.h"
29+
30+
namespace cinder {
31+
32+
typedef std::shared_ptr<class ImageSourceFileQoi> ImageSourceFileQoiRef;
33+
34+
class ImageSourceFileQoi : public ImageSource {
35+
public:
36+
~ImageSourceFileQoi();
37+
38+
static ImageSourceRef create( DataSourceRef dataSourceRef, ImageSource::Options options ) { return ImageSourceFileQoiRef( new ImageSourceFileQoi( dataSourceRef, options ) ); }
39+
40+
static void registerSelf();
41+
42+
void load( ImageTargetRef target ) override;
43+
44+
protected:
45+
ImageSourceFileQoi( DataSourceRef dataSourceRef, ImageSource::Options options );
46+
47+
uint8_t *mData;
48+
size_t mRowBytes;
49+
};
50+
51+
} // namespace cinder
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
Copyright (c) 2025, The Cinder Project, All rights reserved.
3+
4+
This code is intended for use with the Cinder C++ library: http://libcinder.org
5+
6+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that
7+
the following conditions are met:
8+
9+
* Redistributions of source code must retain the above copyright notice, this list of conditions and
10+
the following disclaimer.
11+
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
12+
the following disclaimer in the documentation and/or other materials provided with the distribution.
13+
14+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
15+
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
16+
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
17+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
18+
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
20+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
21+
POSSIBILITY OF SUCH DAMAGE.
22+
*/
23+
24+
#pragma once
25+
26+
#include "cinder/ImageIo.h"
27+
28+
namespace cinder {
29+
30+
typedef std::shared_ptr<class ImageTargetFileQoi> ImageTargetFileQoiRef;
31+
32+
class ImageTargetFileQoi : public ImageTarget {
33+
public:
34+
static ImageTargetRef create( DataTargetRef dataTarget, ImageSourceRef imageSource, ImageTarget::Options options, const std::string &extensionData );
35+
36+
void* getRowPointer( int32_t row ) override;
37+
void finalize() override;
38+
39+
static void registerSelf();
40+
41+
protected:
42+
ImageTargetFileQoi( DataTargetRef dataTarget, ImageSourceRef imageSource, ImageTarget::Options options, const std::string &extensionData );
43+
44+
uint8_t mNumComponents;
45+
size_t mRowBytes;
46+
fs::path mFilePath;
47+
std::unique_ptr<uint8_t[]> mData;
48+
DataTargetRef mDataTarget;
49+
};
50+
51+
} // namespace cinder

0 commit comments

Comments
 (0)