Skip to content

Commit 0552615

Browse files
committed
Add documentation for image formats
1 parent f5a264f commit 0552615

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

Doxyfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,7 @@ EXCLUDE_SYMLINKS = NO
975975

976976
EXCLUDE_PATTERNS = */internal/* \
977977
*/src/blocks/* \
978+
*/src/imageformats/* \
978979
*_p.cpp \
979980
*_p.h
980981

docs/Image formats.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
\page imageFormats Image formats
2+
3+
To work with costumes, libscratchcpp has to read image files from Scratch projects.
4+
No formats are currently supported, but that will change soon.
5+
6+
# Implementing a custom image format
7+
To implement a custom image format that libscratchcpp doesn't support,
8+
subclass \link libscratchcpp::IImageFormat IImageFormat \endlink
9+
and override all of the methods.
10+
11+
Then subclass \link libscratchcpp::IImageFormatFactory IImageFormatFactory \endlink
12+
and override \link libscratchcpp::IImageFormatFactory::createInstance() createInstance() \endlink.
13+
14+
It's recommended to use the libscratchcpp namespace like this in your classes:
15+
```cpp
16+
using namespace libscratchcpp;
17+
```
18+
19+
Here's an example of the `createInstance()` method:
20+
```cpp
21+
std::shared_ptr<IImageFormat> TiffImageFormatFactory::createInstance() {
22+
return std::make_shared<TiffImageFormat>();
23+
}
24+
```
25+
26+
# Registering the image format
27+
To register the image format, you need to register the factory class.
28+
It will be used by classes such as \link libscratchcpp::Costume Costume \endlink
29+
internally to instantiate your image format.
30+
31+
```cpp
32+
libscratchcpp::ScratchConfiguration::registerImageFormat("tiff", std::make_shared<TiffImageFormatFactory>());
33+
```

0 commit comments

Comments
 (0)