flat assembler
Message board for the users of flat assembler.

Index > Windows > Code for visualization

Author
Thread Post new topic Reply to topic
SeryZone



Joined: 20 Dec 2013
Posts: 38
Location: Ukraine, Kryviy Rih
SeryZone 07 Apr 2014, 14:24
I very 'young' for writing full programs on assembler, therefore I think, that I should optimize existing delphi code.
Here - visualization:
Code:
begin
        step := ln(max/min);
        index := 0; // cnt := 0;
        for y := 0 to maxy - 1 do
          for x := 0 to maxx - 1 do
          begin
            if (IterDat[x, y] >= max) then
            begin
              buffer[index] := 255; // red
              buffer[index + 1] := 255; // green
              buffer[index + 2] := 255; // blue
            end
            else if (IterDat[x, y] > 0) then
            begin
              ColorIndex := round( 4096*( ln(IterDat[x,y]/min)/step )  ) mod 4096;
              buffer[index] := pal[ColorIndex].b; // red
              buffer[index + 1] := pal[ColorIndex].g; // green
              buffer[index + 2] := pal[ColorIndex].r; // blue
            end;
            inc(index, 4)
          end;
      end;
SetDIBitsToDevice(Form1.Image1.Canvas.Handle, 0, 0, Maxx, Maxy,0,0,0, maxy, @Buffer[0], MyBMInfo, DIB_RGB_COLORS);    


I have some variables: min, max, ColorIndex (integer), Iterdat(dynamic 2-dimensions array), buffer(dynamic array of byte = Length(iterdat)*4 - color map), maxx, maxy(integer width and height of IterDat array) and pal[] - array with 4096 indexes of palette. That's work slowly.

Code:
;visualizing
format MS COFF
;data for visualization
extrn maxx        ;Width
extrn maxy        ;Height
extrn IterDat     ;Data
extrn min         ;Minimum
extrn max         ;Maximum
extrn pal         ;palette

Visualize:
    ; Calculating
    invoke SetDIBItsToDevice, ; Howto???
                                                                                 

Here - all, that I could do... Please, explain me, how to do it...
Post 07 Apr 2014, 14:24
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20416
Location: In your JS exploiting you and your system
revolution 07 Apr 2014, 14:27
The first place to start is the MS documentation for each API

Then you can write it like this:
Code:
invoke GetDC
mov [DC],eax ;save for later
invoke SetDIBItsToDevice,[DC],0,0,[maxx],...    
Post 07 Apr 2014, 14:27
View user's profile Send private message Visit poster's website Reply with quote
SeryZone



Joined: 20 Dec 2013
Posts: 38
Location: Ukraine, Kryviy Rih
SeryZone 07 Apr 2014, 14:44
revolution wrote:
The first place to start is the MS documentation for each API

Then you can write it like this:
Code:
invoke GetDC
mov [DC],eax ;save for later
invoke SetDIBItsToDevice,[DC],0,0,[maxx],...    


Thanks, but I have on Delphi variable MyBMInfo (BItmapInfo). How to get DC from BitMap info or BitMap?

And, maybe, I must add this:

Code:
extrn bmp ;BitMap
    
Post 07 Apr 2014, 14:44
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20416
Location: In your JS exploiting you and your system
revolution 07 Apr 2014, 14:51
Bitmaps don't have DCs as such. But you can use CreateDC and then select a bitmap into the DC (with SelectObject) and use the standard GDI functions with it.
Post 07 Apr 2014, 14:51
View user's profile Send private message Visit poster's website Reply with quote
SeryZone



Joined: 20 Dec 2013
Posts: 38
Location: Ukraine, Kryviy Rih
SeryZone 07 Apr 2014, 15:08
okay, like this???
Code:
;visualizing
format MS COFF
;data for visualization

public Visualize

extrn maxx        ;Width
extrn maxy        ;Height
extrn IterDat     ;Data
extrn min         ;Minimum
extrn max         ;Maximum
extrn pal         ;palette
extrn bmp

DC rd 1

Visualize:
    ; Calculating
    invoke getDC
    invoke CreateDC, 0,0,bmp,0 ;What I must write???
    mov [DC], eax
    invoke SetDIBItsToDevice,[DC],0,0,[maxx],[maxy] ; Howto???

                                                                           
