• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

D bindings to the GraphicsMagick library.


Commit MetaInfo

Revisiond331323932b3833aaff5cab0762c7099e3b36555 (tree)
Zeit2023-01-14 16:34:54
Autorkaerou <stigma@disr...>
Commiterkaerou

Log Message

Add a "convert" example.

Again, the issue with GC freeing ImageInfo before Image. Will probably
change it so the ImageInfo is either removed or retained in Image. Just
not sure how useful the ImageInfo is without an initial Image.

Ändern Zusammenfassung

Diff

--- /dev/null
+++ b/examples/convert.d
@@ -0,0 +1,63 @@
1+/*
2+ File: examples/convert.d
3+ Contains: An example program which will 'convert' an input to an output.
4+ Copyright: (C) 2023 kaerou <stigma@disroot.org>
5+
6+ Permission is hereby granted, free of charge, to any person obtaining a copy
7+ of this software and associated documentation files (the "Software"), to deal
8+ in the Software without restriction, including without limitation the rights
9+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ copies of the Software, and to permit persons to whom the Software is
11+ furnished to do so, subject to the following conditions:
12+
13+ The above copyright notice and this permission notice shall be included in all
14+ copies or substantial portions of the Software.
15+
16+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+ SOFTWARE.
23+*/
24+module examples.convert;
25+
26+import std.stdio;
27+
28+import magickd;
29+
30+import graphicsmagick_c.magick.image : UniformNoise;
31+
32+int main(string[] args) {
33+ if (args.length != 3) {
34+ writefln("Usage: %s <infile> <outfile>", args[0]);
35+ return 1;
36+ }
37+
38+ version (GMagick_Dynamic) {
39+ void* libgm;
40+
41+ if (false == loadGraphicsMagick(libgm)) {
42+ stderr.writeln("Loading GraphicsMagick wasn't without errors...");
43+ }
44+ }
45+
46+ InitializeMagick(null);
47+ scope(exit) { DestroyMagick(); }
48+
49+ /*
50+ * Try to use scope... it prevents issues with the GC.
51+ */
52+ scope imageInfo = new ImageInfo(args[1]);
53+ scope image = new Image(imageInfo);
54+ image.filename = args[2];
55+
56+ // Trying out some methods.
57+ image.addNoise(UniformNoise);
58+ image.blur(0.0, 2.5);
59+
60+ image.write(args[2]);
61+
62+ return 0;
63+}