• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 340
  • Last Modified:

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

Does anybody know how to implement FX (in pascal/better asm)
as Blur,Distort, or smth else???
0
jack_p50
Asked:
jack_p50
  • 12
  • 10
  • 7
  • +1
1 Solution
 
scrapdogCommented:
Which one?
0
 
jack_p50Author Commented:
Both (or more than both)
0
 
jack_p50Author Commented:
Adjusted points to 50
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
scrapdogCommented:
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
 
jack_p50Author Commented:
Blur makes image smoother and remove rough, but, of course, lowers image quality.
Distort adds some waves/ripples to image.
0
 
viktornetCommented:
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
 
scrapdogCommented:
>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
 
viktornetCommented:
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
 
scrapdogCommented:
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
 
viktornetCommented:
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
 
scrapdogCommented:
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
 
viktornetCommented:
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
 
scrapdogCommented:
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
 
viktornetCommented:
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
 
scrapdogCommented:
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
 
viktornetCommented:
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
 
scrapdogCommented:
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
 
viktornetCommented:
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
 
viktornetCommented:
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
 
scrapdogCommented:
>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
 
scrapdogCommented:
>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
 
jack_p50Author Commented:
Scaling and rotating is very easy, i need only methods (not source) of blur...
0
 
viktornetCommented:
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
 
jack_p50Author Commented:
My e-mail is : jack_p50@usa.net
Sorry about 100 pts - i have no more yet :(
0
 
viktornetCommented:
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
 
jack_p50Author Commented:
Hey, why don't you sending it (jack_p50@usa.net)
0
 
viktornetCommented:
Opppssss... Sorry.... I forgot.... Ok here it is... I'll send it to you in a few minutes.. :) I promise

Cheers,
Viktor
0
 
viktornetCommented:
Ok, I sent it to you

Regards,
Viktor Ivanov
0
 
RkMkCommented:
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
 
jack_p50Author Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

  • 12
  • 10
  • 7
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now