Solved

Help converting MS "C" sample code

Posted on 1998-03-05
37
230 Views
Last Modified: 2010-04-06
I've been trying to convert some C code with not much luck. The C code is a sample that fades a bitmap from black to color. After completely rewriting the sample in D3(3times), spending many days, hours, and many Evariant conversion errors, I realized I'm in over my head on this one. Does any one have converted D3 source of the following of fadein.c from microsoft. The source is at http://support.microsoft.com/support/kb/articles/q149/8/55.asp It's a self extracting exe

Much thanks in advance for even considering this conversion.

I dont want a compiled component because I want to take this code method/concept a lot further.

//Steve
//sbsullivan@ucdavis.edu
     
0
Comment
Question by:sz3905
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 19
  • 9
  • 9
37 Comments
 
LVL 8

Expert Comment

by:ZifNab
ID: 1360114
Hi,  sz3905

I went to that page, but can't find any source except for the program, namely FADEIN.EXE

Regards, Zif
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1360115
Woops, don't mention, it's a self-extracting file, sorry.
0
 

Author Comment

by:sz3905
ID: 1360116
Edited text of question
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Expert Comment

by:inter
ID: 1360117
Hi,

Working on it too. How is yours going on Zif?

Igor
0
 
LVL 5

Expert Comment

by:inter
ID: 1360118
Hi,

Working on it too. How it yours going on Zif?

Igor
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1360119
Hi inter,

Haven't done anything yet. My comment was of thursday evening. Then my server went down and now I haven't got time till this evening again. So, if yours is already done, please give it as an answer. But I'm going to try it out myself too. Maybe a new article is born here?

Regards, Zif.
0
 
LVL 5

Expert Comment

by:inter
ID: 1360120
I have translated the half of the code already. However there is a sort routine common to c++ named qsort(I should implement such thing in Delphi-or just cut and paste). Other than that, I think this question also helps us to answer the questions like How do I convert from 24 bit to 8 bit(as you can remember).

Regards,
Igor
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1360121
hi Inter,
Correct, the Quick Sort routine isn't standard implemented in Delphi. But that shouldn't be so hard.
Good luck.
0
 
LVL 5

Expert Comment

by:inter
ID: 1360122
Hi friends,

Now we have a translated source, BUT, just mangling the colors in the desktop!

Any comment?(I am trying to fix it)

Igor
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1360123
? Don't you've to assign a handler for changing the DIBbits? Now you probable take the handle of the desktop.
0
 
LVL 5

Expert Comment

by:inter
ID: 1360124
Ok THATS IT!

Do I paste the code here or send it?(Or who wants the source)

Igor
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1360125
You may send me the code, if you want.

But also answer this question!!

Regards, Zif.
0
 
LVL 5

Accepted Solution

by:
inter earned 300 total points
ID: 1360126
Thanks all, I am sending it!(Just the PAS, DFM and RES files-create a new project, add fadeform.pas as mainform and run)

Regards,
Igor
0
 
LVL 5

Expert Comment

by:inter
ID: 1360127
My mailer still could not send the files. If you want I can paste it here. The raw code takes about 700 lines. But I may reduce it if I remove the comments from microsoft. What do you want. Also, are you there sz3905?

Igor
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1360128
Inter, I received your mail 2 times. Many thanks already.
0
 

Author Comment

by:sz3905
ID: 1360129
Igor and Zif,

Yes i'm here.
I am truly impressed.
I just unzipped and am trying Igor's version(very good!)  while it while we speak. . .
I'm not sure why I'm getting a incompatible types  integer and pointer  error in:

TheBitmap := CreateDIBSection(TheDC, pbmi^, DIB_RGB_COLORS, Pointer(pBits), nil, 0);

I shoudl know in a few minutes.

"What do you want."
I can wait for another email zip or raw email. What ever is convient for you guys.
Again, truly impressed
/steve      
0
 
LVL 5

Expert Comment

by:inter
ID: 1360130
I am glad you receive it(by the way reject the answer if Zif also sends you the code, I want to share the points with him after the fix)