Post 07 Apr 2014, 15:08
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20416
Location: In your JS exploiting you and your system
revolution 07 Apr 2014, 15:13
CreateDC deals with devices so it can't be used upon a bitmap. You need to use SelectObject to load the bitmap into the DC. And if you use CreateDC then you don't need GetDC. There is also CreateCompatibleDC which might be more appropriate depending upon what you are doing.

BTW: The MS docs are pretty extensive and informative on the use of DCs (Device Contexts).
Post 07 Apr 2014, 15:13
View user's profile Send private message Visit poster's website Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 07 Apr 2014, 15:56
SeryZone,

Division is a slow operation, ln(IterDat[x,y]/min) can be written as ln(IterDat[x,y])-ln(min) (with some accuracy lost, probably).

Are IterDat[] items contained in range [min, max) (or [min, max])?
Post 07 Apr 2014, 15:56
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20416
Location: In your JS exploiting you and your system
revolution 07 Apr 2014, 16:07
baldr wrote:
Division is a slow operation ...
Premature optimisation at work here! Wink How about we just stick to getting it working first and see if there is a noticeable performance impact before we start looking into alternative division techniques?
Post 07 Apr 2014, 16:07
View user's profile Send private message Visit poster's website Reply with quote
SeryZone



Joined: 20 Dec 2013
Posts: 38
Location: Ukraine, Kryviy Rih
SeryZone 07 Apr 2014, 16:14
baldr wrote:
SeryZone,

Division is a slow operation, ln(IterDat[x,y]/min) can be written as ln(IterDat[x,y])-ln(min) (with some accuracy lost, probably).

Are IterDat[] items contained in range [min, max) (or [min, max])?


Oh, I forgot to replace division))) Thank you!
no, only some data in IterDat() in range [min; max). If smaller than min - first color in palette (pal[0]). if more than max - last color in palette (pal[4095]).
Post 07 Apr 2014, 16:14
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 07 Apr 2014, 22:13
revolution,

We surely should look at the source. Somehow it makes me to say "wrong structure" right away.
Post 07 Apr 2014, 22:13
View user's profile Send private message Reply with quote
SeryZone



Joined: 20 Dec 2013
Posts: 38
Location: Ukraine, Kryviy Rih
SeryZone 08 Apr 2014, 12:26
baldr wrote:
revolution,

We surely should look at the source. Somehow it makes me to say "wrong structure" right away.


You want to see delphi source?
Post 08 Apr 2014, 12:26
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20416
Location: In your JS exploiting you and your system
revolution 08 Apr 2014, 12:33
SeryZone wrote:
You want to see delphi source?
No. We want to see assembly source.
Post 08 Apr 2014, 12:33
View user's profile Send private message Visit poster's website Reply with quote
SeryZone



Joined: 20 Dec 2013
Posts: 38
Location: Ukraine, Kryviy Rih
SeryZone 08 Apr 2014, 13:16
Code:
;visualizing
format MS COFF
;data for visualization
include 'macro\if.inc'

public Visualize

extrn maxx        ;Width
extrn maxy        ;Height
extrn IterDat     ;Data
extrn min         ;Minimum
extrn max         ;Maximum
extrn pal         ;palette
extrn bmp

DC rd 1
buffer rd maxx*maxy
BMInfo BITMAPINFOHEADER sizeof.BITMAPINFOHEADER, [maxx], [maxy], 1, 32, 0, maxx*maxy*4

Visualize:
    ; Calculating
    mov [DC], eax

    fld qword [max], st0 ;move maximum to register st0
    fdiv min             ;and divide in on minimum
    fld1 st1             ;move 1 to st1 for result
    fyl2x                ;compute log2(st0)*st1 and move result to st1


    mov  ecx,maxx*maxy
@@:   ;How to make cycle and how to call x and y in array???

loop @b

    invoke SetDIBItsToDevice,[DC],0,0,[maxx],[maxy],0,0,0,maxy,buffer,BMInfo


                                                                                                                 


Here, code without cycles.[/code]
Post 08 Apr 2014, 13:16
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.