author | František Kučera <franta-hg@frantovo.cz> |
Sun, 03 Dec 2023 00:57:54 +0100 | |
branch | v_0 |
changeset 13 | 82bb4fe2fd4a |
parent 1 | fb65455622b9 |
permissions | -rw-r--r-- |
0 | 1 |
/** |
2 |
* ShaderShark |
|
3 |
* Copyright © 2023 František Kučera (Frantovo.cz, GlobalCode.info) |
|
4 |
* |
|
5 |
* This program is free software: you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation, version 3 of the License. |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 |
*/ |
|
17 |
||
1
fb65455622b9
load textures from PNG, JPEG etc. files using ImageMagick
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
18 |
#include <iostream> |
0 | 19 |
|
1
fb65455622b9
load textures from PNG, JPEG etc. files using ImageMagick
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
20 |
#include <Magick++.h> |
0 | 21 |
|
1
fb65455622b9
load textures from PNG, JPEG etc. files using ImageMagick
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
22 |
#include "ImageLoader.h" |
fb65455622b9
load textures from PNG, JPEG etc. files using ImageMagick
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
23 |
#include "AllocatedBuffer.h" |
0 | 24 |
|
1
fb65455622b9
load textures from PNG, JPEG etc. files using ImageMagick
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
25 |
ImageLoader::ImageBuffer* ImageLoader::loadImage(const Buffer& input) { |
fb65455622b9
load textures from PNG, JPEG etc. files using ImageMagick
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
26 |
Magick::Blob inputBlob(input.getData(), input.getSize()); |
fb65455622b9
load textures from PNG, JPEG etc. files using ImageMagick
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
27 |
Magick::Image image(inputBlob); |
13
82bb4fe2fd4a
ImageLoader: convert images always to 8-bit depth as expected by Shark.cpp (i.e. 16-bit images can be loaded now)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
28 |
// Magick::Image image("magick:LOGO"); |
82bb4fe2fd4a
ImageLoader: convert images always to 8-bit depth as expected by Shark.cpp (i.e. 16-bit images can be loaded now)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
29 |
// Magick::Image image("magick:WIZARD"); |
82bb4fe2fd4a
ImageLoader: convert images always to 8-bit depth as expected by Shark.cpp (i.e. 16-bit images can be loaded now)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
30 |
// Magick::Image image("https://.../remote-image.png"); |
82bb4fe2fd4a
ImageLoader: convert images always to 8-bit depth as expected by Shark.cpp (i.e. 16-bit images can be loaded now)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
31 |
// Magick::Image image("x:root"); // whole desktop |
82bb4fe2fd4a
ImageLoader: convert images always to 8-bit depth as expected by Shark.cpp (i.e. 16-bit images can be loaded now)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
32 |
// Magick::Image image("x:0x6a0001c"); // single window, use e.g. xwininfo |
0 | 33 |
|
1
fb65455622b9
load textures from PNG, JPEG etc. files using ImageMagick
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
34 |
// Magick::PixelPacket* parsedPixels = parsedImage.getPixels( |
fb65455622b9
load textures from PNG, JPEG etc. files using ImageMagick
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
35 |
// 0, 0, parsedImage.size().width(), parsedImage.size().height()); |
fb65455622b9
load textures from PNG, JPEG etc. files using ImageMagick
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
36 |
|
fb65455622b9
load textures from PNG, JPEG etc. files using ImageMagick
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
37 |
Magick::Blob outputBlob; |
fb65455622b9
load textures from PNG, JPEG etc. files using ImageMagick
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
38 |
image.magick("RGBA"); |
13
82bb4fe2fd4a
ImageLoader: convert images always to 8-bit depth as expected by Shark.cpp (i.e. 16-bit images can be loaded now)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
39 |
image.depth(8); // TODO: pass more bits to OpenGL? |
1
fb65455622b9
load textures from PNG, JPEG etc. files using ImageMagick
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
40 |
image.write(&outputBlob); |
0 | 41 |
|
1
fb65455622b9
load textures from PNG, JPEG etc. files using ImageMagick
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
42 |
ImageBuffer* outputBuffer = new ImageBuffer( |
fb65455622b9
load textures from PNG, JPEG etc. files using ImageMagick
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
43 |
(void*) outputBlob.data(), |
fb65455622b9
load textures from PNG, JPEG etc. files using ImageMagick
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
44 |
outputBlob.length(), |
fb65455622b9
load textures from PNG, JPEG etc. files using ImageMagick
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
45 |
image.size().width(), |
fb65455622b9
load textures from PNG, JPEG etc. files using ImageMagick
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
46 |
image.size().height()); |
0 | 47 |
|
1
fb65455622b9
load textures from PNG, JPEG etc. files using ImageMagick
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
48 |
return outputBuffer; |
fb65455622b9
load textures from PNG, JPEG etc. files using ImageMagick
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
49 |
} |