QtE56: QFormBuilder: Error: undefined identifier `QFormBuilder`
I'm trying to load a .ui GUI designed in Qt Designer. I'm following the examples in the links below, but the following error occurs: Error: undefined identifier `QFormBuilder` QFormBuilder qfb = new QFormBuilder(this); setQtObj((qfb.load(":/fQtE56help.ui")).QtObj); * https://github.com/MGWL/QtE5/ * https://github.com/MGWL/QtE5/wiki * https://github.com/MGWL/QtE5/wiki * https://www.youtube.com/watch?v=TFN5P4eoS_o Could anyone help me to solve the problem? I would like to design my GUI in Qt Designer, and load the .ui to create my program.
Re: Library for image editing and text insertion
On Tuesday, 26 April 2022 at 18:31:49 UTC, H. S. Teoh wrote: maybe look at Adam Ruppe's arsd library (https://github.com/adamdruppe/arsd) for some lightweight modules that read common image formats and do some primitive image manipulations. I don't actually have an image to image blit function, but writing one is trivial - just loop over it and call alphaBlend. It can load ttf fonts, render them to bitmaps, load images, combined them, then save images. Can even load ttfs off the operating system if you wanted to use those or even have the OS functions do the drawing instead of diy, but probably easier to diy this simple case. Sample code would be: --- import arsd.image; import arsd.ttf; void main() { auto image = loadImageFromFile("/home/me/small-clouds.png"); if(image is null) throw new Exception("Couldn't load the image file"); auto tci = image.getAsTrueColorImage(); // convert to rgba for simplicity import std.file; auto font = TtfFont(cast(ubyte[]) std.file.read("/home/me/arsd/sans-serif.ttf")); int width, height; auto bitmap = font.renderString("Hello", 14, width, height); // it populates width and height fyi // where we want to put it int xput = 30; int yput = 20; int bitmapOffset = 0; // color to draw the text int r = 255; int g = 0; int b = 0; foreach(y; 0 .. height) { if(y + yput >= image.height) break; foreach(x; 0 .. width) { scope(exit) bitmapOffset++; // always advance this as long as we're still drawing... // but don't draw out of bounds if(x + xput >= image.width) continue; // replace a pixel with the blended version of the text bitmap image.setPixel( xput + x, yput + y, image.getPixel(xput + x, yput + y). alphaBlend(Color(r, g, b, bitmap[bitmapOffset])) ); } } import arsd.png; writePng("text-image.png", image); // save it back to a png } --- Open the text-image.png to see the result. (Or: --- import arsd.simpledisplay; displayImage(Image.fromMemoryImage(image)); --- to display it in a window right from your program!) My libs are available as individual files from the github - you might just use png instead of the whole image.d to avoid needing additional files for formats you don't need - or you can pull it on dub under the arsd-official:image_files package and arsd-official:ttf.
Re: Reference counting example
On Tuesday, 26 April 2022 at 22:16:01 UTC, cc wrote: Test application: I should point out that all this stuff with saving refcounted things to arrays and so on is extremely untested and experimental One problem I'm seeing is the inability for a refcounted class to pass itself to another function, since the class internals don't see the struct wrapper.. you can pass the naked object reference itself, and hope the reference doesn't get saved otherwise there's your dangling pointer, but then you also have the problem of inconsistent method declarations, with some things taking Foo and others taking RefCounted!Foo etc... Every night I pray for a `refcounted` keyword. Wouldn't something like `auto foo = new refcount Foo();` be nice? Then every class that deals with the objects could continue to be allocator-agnostic... definitely not a trivial change though.
Re: A template construct like using()
On Tuesday, 26 April 2022 at 23:00:57 UTC, cc wrote: If your draw code doesn't depend on any scoped state you can use `function()` instead of `delegate()` to save a GC call. `scope delegate` also works here and just reuses the stack.
Re: A template construct like using()
On Tuesday, 26 April 2022 at 21:33:43 UTC, Chris Katko wrote: I swear I asked something like this before years ago but it doesn't show up in my previous forum posts. I'm looking for a construct that mimics using(var)/with(var) ```d void draw_with(bitmap* drawb, void delegate() dg) { set_target_bitmap(drawb); dg(); set_target_bitmap(original_target); } bitmap* b; draw_with(b, { draw_pixel(red, 16, 16); }); ``` If your draw code doesn't depend on any scoped state you can use `function()` instead of `delegate()` to save a GC call.
Re: Library for image editing and text insertion
On Tuesday, 26 April 2022 at 22:16:15 UTC, rikki cattermole wrote: Of course I still don't think that code is right and should have the casts. Absolutely. I'm a bit anxious about "accidental VRP" now, not sure if the checks fluctuate from version to version, or worse, depends upon the platform.
Re: Library for image editing and text insertion
On 27/04/2022 10:05 AM, Guillaume Piolat wrote: On Tuesday, 26 April 2022 at 21:59:39 UTC, rikki cattermole wrote: Putting an int into a ubyte absolutely should error, that is a lossy conversion and should not be automatic. It's just VRP, here it works in 2.094 https://d.godbolt.org/z/vjq7xsMdn because the compiler wasn't complaining I wouldn't know it was reliant on VRP (which is certainly an issue to be fixed). Okay further testing locally, I cannot reproduce. Of course I still don't think that code is right and should have the casts. Either way whatever the dmd is, it must not be as recent as thought to be.
Re: Reference counting example
On Tuesday, 26 April 2022 at 06:55:34 UTC, Alain De Vos wrote: Can someone provide a simple/very simple reference counting or refcounted example i can understand. Thanks. I've been playing around with the automem[1] library's RefCounted feature as we speak, it seems to fit my needs more than std.typecons which doesn't quite do what I want. I did have to make some changes to the library though to allow for inheritance and manually releasing (below). It's pretty fun so far so I'm looking forward to trying it in some other projects like a non-GC XML library. [1] https://github.com/atilaneves/automem Test application: ```d import std.stdio; import core.memory; import util.array; // ARRAY Custom wrapper for std.container.array // The vector/array library provided with automem does NOT properly destroy array elements // so we'll use std.container.array instead import std.experimental.allocator.mallocator; import automem; alias RC(T) = RefCounted!(T, Mallocator); // Optional default constructor workaround auto RCREATE(T, Args...)(auto ref Args args) { return RC!T.create(args); } class Farm { ARRAY!(RC!Cow) animals; //this() {} this(int) { writeln("[Farm]"); } ~this() { writeln("[~Farm]"); animals.clear(); writeln("[/Farm]"); } void pet(RC!Animal animal) { writefln("Farm: The %s says...", animal); animal.speak; } } class Animal { void speak() { writeln("Animal: ???"); } } class Cow : Animal { ARRAY!(RC!Animal) friends; // Amazingly, this works, as long as the array elem type is NOT the same as RC!(this class) // otherwise we get a forwarding error int x; this() { writefln("[Cow]"); } this(int x) { this.x = x; writefln("[Cow %s]", x); } ~this() { writefln("[/Cow %s]", x); } override void speak() { writefln("Cow#%s: Moo.", x); } } void main() { auto used = GC.stats.usedSize; scope(exit) assert(GC.stats.usedSize == used); // GC is not touched! { assert(RCREATE!Cow.x == 0); assert(RCREATE!Cow(99).x == 99); } RC!Animal other; auto farm = RC!Farm(1); { auto cow = RC!Cow(1); farm.animals ~= cow; farm.animals ~= RC!Cow(2); other = farm.animals[1]; auto cowGoesOutOfScope = RC!Cow(70); } writeln("out, should have seen Cow#70's dtor"); farm.animals[0] = farm.animals[1]; writeln("animals[0] (Cow#1) just got overwritten so we should have seen its dtor"); farm.animals ~= RC!Cow(3); farm.pet(other); other = null; farm = null; writeln("done"); } ``` Output: ``` [Cow] [/Cow 0] [Cow 99] [/Cow 99] [Farm] [Cow 1] [Cow 2] [Cow 70] [/Cow 70] out, should have seen Cow#70's dtor [/Cow 1] animals[0] (Cow#1) just got overwritten so we should have seen its dtor [Cow 3] Farm: The memtest.Cow says... Cow#2: Moo. [~Farm] [/Cow 2] [/Cow 3] [/Farm] done ``` I added the following functions to automem `ref_counted.d`: ```d // static .create method to allow use of class's default constructor if desired static if (isGlobal && is(Type == class) && __traits(compiles, new Type())) { static auto create(Args...)(auto ref Args args) { typeof(this) obj; obj.makeObject!args(); return obj; } } // allow instantiation or assignment from derived classes if the Allocator is the same this(U)(ref RefCounted!(U,Allocator) rhs) if (is(U == class) && !is(U == Type)) { _impl = cast(typeof(_impl)) rhs._impl; if(_impl !is null) inc; } void opAssign(U : Type)(ref RefCounted!(U,Allocator) other) if (is(U == class) && !is(U == Type)) { //if (_impl == other._impl) return; if (_impl._rawMemory.ptr == other._impl._rawMemory.ptr) return; if(_impl !is null) release; static if(!isGlobal) _allocator = other._allocator; _impl = cast(typeof(_impl)) other._impl; if(_impl !is null) inc; } // Allow assigning null to manually release payload void opAssign(typeof(null)) { if(_impl !is null) release; _impl = null; } ```
Re: Library for image editing and text insertion
On Tuesday, 26 April 2022 at 21:59:39 UTC, rikki cattermole wrote: Putting an int into a ubyte absolutely should error, that is a lossy conversion and should not be automatic. It's just VRP, here it works in 2.094 https://d.godbolt.org/z/vjq7xsMdn because the compiler wasn't complaining I wouldn't know it was reliant on VRP (which is certainly an issue to be fixed).
Re: Library for image editing and text insertion
On 27/04/2022 9:55 AM, Guillaume Piolat wrote: On Tuesday, 26 April 2022 at 21:44:56 UTC, rikki cattermole wrote: On 27/04/2022 9:39 AM, Guillaume Piolat wrote: On Tuesday, 26 April 2022 at 21:13:38 UTC, Alexander Zhirov wrote: more build errors If you "dub upgrade" it should work a bit better. No success in reproducing the bug here. It definitely on your end. void main() { int scale; int* in_ = new int; ubyte b = cast(int)scale * (cast(int)*in_ >> 7); } onlineapp.d(5): Error: cannot implicitly convert expression `scale * (*in_ >> 7)` of type `int` to `ubyte` No. Obviously VRP works differently for me and for him, for an unknown reason. I copied and pasted the same code that is failing from the file in question and put it into that test code. Putting an int into a ubyte absolutely should error, that is a lossy conversion and should not be automatic.
Re: Library for image editing and text insertion
On Tuesday, 26 April 2022 at 21:44:56 UTC, rikki cattermole wrote: On 27/04/2022 9:39 AM, Guillaume Piolat wrote: On Tuesday, 26 April 2022 at 21:13:38 UTC, Alexander Zhirov wrote: more build errors If you "dub upgrade" it should work a bit better. No success in reproducing the bug here. It definitely on your end. void main() { int scale; int* in_ = new int; ubyte b = cast(int)scale * (cast(int)*in_ >> 7); } onlineapp.d(5): Error: cannot implicitly convert expression `scale * (*in_ >> 7)` of type `int` to `ubyte` No. Obviously VRP works differently for me and for him, for an unknown reason.
Re: A template construct like using()
On Tue, Apr 26, 2022 at 09:33:43PM +, Chris Katko via Digitalmars-d-learn wrote: [...] > I'm looking for a construct that mimics using(var)/with(var) > > D > bitmap* b; > > draw_with(b) > { > draw_pixel(red, 16, 16); //draw red pixel to bitmap b (b is implied above) > } > > > But the code ends up being: > D > bitmap* b; > > set_target_bitmap(b); //entry code > draw_pixel(red, 16, 16); // body > set_target_bitmap(original_target); // exit code > > > The essence is wrapping something the code up in a kind of RAII-like > entry and exit code that references a given target variable. [...] Kinda ugly-looking, but here's the first idea that came to mind: bitmap* b; { set_target_bitmap(b); scope(exit) set_target_bitmap(original_target); draw_pixel(...); ... // blah blah blah } // scope(exit) runs here T -- Unix was not designed to stop people from doing stupid things, because that would also stop them from doing clever things. -- Doug Gwyn
Re: Library for image editing and text insertion
On 27/04/2022 9:39 AM, Guillaume Piolat wrote: On Tuesday, 26 April 2022 at 21:13:38 UTC, Alexander Zhirov wrote: more build errors If you "dub upgrade" it should work a bit better. No success in reproducing the bug here. It definitely on your end. void main() { int scale; int* in_ = new int; ubyte b = cast(int)scale * (cast(int)*in_ >> 7); } onlineapp.d(5): Error: cannot implicitly convert expression `scale * (*in_ >> 7)` of type `int` to `ubyte`
Re: Library for image editing and text insertion
On Tuesday, 26 April 2022 at 21:13:38 UTC, Alexander Zhirov wrote: more build errors If you "dub upgrade" it should work a bit better. No success in reproducing the bug here.
A template construct like using()
I swear I asked something like this before years ago but it doesn't show up in my previous forum posts. I'm looking for a construct that mimics using(var)/with(var) D bitmap* b; draw_with(b) { draw_pixel(red, 16, 16); //draw red pixel to bitmap b (b is implied above) } But the code ends up being: D bitmap* b; set_target_bitmap(b); //entry code draw_pixel(red, 16, 16); // body set_target_bitmap(original_target); // exit code The essence is wrapping something the code up in a kind of RAII-like entry and exit code that references a given target variable. Perhaps a mixin is what I'm looking for?
Re: Library for image editing and text insertion
No args added there. https://github.com/AuburnSounds/Dplug/blob/master/graphics/dplug/graphics/pngload.d#L1972 Yup that code certainly looks wrong. Note the casts above it in around: https://github.com/AuburnSounds/Dplug/blob/master/graphics/dplug/graphics/pngload.d#L1956 So yeah upstream issue.
Re: Library for image editing and text insertion
On Tuesday, 26 April 2022 at 21:04:17 UTC, rikki cattermole wrote: $ dub build -v ```d Using dub registry url 'https://code.dlang.org/' Refreshing local packages (refresh existing: true)... Looking for local package map at /var/lib/dub/packages/local-packages.json Looking for local package map at /home/alexander/.dub/packages/local-packages.json Looking for local package map at /mnt/hdd_data/programming/d/write text on image/.dub/packages/local-packages.json Note: Failed to determine version of package lol at .. Assuming ~master. Refreshing local packages (refresh existing: false)... Looking for local package map at /var/lib/dub/packages/local-packages.json Looking for local package map at /home/alexander/.dub/packages/local-packages.json Looking for local package map at /mnt/hdd_data/programming/d/write text on image/.dub/packages/local-packages.json Found dependency dplug:graphics 12.5.2 Found dependency intel-intrinsics 1.9.2 Found dependency dplug:math 12.5.2 Found dependency dplug:core 12.5.2 Refreshing local packages (refresh existing: false)... Looking for local package map at /var/lib/dub/packages/local-packages.json Looking for local package map at /home/alexander/.dub/packages/local-packages.json Looking for local package map at /mnt/hdd_data/programming/d/write text on image/.dub/packages/local-packages.json Found dependency dplug:graphics 12.5.2 Found dependency intel-intrinsics 1.9.2 Found dependency dplug:math 12.5.2 Found dependency dplug:core 12.5.2 Generating using build Configuring dependent lol, deps:"dplug:graphics" Configuring dependent dplug:graphics, deps:"dplug:core", "dplug:math", "intel-intrinsics" Configuring dependent dplug:core, deps:"intel-intrinsics" Configuring dependent intel-intrinsics, deps: Configuring dependent dplug:math, deps:"intel-intrinsics" Performing "debug" build using /usr/bin/dmd for x86_64. intel-intrinsics 1.9.2: target for configuration "library" is up to date. Using existing build in /home/alexander/.dub/packages/intel-intrinsics-1.9.2/intel-intrinsics/.dub/build/library-debug-linux.posix-x86_64-dmd_v2.098.0-67C75DB793DA1F77431FDBF6F478D1AC/. Copying target from /home/alexander/.dub/packages/intel-intrinsics-1.9.2/intel-intrinsics/.dub/build/library-debug-linux.posix-x86_64-dmd_v2.098.0-67C75DB793DA1F77431FDBF6F478D1AC/libintel-intrinsics.a to /home/alexander/.dub/packages/intel-intrinsics-1.9.2/intel-intrinsics dplug:core 12.5.2: target for configuration "library" is up to date. Using existing build in /home/alexander/.dub/packages/dplug-12.5.2/dplug/.dub/build/library-debug-linux.posix-x86_64-dmd_v2.098.0-D8C57FD168AF1371806144D918242E73/. Copying target from /home/alexander/.dub/packages/dplug-12.5.2/dplug/.dub/build/library-debug-linux.posix-x86_64-dmd_v2.098.0-D8C57FD168AF1371806144D918242E73/libdplug_core.a to /home/alexander/.dub/packages/dplug-12.5.2/dplug dplug:math 12.5.2: target for configuration "library" is up to date. Using existing build in /home/alexander/.dub/packages/dplug-12.5.2/dplug/.dub/build/library-debug-linux.posix-x86_64-dmd_v2.098.0-331F3B3983F69B80C64AABFDF7D43329/. Copying target from /home/alexander/.dub/packages/dplug-12.5.2/dplug/.dub/build/library-debug-linux.posix-x86_64-dmd_v2.098.0-331F3B3983F69B80C64AABFDF7D43329/libdplug_math.a to /home/alexander/.dub/packages/dplug-12.5.2/dplug Target '/home/alexander/.dub/packages/dplug-12.5.2/dplug/.dub/build/library-debug-linux.posix-x86_64-dmd_v2.098.0-566711123C5A86FF62721CA5E0A67A56/libdplug_graphics.a' doesn't exist, need rebuild. dplug:graphics 12.5.2: building configuration "library"... /usr/bin/dmd -lib -of/home/alexander/.dub/packages/dplug-12.5.2/dplug/.dub/build/library-debug-linux.posix-x86_64-dmd_v2.098.0-566711123C5A86FF62721CA5E0A67A56/libdplug_graphics.a -debug -g -w -version=Have_dplug_graphics -version=Have_dplug_core -version=Have_dplug_math -version=Have_intel_intrinsics -I/home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics -I/home/alexander/.dub/packages/dplug-12.5.2/dplug/core -I/home/alexander/.dub/packages/intel-intrinsics-1.9.2/intel-intrinsics/source -I/home/alexander/.dub/packages/dplug-12.5.2/dplug/math /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics/color.d /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics/draw.d /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics/drawex.d /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics/font.d /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics/image.d /home/alexander/.dub/packages/dplug-12.5.2/dplug/! graphics/dplug/graphics/jpegload.d /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics/mipmap.d /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics/package.d /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics/pngload.d
Re: Library for image editing and text insertion
To get the commands dub used, use -v. $ dub build -v
Re: Library for image editing and text insertion
On Tuesday, 26 April 2022 at 20:45:16 UTC, Alexander Zhirov wrote: On Tuesday, 26 April 2022 at 20:37:28 UTC, Guillaume Piolat wrote: Curious as to what DMD you are using on what OS? It builds with 2.095.1 to 2.100-b1 here. DMD64 D Compiler v2.098.0 OS Solus Linux Well I cannot reproduce your problem => https://imgur.com/a/HZvZWr2 Perhaps a DUB mismatch that would give different DIP flags. DUB version 1.27.0, built on Oct 19 2021 Good luck.
Re: Library for image editing and text insertion
On Tuesday, 26 April 2022 at 20:37:28 UTC, Guillaume Piolat wrote: Curious as to what DMD you are using on what OS? It builds with 2.095.1 to 2.100-b1 here. DMD64 D Compiler v2.098.0 OS Solus Linux
Re: Library for image editing and text insertion
On Tuesday, 26 April 2022 at 20:26:42 UTC, Alexander Zhirov wrote: build error Curious as to what DMD you are using on what OS? It builds with 2.095.1 to 2.100-b1 here.
Re: Library for image editing and text insertion
On Tuesday, 26 April 2022 at 18:12:55 UTC, Guillaume Piolat wrote: You can eventually use dplug:graphics for that https://u.pcloud.link/publink/show?code=XZPwMFVZW9c6bTWtevRvNz7UdfOOqVYIE5uk ```d Performing "debug" build using /usr/bin/dmd for x86_64. intel-intrinsics 1.9.2: target for configuration "library" is up to date. dplug:core 12.5.2: target for configuration "library" is up to date. dplug:math 12.5.2: target for configuration "library" is up to date. dplug:graphics 12.5.2: building configuration "library"... /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics/pngload.d(1972,34): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ >> 7)` of type `int` to `ubyte` /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics/pngload.d(1973,34): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ >> 6 & 1)` of type `int` to `ubyte` /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics/pngload.d(1974,34): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ >> 5 & 1)` of type `int` to `ubyte` /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics/pngload.d(1975,34): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ >> 4 & 1)` of type `int` to `ubyte` /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics/pngload.d(1976,34): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ >> 3 & 1)` of type `int` to `ubyte` /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics/pngload.d(1977,34): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ >> 2 & 1)` of type `int` to `ubyte` /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics/pngload.d(1978,34): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ >> 1 & 1)` of type `int` to `ubyte` /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics/pngload.d(1979,34): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ & 1)` of type `int` to `ubyte` /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics/pngload.d(1981,41): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ >> 7)` of type `int` to `ubyte` /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics/pngload.d(1982,41): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ >> 6 & 1)` of type `int` to `ubyte` /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics/pngload.d(1983,41): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ >> 5 & 1)` of type `int` to `ubyte` /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics/pngload.d(1984,41): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ >> 4 & 1)` of type `int` to `ubyte` /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics/pngload.d(1985,41): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ >> 3 & 1)` of type `int` to `ubyte` /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics/pngload.d(1986,41): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ >> 2 & 1)` of type `int` to `ubyte` /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics/pngload.d(1987,41): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ >> 1 & 1)` of type `int` to `ubyte` /usr/bin/dmd failed with exit code 1. ``` It's strange, for some reason it's not building.
Re: Library for image editing and text insertion
On Tue, Apr 26, 2022 at 05:22:54PM +, Alexander Zhirov via Digitalmars-d-learn wrote: > It is necessary to write a utility that will insert (x,y) text on the > image. It is desirable that the utility does not depend on large > libraries, since a minimum utility size is required. I'm looking for > something similar in C/C++, I can't find anything. Maybe there is some > simple library on D? Maybe use imagemagick? https://stackoverflow.com/questions/23236898/add-text-on-image-at-specific-point-using-imagemagick Handling multiple image formats is generally a complex task that requires multiple libraries, some of which may not be trivial. Unless you have a specific image format in mind? Also, text rendering, in general, is an extremely complex and hairy problem. At the very minimum, you need a font. If you have a bitmap font, then it's relatively easy (just blit the characters you need onto the image with alpha blending). But if you're looking at TTF fonts or similar, you're looking at the very minimum at using libfreetype to be able to meaningfully use the font file. Then there's the issue of font layout, which is language-specific and may require a complex layout engine like HarfBuzz (which requires libraries with complex dependencies). If utility size is of utmost importance, then the ideal case would be a fixed image format (so only 1 library is needed to process files of that type) with a bitmapped font (at worst, a 2nd library for reading the font) for a specific language (so no cross-language layout issues that requires complex layout engines). Then you can just treat the font characters as bitmaps and alpha-blend them onto the image. Preferably, use a monospaced bitmap font so that you can just use a fixed grid for character placement, and not have to deal with complex font metrics, hinting, kerning, and all of that complex stuff. For this, maybe look at Adam Ruppe's arsd library (https://github.com/adamdruppe/arsd) for some lightweight modules that read common image formats and do some primitive image manipulations. T -- People who are more than casually interested in computers should have at least some idea of what the underlying hardware is like. Otherwise the programs they write will be pretty weird. -- D. Knuth
Language server
In a perfect world there would be someone uploading a youtube video how to implement neovim with a dlang language-server. With function-completions-help where hints are given about the functions and libraries. If anyone could do this , this would be nice to have.
Re: Library for image editing and text insertion
On Tuesday, 26 April 2022 at 17:22:54 UTC, Alexander Zhirov wrote: It is necessary to write a utility that will insert (x,y) text on the image. It is desirable that the utility does not depend on large libraries, since a minimum utility size is required. I'm looking for something similar in C/C++, I can't find anything. Maybe there is some simple library on D? You can eventually use dplug:graphics for that https://u.pcloud.link/publink/show?code=XZPwMFVZW9c6bTWtevRvNz7UdfOOqVYIE5uk
Library for image editing and text insertion
It is necessary to write a utility that will insert (x,y) text on the image. It is desirable that the utility does not depend on large libraries, since a minimum utility size is required. I'm looking for something similar in C/C++, I can't find anything. Maybe there is some simple library on D?
Re: Problem with GC - linking C++ & D (with gdc)
On Tuesday, 26 April 2022 at 12:49:21 UTC, Alain De Vos wrote: PS : I use ``` ldc2 --gcc=cc , cc -v : clang version 11.0.1 ``` We only have gcc in our toolchain (we target an ARM-based embedded system). --- I also encountered problems while I was trying to use CTFE only functions (using betterC so I don't have to link phobos/D-runtime). However, if those functions use the GC for instance (like appending a dynamic-array), it will require me to link D-runtime, whereas I only use them at compile-time. So I'm a bit confused... I'll try and get more information and reduce a code sample.
Re: Reference counting example
On Tuesday, 26 April 2022 at 06:55:34 UTC, Alain De Vos wrote: Can someone provide a simple/very simple reference counting or refcounted example i can understand. Thanks. I suggest to look at RefCounted [here](https://code.dlang.org/packages/automem) rather than in Phobos. There are simple examples.
Re: Problem with GC - linking C++ & D (with gdc)
PS : I use ``` ldc2 --gcc=cc , cc -v : clang version 11.0.1 ```
Re: Problem with GC - linking C++ & D (with gdc)
On Tuesday, 26 April 2022 at 10:29:39 UTC, Iain Buclaw wrote: On Tuesday, 26 April 2022 at 10:23:15 UTC, Claude wrote: Hello, Hello, <%--SNIP--%> Does anyone have any idea what's going on? (if I just compile a single D file with "int main() { int* a = new int(42); return *a; }", it works as intended.) The `new` keyword requests the druntime GC to allocate memory, however you haven't initialized the D run-time in your program. main.cpp ```D extern "C" int rt_init(); extern "C" const int* ct_parse(); int main(int argc, char ** argv) { rt_init(); return *ct_parse(); } ``` Ok, thanks! I should have suspected something like this.
Re: Problem with GC - linking C++ & D (with gdc)
On Tuesday, 26 April 2022 at 10:23:15 UTC, Claude wrote: It seg-faults... Just to make it clear, it seg-faults at run-time (not at compilation or link time) when I launch the executable "test".
Re: Problem with GC - linking C++ & D (with gdc)
On Tuesday, 26 April 2022 at 10:23:15 UTC, Claude wrote: Hello, Hello, <%--SNIP--%> Does anyone have any idea what's going on? (if I just compile a single D file with "int main() { int* a = new int(42); return *a; }", it works as intended.) The `new` keyword requests the druntime GC to allocate memory, however you haven't initialized the D run-time in your program. main.cpp ```D extern "C" int rt_init(); extern "C" const int* ct_parse(); int main(int argc, char ** argv) { rt_init(); return *ct_parse(); } ```
Problem with GC - linking C++ & D (with gdc)
Hello, I'm working on a C++ project requiring an XML parser. I decided to make it in D so I could easily parse at run-time or compile-time as I wish. As our project uses a gcc tool-chain, I naturally use GDC (GCC 9.4.0). But I have a few problems with D, linking with it, trying to use better-C and CTFE, etc. Here's a reduced sample of one of my problems: parser.d ``` extern(C) int* ct_parse() { int* a = new int(42); return a; } ``` main.cpp ``` extern "C" const int* ct_parse(); int main(int argc, char ** argv) { return *ct_parse(); } ``` Compiling/linking using the following command-lines: ``` gcc -c parser.d -o parser.o gcc -std=c++17 -c main.cpp -o main.o gcc main.o parser.o -lstdc++ -lgphobos -lgdruntime -o test ``` It seg-faults... Here's the output of gdb: ``` Program received signal SIGSEGV, Segmentation fault. 0x7777858a in gc_qalloc () from /usr/lib/x86_64-linux-gnu/libgdruntime.so.76 ``` Does anyone have any idea what's going on? (if I just compile a single D file with "int main() { int* a = new int(42); return *a; }", it works as intended.)
Reference counting example
Can someone provide a simple/very simple reference counting or refcounted example i can understand. Thanks.
Re: How to use destroy and free.
On Monday, 25 April 2022 at 14:25:17 UTC, H. S. Teoh wrote: On Mon, Apr 25, 2022 at 01:28:01PM +, Alain De Vos via Digitalmars-d-learn wrote: Could thc or hboehm provide solutions ? In general, GC (of any kind) does not (and cannot) guarantee the order objects will be collected in. So in the dtor, you cannot assume that any objects you depend on still exist (they may have already been collected). There is also no guarantee that the object will *ever* get collected: in theory, the GC may only collect just enough to make space for further allocations, it's not obligated to collect *everything* that's collectible. Or the collection might not take place before the end of the program -- the GC may skip the final collection because it knows the OS will reclaim everything automatically anyway. Basically, deterministic destruction and GC are antithetical to each other, and trying to have both is the road to trouble. If you wish to have deterministic destruction, don't use the GC; use RAII or reference counting instead. T When you can foresee a "maximum size" , you can create "deterministic" stack objects. ``` class C { @nogc this(){} @nogc this(int dummy){}; @nogc int[3] fixarr=new int[3]; }//C @nogc void myfun(){ int a; scope c = new C(); scope c2 = new C(5); }//myfun void main(){ myfun(); }//main ``` It's just the variable length arrays which are "problematic". Feel free to elaborate.