Board index » delphi » "buttonised" effect on bitmaps

"buttonised" effect on bitmaps

I currently have 100 or so bmp images that I wish to convert to a buttonised
effect (curved edges, ie a gradual color shift form base to highlight.
Lightened top, left and darkened right, bottom). I could use a proffessional
graphics package to get the effect I desire, but i would rather do it
"dynamically", allowing me to apply this technique on a variety of other
bitmap images at some future point.

I have a working unit this achieves this, but really screws up when it
encounters clRed (0000ff) or indeed any high intensity colours while I am
trying to "lighten" the image ( in this example, it generates a subtle shade
of fuchsia, which, while different, is not the desired effect!).

Does anyone have such algorithms/units around or know where i can get one
from?

KevanB

 

Re:"buttonised" effect on bitmaps


If you would care to share your source code, I could try and find your
errors.

--
Jon Perry
pe...@globalnet.co.uk

Quote
KevanB <k...@a-t-f.demon.co.uk> wrote in message

news:7v3u7g$jqu2@forums.borland.com...
Quote
> I currently have 100 or so bmp images that I wish to convert to a
buttonised
> effect (curved edges, ie a gradual color shift form base to highlight.
> Lightened top, left and darkened right, bottom). I could use a
proffessional
> graphics package to get the effect I desire, but i would rather do it
> "dynamically", allowing me to apply this technique on a variety of other
> bitmap images at some future point.

> I have a working unit this achieves this, but really screws up when it
> encounters clRed (0000ff) or indeed any high intensity colours while I am
> trying to "lighten" the image ( in this example, it generates a subtle
shade
> of fuchsia, which, while different, is not the desired effect!).

> Does anyone have such algorithms/units around or know where i can get one
> from?

> KevanB

Re:"buttonised" effect on bitmaps


Jon, I have emailed the source code directly to you, rather than clutter up
this NG.

KevanB

Re:"buttonised" effect on bitmaps


I haven't received any such email!

--
Jon Perry
pe...@globalnet.co.uk

Quote
KevanB <k...@a-t-f.demon.co.uk> wrote in message

news:7v6pbt$d744@forums.borland.com...
Quote
> Jon, I have emailed the source code directly to you, rather than clutter
up
> this NG.

> KevanB

Re:"buttonised" effect on bitmaps


Yes I have. You are called 'demon', not KevanB!

--
Jon Perry
pe...@globalnet.co.uk

Quote
Jon Perry <pe...@globalnet.co.uk> wrote in message

news:7v7nf4$j7022@forums.borland.com...
Quote
> I haven't received any such email!

> --
> Jon Perry
> pe...@globalnet.co.uk

> KevanB <k...@a-t-f.demon.co.uk> wrote in message
> news:7v6pbt$d744@forums.borland.com...
> > Jon, I have emailed the source code directly to you, rather than clutter
> up
> > this NG.

> > KevanB

Re:"buttonised" effect on bitmaps


else
    begin
       if c>200 then   // adjustment attempt for high intensity values :(
          value := 2*value /3;
      i := round(c * value);
      Minmax(i, 0, 255);
      result := i;

This section of code looks weak.

For the lighten case, value is from LADJUST, i.e. either 1.8, 1.73, 1.6,
1.4.

You then change this value directly, with no reason to 2*value/3. I can see
no example of you using LADJUST except for this.
.

procedure minmax(var i : Integer; mn, mx : Integer);
  begin
    if i > mx then i := mx;
    if i < mn then i := mn;
  end;

is declaring i as a local variable, which doesn't change the global i
variable, i.e. i is the same i as before calling minmax.

which you assign to result.

Try minmax as a function ( and call it boundary, minmax usually means
MinMax(4,5) gives Min=4 Max=5;)

function Boundary(number,lowerrange,upperrange:integer):integer;
begin
if number>upperrange then Boundary:=upperrange;
if number<lowerrange then Boundary:=lowerrange;
Boundary:=number;
end;

