ImageLoader.cpp
author František Kučera <franta-hg@frantovo.cz>
Tue, 26 Dec 2023 23:46:45 +0100
branchv_0
changeset 28 4cbd9c0beb4c
parent 13 82bb4fe2fd4a
permissions -rw-r--r--
pass texture xattr 'shader-shark.texture.scale' to the shaders as 'uTextureScale' + update variable locations on each shader reload
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
bb715a82a8f1 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
/**
bb715a82a8f1 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
 * ShaderShark
bb715a82a8f1 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
 * Copyright © 2023 František Kučera (Frantovo.cz, GlobalCode.info)
bb715a82a8f1 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
 *
bb715a82a8f1 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     5
 * This program is free software: you can redistribute it and/or modify
bb715a82a8f1 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
bb715a82a8f1 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
 * the Free Software Foundation, version 3 of the License.
bb715a82a8f1 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
 *
bb715a82a8f1 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
bb715a82a8f1 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
bb715a82a8f1 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bb715a82a8f1 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
 * GNU General Public License for more details.
bb715a82a8f1 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
 *
bb715a82a8f1 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
bb715a82a8f1 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
bb715a82a8f1 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
 */
bb715a82a8f1 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    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
bb715a82a8f1 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    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
bb715a82a8f1 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    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
bb715a82a8f1 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    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
bb715a82a8f1 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    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
bb715a82a8f1 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    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
bb715a82a8f1 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    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
}