My delphi version is 2.0. So lets find the problem. First of all Do you have the source code for Delphi 3.0 components?(i.e. you have Client/Server or professional edition.) If so just open Windows.Pas from ..\source\rtl\win\ directory and search for CreateDIBSection( function. Comment it down here and we try to examine the incompatibility. My Windows.pas reports the following prototype:

function CreateDIBSection(DC: HDC; const p2: TBitmapInfo; p3: UINT;
  var p4: Pointer; p5: PHandle; p6: DWORD): HBITMAP; stdcall;

Is it same?
(Also try add adding {$X+} after interface part please)
Igor


0
 
LVL 5

Expert Comment

by:inter
ID: 1360131
Hi there,

If you do not have the sources of VCL please indicate. By the way if you there Zif and have Delphi 3.0 please help (I wonder if I configure my compiler to prevent such errors from compiler options?)

Igor
0
 
LVL 5

Expert Comment

by:inter
ID: 1360132
I think I have found. They probably fixed this in Delphi 3.0. so reports incompatible with 2.0. Please try the following variant of the code

CreateDIBSection(TheDC, pbmi^, DIB_RGB_COLORS, Pointer(pBits), 0, 0);

And please notify
Igor


0
 

Author Comment

by:sz3905
ID: 1360133
Will try
CreateDIBSection(TheDC, pbmi^, DIB_RGB_COLORS, Pointer(pBits), 0, 0);
asap and let you know
/Steve/sz3905
0
 

Author Comment

by:sz3905
ID: 1360134
removing "nil" helped
but . . .
 
 AnimatePalette(hPal, 0, 256, @pe);

gives error imcompatible type "array" and "TPaletteEntry"

probably diff betweem D2 and D3 array pointers ?
/steve
 
0
 
LVL 5

Expert Comment

by:inter
ID: 1360135
try
 AnimatePalette(hPal, 0, 256, pe);
or
 AnimatePalette(hPal, 0, 256, PPaletteEntry(@pe)^);

Igor
0
 
LVL 5

Expert Comment

by:inter
ID: 1360136
I should leave in a minute if you have a comment please present.

Igor
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1360137
Sorry, was a way for a moment. Haven't D3, have D2. What's the problem at the moment?
0
 
LVL 5

Expert Comment

by:inter
ID: 1360138
I am back also,

No problem Zif, some of the API declarations of D2 and D3 varies like some pointers became Var etc. So, I am waiting to fix the things up from the errors reported to Steve by Delphi 3.0.

Igor(l.t. 8:49 p.m)

0
 

Author Comment

by:sz3905
ID: 1360139
I was away also, but we're back
Okay just tried but no can compile. I'll spend more time using watches:

 AnimatePalette(hPal, 0, 256, pe);=
gives error imcompatible type "array" and "PPaletteEntry"

AnimatePalette(hPal, 0, 256, PPaletteEntry(@pe)^); =
gives error imcompatible type "TPaletteEntry" and "PPaletteEntry" Note:this is where I had problems with my version

AnimatePalette(hPal, 0, 256, @pe);=
gives error imcompatible type "array" and "TPaletteEntry"
 
/steve/sz3905
0
 
LVL 5

Expert Comment

by:inter
ID: 1360140
Then just this

AnimatePalette(hPal, 0, 256, PPaletteEntry(@pe));

Ok?
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1360141
Well, if you need some help (which I doubt), i'm still here (l.t. 20.00h)
0
 
LVL 5

Expert Comment

by:inter
ID: 1360142
Dear friend,

Please watch you mailbox so we clear the case tonight if you have time for it by now, or just respond to be off and we will deal it tomorow.
(If we do, would you please report all the API related errors in one or two comments so that we can fix it instant)

Regards,
Igor the watchdog timer(Just for fun friend)
0
 

Author Comment

by:sz3905
ID: 1360143
Igor, Date: 11:09AM - March, 06, 1998 PST
I do not understand your last message? Please explain.
The source compiled but does not work.
/Steve

0
 
LVL 5

Expert Comment

by:inter
ID: 1360144

Ok friend, forget about the last message, i just said "If you have time lets fix this thing"

Questions:

1 - Does your windows setup to 256 color?
2 - Can you see a bitmap when you press the button on the form?
3 - Can you see any color change in the desktop when you press the button?
4 - Does delphi display hints and if so what are they?

Sincerely,
Igor
0
 

Author Comment

by:sz3905
ID: 1360145
Igor,
It kinda works now.
1) It does now
2)Yes
3)Yes black to color with artifacts (desktop (everywhere)
4) No hints or warnings
/steve

0
 
LVL 5

Expert Comment

by:inter
ID: 1360146
Fine,

Since the palette animation uses DAC(a chip on video cards-or we used to do it with DAC) it may happen that the very high frequency pulses disturb your display. To prevent this, run your application full screen or if not, do this kind of animation with DirectX.

Do you have such a problem friend?
Igor
0
 
LVL 5

Expert Comment

by:inter
ID: 1360147
Dear friend,

(If you don't mind) what are you planning to do with these kind of animation?
Igor
0
 

Author Comment

by:sz3905
ID: 1360148
11:40AM - March, 06, 1998 PST
Igor,
No problem. U'm, I'm using a brand new HP Vectra.
Are you saying there is no way for a clean fade using
stock hardware and standard winapi calls?
If so, Is it that DirectX handles hardware differently?
You see, I'm from the old school and  dont want
DirectX, ActiveX, ControlX, AlphaX, BetaX, or any other X driver
set of the week. I've always written driver-less software
Using only the existing OS. I write video software.

You did convert the code, thank You both!
So how do I split points between you and Zif?
/steve

0
 
LVL 5

Expert Comment

by:inter
ID: 1360149
I am too friend,(from the old school, but just learn them for knowledge)

I just say few thing about video. You may probably know these, any way you may skip, sorry I just want to writedown.

The flickerless animation just use up 3 inline assembler lines in DOS days. As you may already know, the CRT traces every line and whole screen from left to right and top to bottom. The scan from left to right is called HScan(Horizontal) and from top to bottom called VScan. A 50Hz monitor scans whole the screen in every 20msecs. This setup time, between individual page scans is called Vertical Blank Period or shortly VBL. We may poll a grahic card register if it is in VBL. If we update the whole screen in that period there can be absolutely no flicker. So a simple function such as WaitVbl can prevent screen from flickering. Windows NT does not allow this(as you now is is !SECURE!) But win95 may? I can not remember the port number and mask but if you want find them. If it works on win95, your animations may works flicker free regardless of the complexity of your scene.

Thanks, have a nice day(we have a nice night here too)
and Regards
Igor
0
 

Author Comment

by:sz3905
ID: 1360150
It's a nice welcome to hear same beliefs as I have. W95 is very forgiving and implemeting
a write on vertical retrace is a snap while in Nt4.0 it is forbidden. I'll work with your solution. I can still use the code with slight mods. I'm going to try to split or give points by asking another fake question for Zif (reopen) after I close this question.
Again, I am impressed.
Best Regard,
Steve Sullivan

 

 
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

734 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