Re: [fpc-pascal] Array as result in function.
On Thursday 19 January 2017 22:50:36 fredvs wrote: > function array_in_out(arrayin: TArFloat): TArFloat; > begin > result := arrayin; > end; > Do you change items of "arrayin" later? If so the items of the result array will be changed too, dynamic array assignment copies the data pointer only. http://www.freepascal.org/docs-html/current/ref/refsu15.html#x39-520003.3.1 Use " function array_in_out(arrayin: TArFloat): TArFloat; begin result:= copy(arrayin); end; " if the result array must be independent. Martin ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Drawing bitmap by pixel
> On Jan 20, 2017, at 7:20 AM, Graeme Geldenhuys > wrote: > > It is slightly confusing. If you are using an Indexed image, then use > the Pixels[] property. If you are not using an Indexed image, then use > the Colors[] property. Thanks guys, Here’s the new program based on your example but it still just outputs a pure black image. procedure Draw; var image: TFPCustomImage; canvas: TFPImageCanvas; writer: TFPWriterPNG; x, y: integer; begin image := TFPCompactImgRGB8Bit.Create(100, 100); image.UsePalette := False; for x := 0 to image.Width-1 do for y := 0 to image.Height-1 do image.Colors[x, y] := FPColor(255, 0, 0, 255); writer := TFPWriterPNG.Create; writer.Indexed := False; image.SaveToFile('bitmap.png', writer); end; Regards, Ryan Joseph ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Drawing bitmap by pixel
> On Jan 20, 2017, at 8:31 AM, Ryan Joseph wrote: > > Thanks guys, > > Here’s the new program based on your example but it still just outputs a pure > black image. never mind! The max color value is 65535. I thought it was 1.0 or 255. Got it working now. Thanks again. Regards, Ryan Joseph ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Drawing bitmap by pixel
On 2017-01-19 14:59, Ryan Joseph wrote: > Is there anyway to set a pixel using TFPImageCanvas? It is slightly confusing. If you are using an Indexed image, then use the Pixels[] property. If you are not using an Indexed image, then use the Colors[] property. Attached is an example program that generates a Minecraft like grass block (texture) and then outputs it to a PNG file. I hope the example helps. Regards, Graeme -- fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp program project1; {$mode objfpc}{$H+} uses Classes, SysUtils, fpcanvas, fpimage, FPWritePNG; const IMGDIM = 64; // image dimensions var mm: TFPCustomImage; imgwri: TFPWriterPNG; br, x, y: integer; r, g, b: word; begin Randomize; // for later usage imgwri := TFPWriterPNG.create; imgwri.Indexed := False; br := 255 - Random(96); mm := TFPCompactImgRGB8Bit.Create(IMGDIM, IMGDIM); mm.UsePalette := False; for y := 0 to IMGDIM-1 do begin for x := 0 to IMGDIM-1 do begin (* // just random noise r := Random($FF); g := Random($FF); b := Random($FF); *) // * Minecraft like grass block ;-) * // ground r := $96; g := $6C; b := $4A; if (random(3) = 0) then br := 255 - random(96); if y < (((x * x * 3 + x * 81) shr 2) and 3) + (IMGDIM * 0.125) then begin // grass r := $6A; g := $AA; b := $40; end else if y < (((x * x * 3 + x * 81) shr 2) and 3) + (IMGDIM * 0.1875) then begin br := br * 2 div 3; end; r := (r * br) div $FF; g := (g * br) div $FF; b := (b * br) div $FF; // duplicate the data to fill a WORD size channel r := (r shl 8) or r; g := (g shl 8) or g; b := (b shl 8) or b; mm.Colors[x, y] := FPColor(r, g, b, $); end; end; mm.SaveToFile('output-1.png', imgwri); imgwri.Free; mm.Free; end. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Language constructs and types that dependent upon system unit
On Thu, January 19, 2017 1:28 pm, gabor wrote: > I was hoping that maybe there is an easy answer. But I understand. > Thanks. > The easy answer is just to use the system unit and have no fear... The main issue with using fpc with C is when you try to use classes or try to use C++ classes As objects are not so portable across languages.. Every language has their own object format. Also strings, being reference counted, will cause some issues unless you convert them to pchar when sending in as a read only to C, or if C writes to the string buffer you have to send a buffer in that is allocated by you (or a fixed buffer) rather than sending in an Ansistring. Memory managers will conflict. Or use shared memory manager. But C knows nothing about what a modern pascal reference counted ansistring is.. it has no information about it. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Array as result in function.
On Thu, Jan 19, 2017 at 6:50 PM, fredvs wrote: > Hello. > > With this code, the result of the function does not have same format as the > array input: > > Why ? > > type > TArFloat = array of cfloat; > > function array_in_out(arrayin: TArFloat): TArFloat; > begin > result := arrayin; > end; > It works fine here. Eg: === begin code === type TArFloat = array of cfloat; function array_in_out(arrayin: TArFloat): TArFloat; var i: byte; begin for i := low(arrayin) to high(arrayin) do arrayin[i] *= 10; Result := arrayin; end; ... var item: cfloat; thebuffer: TArFloat; begin SetLength(thebuffer, 3); thebuffer[0] := 1; thebuffer[1] := 2; thebuffer[2] := 3; WriteLn('before'); for item in thebuffer do WriteLn(item.ToString); thebuffer := array_in_out(thebuffer); WriteLn('after x10'); for item in thebuffer do WriteLn(item.ToString); end; // output: before 1 2 3 after x10 10 20 30 === end code === > Some more explaination. > > If in a code I use: > var > thebuffer: TArFloat; > > // thebuffer was filled with some float-samples > > thebuffer := array_in_out(thebuffer); > > It is not neutral, the data are affected (in audio the data are noisy). > > What is wrong ? > Are you using that function as callback with some (C/C++) library? If so, check its parameter calling convention, declaring it as `function array_in_out(arrayin: TArFloat): TArFloat; cdecl;`. > Thanks. > > Fre;D -- Silvio Clécio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Array as result in function.
Hello. With this code, the result of the function does not have same format as the array input: Why ? type TArFloat = array of cfloat; function array_in_out(arrayin: TArFloat): TArFloat; begin result := arrayin; end; Some more explaination. If in a code I use: var thebuffer: TArFloat; // thebuffer was filled with some float-samples thebuffer := array_in_out(thebuffer); It is not neutral, the data are affected (in audio the data are noisy). What is wrong ? Thanks. Fre;D - Many thanks ;-) -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Array-as-result-in-function-tp5727366.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Language constructs and types that dependent upon system unit
On Thu, Jan 19, 2017 at 8:15 PM, gabor wrote: > problems with initialization/finalization sections). ... > I know that following types require extra code: > object, class, sting, dynamic array, try..except. > What else should I avoid? I think it is a huge exaggeration to rule out all of that. I think that most of this stuff from basic language or system unit should work just fine. Indeed some might not work, but most should work. If you use the unit cmem (or even better if you make your own memory manager that redirects to the C side), I don't see why object/class/string/dynamic arrays should fail, when used internally in the Pascal side. try...except will probably indeed not work, because C often uses a different exception mask than FPC or something like that. I didn't try it myself recently, but instead of going bare-bones I would rule out stuff that fails when they fail, not beforehand suppose they won't work. -- Felipe Monteiro de Carvalho ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] How to remove EXIF data from a JPG file?
Hello, What is the best FPC library able to remove EXIF data from a JPG file? I would prefer to avoid the usage of external tools like ExifTool. Thank you in advance for your suggestions. Sandro Cumerlato ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Language constructs and types that dependent upon system unit
I was hoping that maybe there is an easy answer. But I understand. Thanks. Michał. W dniu 2017-01-19 o 20:28, Jonas Maebe pisze: It is therefore not possible to give an answer to your question that is generally valid. Furthermore, the answer could become wrong at any time because all of that is implementation-dependent. Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Language constructs and types that dependent upon system unit
On 19/01/17 20:15, gabor wrote: I would like to write some code that will be static linked with C application. In addition, I would like to avoid linking system and rtl units and would use only routines that come with C app and library (I heard that combining fpc rtl with C application is not a good idea and there are problems with initialization/finalization sections). I know that some of language constructs and types require additional code (such as memory management, etc.), which I would avoid. I know that following types require extra code: object, class, sting, dynamic array, try..except. What else should I avoid? The system unit implements parts of the language that are too complex to generate directly in the compiler. Which parts these are depend, a.o., on the target architecture and the target operating system. It is therefore not possible to give an answer to your question that is generally valid. Furthermore, the answer could become wrong at any time because all of that is implementation-dependent. Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Language constructs and types that dependent upon system unit
Hello! I would like to write some code that will be static linked with C application. In addition, I would like to avoid linking system and rtl units and would use only routines that come with C app and library (I heard that combining fpc rtl with C application is not a good idea and there are problems with initialization/finalization sections). I know that some of language constructs and types require additional code (such as memory management, etc.), which I would avoid. I know that following types require extra code: object, class, sting, dynamic array, try..except. What else should I avoid? Regards, Michał. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] ppcjvm issues
On 17.01.2017 19:07, Lars wrote: If you have a jvm project with lots of code and now want to start using this code in another regular mode objfpc unix/win32 application... Exactly this as the point I wanted to express. Even when coding an fpc application or library for use with jvm, free (and destroy) should be used and provided in the normal way good old Object Pascal requires. If jvm does garbage collection under the hood (and not momentarily adheres to free, as we are used to with Object Pascal) this should be handled as a hidden implementation detail and as little as possible be communicated outside, so that using this code in another regular mode objfpc unix/win32 application can be done as seamlessly as possible . -Michael ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Drawing bitmap by pixel
On Thu, Jan 19, 2017 at 3:59 PM, Ryan Joseph wrote: > I used the image canvas before to draw bitmap fonts so I have this code > working. Is there anyway to set a pixel using TFPImageCanvas? Use the Colors property, it is fast: property Colors [x,y:integer] : TFPColor read GetColor write SetColor; > canvas.Brush.FPColor := colRed; // how do I set the color as an RGB? Use this function: function FPColor (r,g,b,a:word) : TFPColor; fcl-image is from Free Pascal, not from Lazarus, but in lcl/lazcanvas.pas there is TLazCanvas which extends TFPImageCanvas adding convenience functions for example for alpha blending among other stuff. -- Felipe Monteiro de Carvalho ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Drawing bitmap by pixel
I’d like to draw a bitmap pixel by pixel then save to disk but I can’t understand the docs available online. I know there’s a BGRABitmap class with direct pixel access but I wasn’t able to find the unit in my FPC distribution.I used the image canvas before to draw bitmap fonts so I have this code working. Is there anyway to set a pixel using TFPImageCanvas? I also couldn’t figure out how to set the brush color (confusing reference once again). It looks like Lazarus has good classes but they’re so hard to discover and learn because the references aren’t complete and in one place.What’s the best way to do this? Thanks.procedure DrawBitmap;var image: TFPMemoryImage; canvas: TFPImageCanvas; writer: TFPWriterPNG;begin image := TFPMemoryImage.Create(100, 100); canvas := TFPImageCanvas.Create(image); canvas.Clear; canvas.Brush.FPColor := colRed; // how do I set the color as an RGB? canvas.Rectangle(0, 0, 1, 1); // how do I draw a single pixel? writer := TFPWriterPNG.Create; image.SaveToFile('bitmap.png', writer);end;Regards, Ryan Joseph___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal