Jump to content

Flemming

Members
  • Content Count

    47
  • Joined

  • Last visited

  1. Flemming

    Pixi js NormalMap

    Nevermind! I must admit that this isn't the right solution for my project. Now i'm forced to go native with three.js. It must be the eseast and best bumpmap visualizer for the web. It would be nice if three.js was completely wrapped but i can't wait anymore.
  2. Flemming

    Pixi js NormalMap

    Hi Is it possible to get NormalMapFilter.js wrapped ? I would like to recreate this cool demo in sms: http://www.goodboydigital.com/pixijs/examples/20/ In case you will do it, the necessary files are in the attachment. Thanks Flemming pixi-normalmap.zip
  3. Flemming

    Add form navigation to TW3CustomGameApplication

    Ok - the Mega Demo showed me how to do it. I just changed it to a TW3GraphicControl, and it works fine now :-)
  4. Hi I started a project with the ArcSpiral demo as template. Now i realized that i want some forms and form-navigation. I tried adding this to TApplication.ApplicationStarting: FFormMain := TFormMain.Create(Display.View); FFormMain.Name := 'Main'; RegisterFormInstance(FFormMain, True); ... but how do i navigate between the form and the game-app ?
  5. 1. When i search with "Find in files" i allways get the "Not found" info messagebox, even when there is a search result ? 2. The "whole words" checkbox is not working ! 3. In the right of the messagebox there's a "Auto Hide" button. Clicking it gives me the error: "Control 'CustomDockPanel_PopupPanel' has no parent window" - and then i get this error every time i do a seach.
  6. Flemming

    Where is TRect ?

    Hi I can't find out where to find TRect in ver. 2.1 beta-2 ? It's not in smartCL.System ?
  7. Flemming

    Web Worker not working in Chrome

    Hi I can't get Web Worker running in Chrome ? Have tried the demo to.
  8. Flemming

    Parse ImageData with JSON

    A little change here ! In the process of implementing the code in the Worker i realized that i could'n use btoa() and atob() !? So i replaced them with the functions from System.Encoding.pas. Do you know why they are not supported in sms workers ?
  9. Flemming

    Parse ImageData with JSON

    I finally came to a solution that works. I tried to compare the encoding speed of System.Encoding.pas with the javascript btoa and found the javascript to be about 6 times faster. So i came up with this : // ---------------------------------- In the Worker thread TMyImageData = Record width : integer; height : integer; data : JUInt8ClampedArray; end; function Base64Encode_MyImageData(MyImgData:TMyImageData):string; var data,w,h : variant; begin w:=MyImgData.width; h:=MyImgData.height; data:=MyImgData.data; asm var w1 = (@w & 0xFF); var w2 = ((@w >> 8) & 0xFF); var h1 = (@h & 0xFF); var h2 = ((@h >> 8) & 0xFF); @Result=btoa(String.fromCharCode(w1)+String.fromCharCode(w2)+ String.fromCharCode(h1)+String.fromCharCode(h2)+ String.fromCharCode.apply(null, @data)); end; end; function Base64DecodeTo_MyImageData(b64:string):TMyImageData; var l : integer; begin asm var bytes=atob(@b64); @result.width=bytes.charCodeAt(0)+ (bytes.charCodeAt(1) << 8); @result.height=bytes.charCodeAt(2)+ (bytes.charCodeAt(3) << 8); end; l:=4*result.width*result.height; result.data:=new JUInt8ClampedArray(l); asm for (var i=4;i<bytes.length;i++) { @result.data[i-4]=bytes.charCodeAt(i); }; end; end; // -------------------------------- In the main app function Base64DecodeTo_ImageData(b64:string):TW3ImageData; var l,w,h,i : integer; Handle : variant; cont : TW3GraphicContext; canv : TW3Canvas; imgdata : JUInt8ClampedArray; begin asm var bytes=atob(@b64); @w=bytes.charCodeAt(0)+ (bytes.charCodeAt(1) << 8); @h=bytes.charCodeAt(2)+ (bytes.charCodeAt(3) << 8); end; Cont:=TW3GraphicContext.Create(Null); Cont.Allocate(w,h); Canv:=TW3Canvas.Create(Cont); Result:=Canv.toImageData; Handle:=Result.Handle; l:=4*w*h; imgdata:=new JUInt8ClampedArray(l); asm for (var i=4;i<bytes.length;i++) { @imgdata[i-4]=bytes.charCodeAt(i); }; end; for i:=0 to l-1 do Handle.data[i]:=imgdata[i]; // Handle.data.set(imgdata); Canv.Free; Cont.Free; end; function Base64Encode_ImageData(ImgData:TW3ImageData):string; var data,w,h : variant; begin w:=imgdata.Handle.width; h:=imgdata.Handle.height; data:=imgdata.Handle.data; asm var w1 = (@w & 0xFF); var w2 = ((@w >> 8) & 0xFF); var h1 = (@h & 0xFF); var h2 = ((@h >> 8) & 0xFF); @Result=btoa(String.fromCharCode(w1)+String.fromCharCode(w2)+ String.fromCharCode(h1)+String.fromCharCode(h2)+ String.fromCharCode.apply(null, @data)); end; end; . . . Base64Encoded:=Base64Encode_ImageData(imagedata); // Post to Worker ------------------------------------ MyImageData:=Base64DecodeTo_MyImageData(base64Encoded); // Paint something in the Worker ... for i:=0 to MyImageData.width-1 do MyImageData.data[4*(i+i*MyImageData.width)+1]:=255; Base64Encoded:=Base64Encode_MyImageData(MyImageData); // Post back to DOM document ---------------------------------- W3PaintBox1.canvas.putimagedata(Base64DecodeTo_ImageData(Base64Encoded),0,0); . . . The Base64DecodeTo_ImageData isn't pretty so i will welcome any feedback on optimization ! ;-) Can't use the Handle.data.set(imgdata) to transfer the array ?
  10. Flemming

    Parse ImageData with JSON

    @kdtop3 thanks for your links ! It gives me an idea on how the base64 decoding works, but in respect to performance a javascript written decoder would be preferred. I want to transfer image data to a worker for imageprocessing and back again, and i try to do that without the use of DOM dependend objects in the worker. My samplecode is only to ensure that the encoding/decoding works. It would be nice if i could use base64 but im not sure how to do that in the worker without a canvas class ? If i can parse it to a TW3ImageData or some kind of array it would be fine.
  11. Flemming

    Parse ImageData with JSON

    It should work ! The width, height and data are correctly parsed to the H2 handle, but i can't access the properties through imgdata2 ?
  12. Flemming

    Parse ImageData with JSON

    I started out using the base64 solution, but then i found out that the Web Worker have no access the the DOM objects. I need to make some pixel processing in the Worker and the common java-solution for that is using the ImageData class. I dont know how to decode the base64 string in the Worker without a DOM object ? Im not sure about how the JSON part should work in this case, but could it possibly have something to do with the sms-classes being encoded with the ImageData.data part ? I tried using the handle but doesn seem to work either : ... H:=imgdata.Handle; asm @mText = JSON.stringify(@H); end; imgdata2 :=TW3ImageData.Create; H2:=imgdata2.Handle; asm @H2 = JSON.parse(@mText); end; ... Maybe i should copy the data to a UInt8ClampedArray ?
  13. Flemming

    Parse ImageData with JSON

    Hi I want to parse the content of a TW3ImageData with JSON for the use with Web Worker. But something is not working in the JSON/ImageData convertion. I made a little test sample : procedure TForm1.W3Button3Click(Sender: TObject); var imgdata, imgdata2: TW3ImageData; cont: TW3GraphicContext; canv: TW3Canvas; mText: string; begin img := TW3Image.Create(self); img.LoadFromURL('res/red3.png'); img.OnLoad := procedure (Sender: TObject) var i: integer; begin if img.Ready then begin Cont:=TW3GraphicContext.Create(null); try Cont.Allocate(img.Width,img.Height); canv:=TW3Canvas.Create(Cont); try canv.DrawImageF(img.Handle,0,0); imgdata:=canv.toImageData(); asm @mText = JSON.stringify(@imgdata); end; //... mText To the Worker and back again ... imgdata2 :=TW3ImageData.Create; asm @imgdata2 = JSON.parse(@mText); end; W3PaintBox1 := TW3PaintBox.Create(self); W3PaintBox1.top:=20; W3PaintBox1.width:=10; W3PaintBox1.height:=10; W3PaintBox1.canvas.putimagedata(imgdata2,0,0); finally canv.free; end; finally cont.free; end; end; end; end; The stringify'ed version of imgdata looks like this : {"ClassType":{"$ClassName":"TW3ImageData","$Parent":{"$ClassName":"TObject","$Parent":null}},"FHandle$1":{"height":3,"width":3,"data":{"0":200,"1":50,"2":0,"3":255,"4":200,"5":50,"6":0,"7":255,"8":200,"9":50,"10":0,"11":255,"12":200,"13":50,"14":0,"15":255,"16":200,"17":50,"18":0,"19":255,"20":200,"21":50,"22":0,"23":255,"24":200,"25":50,"26":0,"27":255,"28":200,"29":50,"30":0,"31":255,"32":200,"33":50,"34":0,"35":255,"length":36}}}
  14. Flemming

    Wrap Leap Motion ?

    Thanks André !!! :-) Can't wait to try it out ! Hopefully i will get it working, but anyway it's definitely worth a try ;-)
  15. Flemming

    Wrap Leap Motion ?

    I have been following the progress in Leap Motion the past year, but haven't bought it yet because of the lack of pascal support. If you guys would wrap it i'll buy it right away ! There's so many oportunitys for making cutting edge development with the Leap controller ! :-)
×