and

      i := round(c * value);
      result:=Boundary(i, 0, 255);

Hope this works.
--
Jon Perry
pe...@globalnet.co.uk

Quote
Jon Perry <pe...@globalnet.co.uk> wrote in message

news:7v7nf4$j7022@forums.borland.com...
Quote
> I haven't received any such email!

> --
> Jon Perry
> pe...@globalnet.co.uk

> KevanB <k...@a-t-f.demon.co.uk> wrote in message
> news:7v6pbt$d744@forums.borland.com...
> > Jon, I have emailed the source code directly to you, rather than clutter
> up
> > this NG.

> > KevanB

Re:"buttonised" effect on bitmaps


This email, although correct in essence, was wrong in too many places, so I
have redone it.

The first point was completely wrong, you do pass different values to value.

The second point, although in my opinion the source of the problem, and
fixable the way I suggested, contained an incorrect function Boundary, which
will equally return number whatever.

I suggest :

Procedure Boundary(number,lowerrange,upperrange:integer);
begin
if number>upperrange then number:=upperrange;
if number<lowerrange then number:=lowerrange;
i:=number;
end;

which will alter the global i, and hence give the result required.

--
Jon Perry
pe...@globalnet.co.uk

Quote
Jon Perry <pe...@globalnet.co.uk> wrote in message

news:7v7pfk$mgl1@forums.borland.com...
Quote
> else
>     begin
>        if c>200 then   // adjustment attempt for high intensity values :(
>           value := 2*value /3;
>       i := round(c * value);
>       Minmax(i, 0, 255);
>       result := i;

> This section of code looks weak.

> For the lighten case, value is from LADJUST, i.e. either 1.8, 1.73, 1.6,
> 1.4.

> You then change this value directly, with no reason to 2*value/3. I can
see
> no example of you using LADJUST except for this.
> .

> procedure minmax(var i : Integer; mn, mx : Integer);
>   begin
>     if i > mx then i := mx;
>     if i < mn then i := mn;
>   end;

> is declaring i as a local variable, which doesn't change the global i
> variable, i.e. i is the same i as before calling minmax.

> which you assign to result.

> Try minmax as a function ( and call it boundary, minmax usually means
> MinMax(4,5) gives Min=4 Max=5;)

> function Boundary(number,lowerrange,upperrange:integer):integer;
> begin
> if number>upperrange then Boundary:=upperrange;
> if number<lowerrange then Boundary:=lowerrange;
> Boundary:=number;
> end;

> and

>       i := round(c * value);
>       result:=Boundary(i, 0, 255);

> Hope this works.
> --
> Jon Perry
> pe...@globalnet.co.uk

> Jon Perry <pe...@globalnet.co.uk> wrote in message
> news:7v7nf4$j7022@forums.borland.com...
> > I haven't received any such email!

> > --
> > Jon Perry
> > pe...@globalnet.co.uk

> > KevanB <k...@a-t-f.demon.co.uk> wrote in message
> > news:7v6pbt$d744@forums.borland.com...
> > > Jon, I have emailed the source code directly to you, rather than
clutter
> > up
> > > this NG.

> > > KevanB

Re:"buttonised" effect on bitmaps


Hi Jon,

maybe we have very different delphi-compilers ;-) ... but if i define a
procedure's variable with "var", then i can change it's value in the
procedure to get a different value back.

procedure ChangeValue(var number:integer; newval:integer);
begin
  number := newval;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  i : integer;
begin
  i := 1;
  showmessage(inttostr(i));
  changevalue(i, 5);
  showmessage(inttostr(i));
end;

So you don't have to use global vars just to change them by another
procedure...

Quote
Jon Perry <pe...@globalnet.co.uk> wrote in message

news:7v7qjp$mgl4@forums.borland.com...
Quote

> I suggest :

> Procedure Boundary(number,lowerrange,upperrange:integer);
> begin
> if number>upperrange then number:=upperrange;
> if number<lowerrange then number:=lowerrange;
> i:=number;
> end;

> which will alter the global i, and hence give the result required.

> --
> Jon Perry
> pe...@globalnet.co.uk

> Jon Perry <pe...@globalnet.co.uk> wrote in message
> news:7v7pfk$mgl1@forums.borland.com...

> > procedure minmax(var i : Integer; mn, mx : Integer);
> >   begin
> >     if i > mx then i := mx;
> >     if i < mn then i := mn;
> >   end;

> > is declaring i as a local variable, which doesn't change the global i
> > variable, i.e. i is the same i as before calling minmax.

> > which you assign to result.

> > Try minmax as a function ( and call it boundary, minmax usually means
> > MinMax(4,5) gives Min=4 Max=5;)

> > function Boundary(number,lowerrange,upperrange:integer):integer;
> > begin
> > if number>upperrange then Boundary:=upperrange;
> > if number<lowerrange then Boundary:=lowerrange;
> > Boundary:=number;
> > end;

> > and

> >       i := round(c * value);
> >       result:=Boundary(i, 0, 255);

Re:"buttonised" effect on bitmaps


Quote
In article <7v7pfk$m...@forums.borland.com>, Jon Perry wrote:
> procedure minmax(var i : Integer; mn, mx : Integer);
>   begin
>     if i > mx then i := mx;
>     if i < mn then i := mn;
>   end;

> is declaring i as a local variable, which doesn't change the global i
> variable, i.e. i is the same i as before calling minmax.

I presume that you haven't actually tried this <g>

Passing a var parameter *will* update its value. Furthermore, your
*correction* (and that in your reply to yourself) is wrong and poorly
written.

BTW, publicly criticising code that people send you, is hardly the way to
get further help.

 Mike Orriss (TeamB)
 (Unless stated otherwise, my replies relate to Delphi 4.03/5.00)
 (Unsolicited e-mail replies will most likely be ignored)

Re:"buttonised" effect on bitmaps


Jon,

Thanks for the effort, but my problem wasnt so much getting the wrong
results per se, but that my "quick and {*word*193}" algorithm itself was at fault.

Since your reply I have adapted the algortihm to remove as much "clutter" as
possible, yet the solution itself still eludes me..

KevanB

Re:"buttonised" effect on bitmaps


It wasn't a critism, I thought that the local/global issue was a bug with
his code.

Sorry for being wrong, I'm not always right.

--
Jon Perry
pe...@globalnet.co.uk

Mike Orriss (TeamB) <m...@3kcc.co.uk> wrote in message
news:VA.000013e2.7b08222a@mikemain...

Quote
> In article <7v7pfk$m...@forums.borland.com>, Jon Perry wrote:
> > procedure minmax(var i : Integer; mn, mx : Integer);
> >   begin
> >     if i > mx then i := mx;
> >     if i < mn then i := mn;
> >   end;

> > is declaring i as a local variable, which doesn't change the global i
> > variable, i.e. i is the same i as before calling minmax.

> I presume that you haven't actually tried this <g>

> Passing a var parameter *will* update its value. Furthermore, your
> *correction* (and that in your reply to yourself) is wrong and poorly
> written.

> BTW, publicly criticising code that people send you, is hardly the way to
> get further help.

>  Mike Orriss (TeamB)
>  (Unless stated otherwise, my replies relate to Delphi 4.03/5.00)
>  (Unsolicited e-mail replies will most likely be ignored)

Re:"buttonised" effect on bitmaps


P.S. I tried it. Looks like I WAS right.

For example,

procedure Tform1.change(i:string);
begin
i:='Goodbye';
end;

procedure Tform1.button1click(sender:Tobject);
begin
i:='Hello'
edit1.text:=i;
change(i);
edit2.text:=i;
end;

prints Hello and Hello, amply demonstrating local privacy.

--
Jon Perry
pe...@globalnet.co.uk

Mike Orriss (TeamB) <m...@3kcc.co.uk> wrote in message
news:VA.000013e2.7b08222a@mikemain...

Quote
> In article <7v7pfk$m...@forums.borland.com>, Jon Perry wrote:
> > procedure minmax(var i : Integer; mn, mx : Integer);
> >   begin
> >     if i > mx then i := mx;
> >     if i < mn then i := mn;
> >   end;

> > is declaring i as a local variable, which doesn't change the global i
> > variable, i.e. i is the same i as before calling minmax.

> I presume that you haven't actually tried this <g>

> Passing a var parameter *will* update its value. Furthermore, your
> *correction* (and that in your reply to yourself) is wrong and poorly
> written.

> BTW, publicly criticising code that people send you, is hardly the way to
> get further help.

>  Mike Orriss (TeamB)
>  (Unless stated otherwise, my replies relate to Delphi 4.03/5.00)
>  (Unsolicited e-mail replies will most likely be ignored)

Re:"buttonised" effect on bitmaps


Quote
In article <7vcvqa$5...@forums.borland.com>, Jon Perry wrote:
> P.S. I tried it. Looks like I WAS right.

Are you trying to wind me up?

You first complained that a routine was wrong because it did not change
the caller's value.

Now you say that you were right because you have demonstrated local
privacy!

It appears to me as if you are not reading these threaded newsgroups
correctly and are thus losing the context of conversations.

 Mike Orriss (TeamB)
 (Unless stated otherwise, my replies relate to Delphi 4.03/5.00)
 (Unsolicited e-mail replies will most likely be ignored)

Re:"buttonised" effect on bitmaps


You didn't see the code.

He called a function minmax, trying to change a global variable i. Only the
function mimmax used a local variable i, which he tried to change the global
variable i into. Only it didn't work. Like my example, where, if I was to
expect 'Hello', and 'Goodbye', I would have been wrong.

The other point was that the only time he used this variable 'value', he
changed it by 2/3, which I pointed out was pointless.

The first procedure I created used immediate returns, i.e. set the result
and then the function ends. Incorrect I know, that is why I corrected it.

Haven't you got anyone else to pester?

--
Jon Perry
pe...@globalnet.co.uk

Mike Orriss (TeamB) <m...@3kcc.co.uk> wrote in message
news:VA.0000141e.86342ba6@mikemain...

Quote
> In article <7vcvqa$5...@forums.borland.com>, Jon Perry wrote:
> > P.S. I tried it. Looks like I WAS right.

> Are you trying to wind me up?

> You first complained that a routine was wrong because it did not change
> the caller's value.

> Now you say that you were right because you have demonstrated local
> privacy!

> It appears to me as if you are not reading these threaded newsgroups
> correctly and are thus losing the context of conversations.

>  Mike Orriss (TeamB)
>  (Unless stated otherwise, my replies relate to Delphi 4.03/5.00)
>  (Unsolicited e-mail replies will most likely be ignored)

Re:"buttonised" effect on bitmaps


Quote
Jon Perry wrote:
>You didn't see the code.

>He called a function minmax, trying to change a global variable i. Only the
>function mimmax used a local variable i, which he tried to change the global
>variable i into. Only it didn't work. Like my example, where, if I was to
>expect 'Hello', and 'Goodbye', I would have been wrong.

To quote from your post:

<quote>
procedure minmax(var i : Integer; mn, mx : Integer);
  begin
    if i > mx then i := mx;
    if i < mn then i := mn;
  end;

is declaring i as a local variable, which doesn't change the global i
variable, i.e. i is the same i as before calling minmax.
</quote>

What you say in your last paragraph is plain wrong. the "var i:
Integer;" parameter is a reference to the actual integer that's
passed. Changing i will in fact change the actual global variable
passed to it.

--
Rudy Velthuis

Go to page: [1] [2]

Other Threads