ares-openbsd/nall/image.hpp

195 行
6.5 KiB
C++
Raw 通常表示 履歴

#pragma once
#include <algorithm>
#include <nall/file-map.hpp>
#include <nall/interpolation.hpp>
#include <nall/stdint.hpp>
#include <nall/decode/bmp.hpp>
Update to v094r09 release. byuu says: This will easily be the biggest diff in the history of higan. And not in a good way. * target-higan and target-loki have been blown away completely * nall and ruby massively updated * phoenix replaced with hiro (pretty near a total rewrite) * target-higan restarted using hiro (just a window for now) * all emulation cores updated to compile again * installation changed to not require root privileges (installs locally) For the foreseeable future (maybe even permanently?), the new higan UI will only build under Linux/BSD with GTK+ 2.20+. Probably the most likely route for Windows/OS X will be to try and figure out how to build hiro/GTK on those platforms, as awful as that would be. The other alternative would be to produce new UIs for those platforms ... which would actually be a good opportunity to make something much more user friendly. Being that I just started on this a few hours ago, that means that for at least a few weeks, don't expect to be able to actually play any games. Right now, you can pretty much just compile the binary and that's it. It's quite possible that some nall changes didn't produce compilation errors, but will produce runtime errors. So until the UI can actually load games, we won't know if anything is broken. But we should mostly be okay. It was mostly just trim<1> -> trim changes, moving to Hash::SHA256 (much cleaner), and patching some reckless memory copy functions enough to compile. Progress isn't going to be like it was before: I'm now dividing my time much thinner between studying and other hobbies. My aim this time is not to produce a binary for everyone to play games on. Rather, it's to keep the emulator alive. I want to be able to apply critical patches again. And I would also like the base of the emulator to live on, for use in other emulator frontends that utilize higan.
2015-02-26 19:10:46 +09:00
#include <nall/decode/png.hpp>
namespace nall {
struct image {
enum class blend : u32 {
add,
sourceAlpha, //color = sourceColor * sourceAlpha + targetColor * (1 - sourceAlpha)
sourceColor, //color = sourceColor
targetAlpha, //color = targetColor * targetAlpha + sourceColor * (1 - targetAlpha)
targetColor, //color = targetColor
};
struct channel {
channel(u64 mask, u32 depth, u32 shift) : _mask(mask), _depth(depth), _shift(shift) {
}
auto operator==(const channel& source) const -> bool {
return _mask == source._mask && _depth == source._depth && _shift == source._shift;
}
auto operator!=(const channel& source) const -> bool {
return !operator==(source);
}
auto mask() const { return _mask; }
auto depth() const { return _depth; }
auto shift() const { return _shift; }
private:
u64 _mask;
u32 _depth;
u32 _shift;
};
//core.hpp
image(const image& source);
image(image&& source);
image(bool endian, u32 depth, u64 alphaMask, u64 redMask, u64 greenMask, u64 blueMask);
image(const string& filename);
image(const void* data, u32 size);
image(const vector<u8>& buffer);
template<u32 Size> image(const u8 (&Name)[Size]);
image();
~image();
auto operator=(const image& source) -> image&;
auto operator=(image&& source) -> image&;
explicit operator bool() const;
auto operator==(const image& source) const -> bool;
auto operator!=(const image& source) const -> bool;
auto read(const u8* data) const -> u64;
auto write(u8* data, u64 value) const -> void;
auto free() -> void;
auto load(const string& filename) -> bool;
auto copy(const void* data, u32 pitch, u32 width, u32 height) -> void;
auto allocate(u32 width, u32 height) -> void;
//fill.hpp
auto fill(u64 color = 0) -> void;
auto gradient(u64 a, u64 b, u64 c, u64 d) -> void;
auto gradient(u64 a, u64 b, s32 radiusX, s32 radiusY, s32 centerX, s32 centerY, function<f64 (f64, f64)> callback) -> void;
auto crossGradient(u64 a, u64 b, s32 radiusX, s32 radiusY, s32 centerX, s32 centerY) -> void;
auto diamondGradient(u64 a, u64 b, s32 radiusX, s32 radiusY, s32 centerX, s32 centerY) -> void;
auto horizontalGradient(u64 a, u64 b, s32 radiusX, s32 radiusY, s32 centerX, s32 centerY) -> void;
auto radialGradient(u64 a, u64 b, s32 radiusX, s32 radiusY, s32 centerX, s32 centerY) -> void;
auto sphericalGradient(u64 a, u64 b, s32 radiusX, s32 radiusY, s32 centerX, s32 centerY) -> void;
auto squareGradient(u64 a, u64 b, s32 radiusX, s32 radiusY, s32 centerX, s32 centerY) -> void;
auto verticalGradient(u64 a, u64 b, s32 radiusX, s32 radiusY, s32 centerX, s32 centerY) -> void;
//scale.hpp
auto scale(u32 width, u32 height, bool linear = true) -> void;
//blend.hpp
auto impose(blend mode, u32 targetX, u32 targetY, image source, u32 x, u32 y, u32 width, u32 height) -> void;
//utility.hpp
auto shrink(u64 transparentColor = 0) -> void;
auto crop(u32 x, u32 y, u32 width, u32 height) -> bool;
auto alphaBlend(u64 alphaColor) -> void;
auto alphaMultiply() -> void;
auto transform(const image& source = {}) -> void;
auto transform(bool endian, u32 depth, u64 alphaMask, u64 redMask, u64 greenMask, u64 blueMask) -> void;
//static.hpp
static auto bitDepth(u64 color) -> u32;
static auto bitShift(u64 color) -> u32;
static auto normalize(u64 color, u32 sourceDepth, u32 targetDepth) -> u64;
//access
auto data() { return _data; }
auto data() const { return _data; }
auto width() const { return _width; }
auto height() const { return _height; }
auto endian() const { return _endian; }
auto depth() const { return _depth; }
auto stride() const { return (_depth + 7) >> 3; }
auto pitch() const { return _width * stride(); }
auto size() const { return _height * pitch(); }
auto alpha() const { return _alpha; }
auto red() const { return _red; }
auto green() const { return _green; }
auto blue() const { return _blue; }
private:
//core.hpp
auto allocate(u32 width, u32 height, u32 stride) -> u8*;
//scale.hpp
auto scaleLinearWidth(u32 width) -> void;
auto scaleLinearHeight(u32 height) -> void;
auto scaleLinear(u32 width, u32 height) -> void;
auto scaleNearest(u32 width, u32 height) -> void;
//load.hpp
auto loadBMP(const string& filename) -> bool;
auto loadBMP(const u8* data, u32 size) -> bool;
auto loadPNG(const string& filename) -> bool;
auto loadPNG(const u8* data, u32 size) -> bool;
//interpolation.hpp
auto isplit(u64* component, u64 color) -> void;
auto imerge(const u64* component) -> u64;
auto interpolate1f(u64 a, u64 b, f64 x) -> u64;
auto interpolate1f(u64 a, u64 b, u64 c, u64 d, f64 x, f64 y) -> u64;
auto interpolate1i(s64 a, s64 b, u32 x) -> u64;
auto interpolate1i(s64 a, s64 b, s64 c, s64 d, u32 x, u32 y) -> u64;
auto interpolate4f(u64 a, u64 b, f64 x) -> u64;
auto interpolate4f(u64 a, u64 b, u64 c, u64 d, f64 x, f64 y) -> u64;
auto interpolate4i(u64 a, u64 b, u32 x) -> u64;
auto interpolate4i(u64 a, u64 b, u64 c, u64 d, u32 x, u32 y) -> u64;
u8* _data = nullptr;
u32 _width = 0;
u32 _height = 0;
bool _endian = 0; //0 = lsb, 1 = msb
u32 _depth = 32;
channel _alpha{255u << 24, 8, 24};
channel _red {255u << 16, 8, 16};
channel _green{255u << 8, 8, 8};
channel _blue {255u << 0, 8, 0};
};
2021-09-04 00:07:37 +09:00
struct multiFactorImage : public image {
using image::image;
multiFactorImage(const multiFactorImage& source);
multiFactorImage(multiFactorImage&& source);
multiFactorImage(const image& lowDPI, const image& highDPI);
multiFactorImage(const image& source);
multiFactorImage(image&& source);
multiFactorImage();
~multiFactorImage();
auto operator=(const multiFactorImage& source) -> multiFactorImage&;
auto operator=(multiFactorImage&& source) -> multiFactorImage&;
auto operator==(const multiFactorImage& source) const -> bool;
auto operator!=(const multiFactorImage& source) const -> bool;
const image& lowDPI() const { return *this; }
const image& highDPI() const { return _highDPI; }
private:
image _highDPI;
};
}
#include <nall/image/static.hpp>
#include <nall/image/core.hpp>
#include <nall/image/load.hpp>
#include <nall/image/interpolation.hpp>
#include <nall/image/fill.hpp>
#include <nall/image/scale.hpp>
#include <nall/image/blend.hpp>
#include <nall/image/utility.hpp>
2021-09-04 00:07:37 +09:00
#include <nall/image/multifactor.hpp>