Solved

FX like Blur,Distort,...(as in Photoshop)

Posted on 1998-11-05
30
291 Views
Last Modified: 2010-04-16
Does anybody know how to implement FX (in pascal/better asm)
as Blur,Distort, or smth else???
0
Comment
Question by:jack_p50
  • 12
  • 10
  • 7
  • +1
30 Comments
 
LVL 5

Expert Comment

by:scrapdog
ID: 1215943
Which one?
0
 
LVL 4

Author Comment

by:jack_p50
ID: 1215944
Both (or more than both)
0
 
LVL 4

Author Comment

by:jack_p50
ID: 1215945
Adjusted points to 50
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1215946
I know how to do effects on graphics, but I have never used Photoshop so I don't know what the effect of these effects are. :)
0
 
LVL 4

Author Comment

by:jack_p50
ID: 1215947
Blur makes image smoother and remove rough, but, of course, lowers image quality.
Distort adds some waves/ripples to image.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1215948
I got a routine for blurring an image.... It does it exactly as Photoshop in a radius...

I can give it to you if you get your points to 100 and let scrapdog answer the question and get the points... Otherwise I don't think the code should be given...

btw- Kevin, would you please teach me a few graphics effects?? I mean how to do graphic effects in programming??

Cheers,
Viktor
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1215949
>I can give it to you if you get your points to 100 and let
>scrapdog answer the question and get the points...

If you give him the routine, YOU should get the points :)

>btw- Kevin, would you please teach me a few graphics effects??
>I mean how to do graphic effects in programming??

Sure.  Any you have in mind?

0
 
LVL 10

Expert Comment

by:viktornet
ID: 1215950
I don't know..just tell me a few routines you know...Choose the easiest so I can learn 'em and be ready for the challenges ;)

>If you give him the routine, YOU should get the points :)
I'd just want you to get that t-shirt ;-)

Cheers,
Viktor
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1215951
I don't know..just tell me a few routines you know...Choose the easiest so I can learn 'em and be ready for the challenges ;)

To start, look at the rotate and scale functions that I posted a couple of weeks ago...it should be somewhere in the PAQ (in Pascal).  It is free for you because I remember you getting in on the discussion.

>I'd just want you to get that t-shirt ;-)

You are getting closer to the t-shirt than I am!! :)

0
 
LVL 10

Expert Comment

by:viktornet
ID: 1215952
I think I still got it here somewhere, but even if I look I don't understand why things are happening that way... Would you please explain it to me... Why you do that?? and so on....

Vik
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1215953
As soon as you understand trigonometry, you will understand these functions...however, if you don't have a good understanding of trig it is very hard to explain.

Basically, all graphics effects involve a transformation of some sort.  Graphic A transforms into B.  In the case of rotation and scaling (and even blur and distort), A and B are 2d surfaces.

I like to do it backwards.  I like to take every pixel in B, do the transformation backwards, and find which pixel in A goes in B.  I make a loop that covers every pixel in B (for x :=0 to 319 do for y := 0 to 199 do  etc.), then for each of these pixels, find which coordinates of A (the original image) goes in x,y in B (the new image).

In the case of rotation, you would apply a function that includes sine and cosine (you will see this in the code).

A very SIMPLE transformation you can start out with is inverting the screen horizontally.  For each value (x,y) in B, you take (319-x,y) from A.  Do you understand why this works?

Here is pseudocode:

for x := 0 to 319 do
  for y := 0 to 199 do
    NewImage[x,y] := OldImage[319-x,y];

if you wanted to invert it both horizontally AND vertically, you
would do this:

for x := 0 to 319 do
  for y := 0 to 199 do
    NewImage[x,y] := OldImage[319-x,199-y];

This is basically how all effects and transformations work.




0
 
LVL 10

Expert Comment

by:viktornet
ID: 1215954
I understand this one... :-) And I understand why it works... The sample program that I showed you in C/C++ actually you guessed what it does, I use something like that to do the backwords counting after it gets half of it...

for (int i = 0; i <= 10; i++){
  if (i > 5)
    cout << 10 - i;
  else
    cout << i;
}

Same thing...I understand this one...What's the next one?? Do you have any other similar to this one??

Cheers,
Viktor
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1215955
Let me see if YOU can figure it out..

Given two images, OldImage and NewImage, write a function (in pseudo code like I did), with parameters dx and dy (integers).

The function will shift the image dx pixels to the right and dy pixels down, and replaces the blank area with 0 and truncates anything that moves off the screen.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1215956
What do you mean by shift?? Move to right or left?? And when you truncate something what do you do?? I'm not very familiar with the vocabulary you use :-|

Here is a try anyway...

for x := 0 to 319 do
       for y := 0 to 199 do begin
            NewImage[x,y] := OldImage[x+dx,y+dy];
            OldImage[x+dx,y+dy] := 0;
end;

Don't understand everything you asked me to do, but here is a try...tell me what I had to do, and if this is is right or wrong,,,,
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1215957
for x := 0 to 319 do
  for y := 0 to 199 do begin
    NewX := x-dx;
    NewY := y-dy;
    if (NewX < 0) or (NewX > 319) or (NewY < 0) or (NewY > 199)
       then NewImage[x,y] := 0
    else NewImage[x,y] := OldImage[NewX, NewY];
end;

Note that I did not change OldImage at all.  Look VERY carefully at what this code does and why it works.  Also try to figure out why it is x-dx to shift to the right and not x+dx. (Remember I am transforming "backwards").  Trying this on graph paper might help you understand it.

By shifting, you got the right idea.  Truncating means that if any pixels are shifted off the screen (i.e. x>319 or y>199), then they are lost.
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 10

Expert Comment

by:viktornet
ID: 1215958
OK, I don't understand.... If you are moving from 0 to 319 for x, why would you have to subtract in order to shift to the right??

left  <----->  right
0    <------> 319
     x=5 + dx=4 we shift 4 to the right and get 9. o O Why do we need to subtract...

5-4 you shift 4 to the left....Can't figure out what's going on....

0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1215959
Another example: On a 320x200 screen with 16 million colors (i.e. no palette), this pseudo code would dim the screen by 50%. [this is only for demonstrative purposes; there are more efficient ways of doing it]

for x := 0 to 319 do
  for y := 0 to 199 do
    screen[x,y] := screen[x,y] shr 1;

0
 
LVL 10

Expert Comment

by:viktornet
ID: 1215960
Oh, you mean you want to read it backwards, and at the same time shift a few pixels????

If that's what you wanted, then I got your point... otherwise it is suppose to be as I tried to do it at the first place . o O
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1215961
Your example will get the value of the color and divide it by 2 and then put it back... Oh, that's a good one... How about if the color is black....0 what's gonna happen then??
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1215962
>How about if the color is black....0 what's gonna happen then??

0 / 2 = 0

Black is the darkest color.  You cannot get any darker.
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1215963
>Oh, you mean you want to read it backwards, and at the same
>time shift a few pixels????

Nope, not "read" it backwards, transform it backwards.

OldImage

ABCDEFGH
IJKLMNOP

If we want to shift 1 to the right, this is what the result would be:

NewImage

0ABCDEFG
0IJKLMNO


To understand why it is x-dx:

Look at pixel 3,0 in the NewImage.  It is a C.  Where did that come from?  It came from pixel 2,0 in OldImage.

To answer the question where did it come from:

x - dx  = OldImageX

3 - 1   = 2

so we extract from pixel 2,0 in the OldImage.  If we wanted to shift to the left, we would ADD dx.
0
 
LVL 4

Author Comment

by:jack_p50
ID: 1215964
Scaling and rotating is very easy, i need only methods (not source) of blur...
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1215965
I can give you sources and methods on how to Blur as long as you do what I told you... It does it exactly like PhotoShop 4 :)

Cheers,
Viktor
0
 
LVL 4

Author Comment

by:jack_p50
ID: 1215966
My e-mail is : jack_p50@usa.net
Sorry about 100 pts - i have no more yet :(
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1215967
Ok, I see you are 15,,, I'll give it to you w/o increasing the points... I'll send it to you in a few hours....

Cheers,
Viktor
0
 
LVL 4

Author Comment

by:jack_p50
ID: 1215968
Hey, why don't you sending it (jack_p50@usa.net)
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1215969
Opppssss... Sorry.... I forgot.... Ok here it is... I'll send it to you in a few minutes.. :) I promise

Cheers,
Viktor
0
 
LVL 10

Accepted Solution

by:
viktornet earned 50 total points
ID: 1215970
Ok, I sent it to you

Regards,
Viktor Ivanov
0
 

Expert Comment

by:RkMk
ID: 1215971
i think it ll work
for Horizonal-BLUR
for y := 0 to maxy do
for x := 0 to maxx-1  do
   putpixel(x,y,(getpixel(x)+getpixel(x+1)) shr 1);
   
   
0
 
LVL 4

Author Comment

by:jack_p50
ID: 1215972
yes, it's something like that, but better to use 2 pages, because the next
pixel you put will be affected by that you put before. It's better to take
some radius pixels (i.e. 5x5 around your pixel), and calculate their
ariphmetical average (of r,g,b; because just averaging color numbers, you won't get anything), then find closest_color. Even in true-color
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
HOW TO: Upload an ISO image to a VMware datastore for use with VMware vSphere Hypervisor 6.5 (ESXi 6.5) using the vSphere Host Client, and checking its MD5 checksum signature is correct.  It's a good idea to compare checksums, because many installat…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now