Sign in to follow this  

2D Engin with little problim

This topic is 4339 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I,m on my way to make an engin(2d) in DX7 by VB6 (so old,eh..) After i made gif class , i could not apply colorkey modifier , the black color still exist . please , get me a solution ASAP

Share this post


Link to post
Share on other sites
You're going to have to give people some more information if you want a reasonable response. Also, just saying "get me a solution" doesn't come across as the most friendly way of asking for help.

Anyway, I presume you've been decoding a GIF format file into a DirectDrawSurface7? It's worth baring in mind that a GIF file uses lossy compression - thus the colours may not be exactly the same as the ones you think you stored. Analyzing the contents of your surface should reveal if this is (or isn't the case).

hth
Jack

Share this post


Link to post
Share on other sites
First of all ,i want to thank you jollyjeffers , but there,s some thing , about friendly asking for help ,sory about this expression because i,m non-native speaker .
Second, yes , you gotit , this is the case that i talked about .

Share this post


Link to post
Share on other sites
I'm afraid I have too little information to help you. But I can tell you that GIF uses a loss-less compression algorithm, and is not lossy. Dunno if that helps you though... :)

Share this post


Link to post
Share on other sites
ok, apologies for that.

Anyway, some more details would be a good idea. If you can post (in [ source ] ...[ /source ] tags) the relevant pieces of code that might help us help you.

Have you verified that your surface contains the data that you expect. One way to check this is to lock the surface and then loop through every pixel and do an assert() or similar on your transparent colour.

The idea with that is if you get NO debug messages then it means that your transparent colour doesn't exist - which would explain your problem. You can then try and "back track" to work out what your transparent colour actually is (probably by checking your compression/decompression routines).

hth
Jack

Share this post


Link to post
Share on other sites
Quote:
Original post by skanatic
But I can tell you that GIF uses a loss-less compression algorithm, and is not lossy.

Unless I've been missing something really big, GIF is a lossy compression scheme. It does a K-Means/analysis and picks a palette of 256 (24bit) colours and encodes the image as that. Thus the image you load will have no more than 256 colours.

I suppose, if your original images used less than 256 colours you could get away without it being lossless - but thats unlikely [smile]

hth
Jack

Share this post


Link to post
Share on other sites
Quote:
Original post by jollyjeffers
Unless I've been missing something really big, GIF is a lossy compression scheme. It does a K-Means/analysis and picks a palette of 256 (24bit) colours and encodes the image as that. Thus the image you load will have no more than 256 colours.

I suppose, if your original images used less than 256 colours you could get away without it being lossless - but thats unlikely [smile]


That's not the definition of a loss less compression though. JPG on the other hand is lossy.

http://en.wikipedia.org/wiki/Lossless_data_compression

EDIT:
Saving a 24bit image in a GIF is just sad... :) PNG would be a better choice.

Share this post


Link to post
Share on other sites
To illuminate the misty , here is the problim :

Function StartLoad(filename As String, X As Integer, Y As Integer) As Boolean

SizeX = X
SizeY = Y

If TDN = "" Then MsgBox "1": Exit Function
If TFN = "" Then MsgBox "2": Exit Function
If FN = "" Then MsgBox "3": Exit Function


Dim Buffer$, Head$
Dim LastIn As Long, NextIn As Long
Dim Comma$
Dim CurPic As String, Lenth As Long
Dim fHead As String
Comma = Chr(0) & Chr(33) & Chr(249)
Open filename For Binary As #1
Lenth = LOF(1)
If Lenth < 128 Then
Close #1

Exit Function: MsgBox "5"


End If
Buffer = String$(Lenth, Chr(0))
Get #1, , Buffer
Close #1
LastIn = InStr(1, Buffer, Comma) + 1
If LastIn = 1 Then Exit Function
Head = Left(Buffer, LastIn)
LastIn = LastIn + 2
Dim F As Integer
F = -1
Do

F = F + 1
DoEvents
NextIn = InStr(LastIn, Buffer, Comma) + 3
If NextIn = 3 Then NextIn = Lenth
CurPic = Head & Mid(Buffer, LastIn - 1, NextIn - LastIn)
Open filename For Binary As #1
Put #1, 1, CurPic
Close #1
Set Pic(F) = LoadPicturefile(filename, X, Y)
Kill filename
fHead = Left(Mid(Buffer, LastIn - 1, NextIn - LastIn), 16)
fTime(F) = (Asc(Mid(fHead, 4, 1)) + Asc(Mid(fHead, 5, 1)) * 256&) * 10&
If NextIn = Lenth Then Exit Do
LastIn = NextIn

Loop

CurFrame = 0
If fTime(0) <> 0 Then

End If

NumFrames = F
StartLoad = True
End Function


EDIT: Using source tags makes it more readable...

Share this post


Link to post
Share on other sites
Quote:
Original post by skanatic
Quote:
Original post by jollyjeffers
Unless I've been missing something really big, GIF is a lossy compression scheme. It does a K-Means/analysis and picks a palette of 256 (24bit) colours and encodes the image as that. Thus the image you load will have no more than 256 colours.

I suppose, if your original images used less than 256 colours you could get away without it being lossless - but thats unlikely [smile]


That's not the definition of a loss less compression though. JPG on the other hand is lossy.

http://en.wikipedia.org/wiki/Lossless_data_compression

EDIT:
Saving a 24bit image in a GIF is just sad... :) PNG would be a better choice.

Ah, okay then - I see your point.

Although, pretty much every usage I've seen of GIF tends to mutilate "true colour" photos down to a 256-colour quantized representation. I'd personally term that as lossless as the compression algorithm discards (loses) data [smile]

In the context of this thread, it is possible that the compression doesn't store the transparent colour as the same colour code as expected. Which is why I brought up the possibility. Doing these sorts of operations after an image has been churned up in a compression algorithm is a good way of introducing errors unless you're very sure you know whats going on.

Jack

Share this post


Link to post
Share on other sites
High Volt, you should try and post the code that would actually help.

The code for function LoadPicturefile(filename, X, Y) for example. And the part where you are actually setting the colour key. And for good measure, the render loop as well. Otherwise you would be waiting till eternity for a solution to your problem!

OOT: I see that jj has taken over as the moderator for DirectX. I've been away at the openGL thread for the past few months you see (cries of "heretic!")... Anyway, congrats jack! Wonder what Muhammad is upto now...

Share this post


Link to post
Share on other sites
Quote:
Original post by Specchum
I see that jj has taken over as the moderator for DirectX. I've been away at the openGL thread for the past few months you see (cries of "heretic!")... Anyway, congrats jack! Wonder what Muhammad is upto now...

Thanks! Muhammad's still around - he's just enjoying his new found spare time [grin] I think he's working on various different samples as well (including the one stuck at the top of the forum).

Jack

Share this post


Link to post
Share on other sites
Ok Specchum, i thought it,s easy to expect , here it is :

this LoadPicturefile(filename, X, Y)

code :

Public Function LoadPicturefile(xFile As String, Optional xSize As Integer = 100, Optional ySize As Integer = 100) As DirectDrawSurface7
SizeX = xSize
SizeY = ySize
Dim KEY As DDCOLORKEY
Dim DDSD2 As DDSURFACEDESC2
DDSD2.lFlags = DDSD_CAPS Or DDSD_HEIGHT Or DDSD_WIDTH
DDSD2.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
DDSD2.lHeight = ySize
DDSD2.lWidth = xSize

Dim PICSURF As Picture
Set PICSURF = LoadPicture(xFile)
SavePicture PICSURF, App.Path & "\BitMap.bmp"


DDSD2.lFlags = DDSD_CAPS Or DDSD_HEIGHT Or DDSD_WIDTH
DDSD2.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
DDSD2.lHeight = ySize
DDSD2.lWidth = xSize
Set LoadPicturefile = D_DRAW.CreateSurfaceFromFile(App.Path & "\BitMap.bmp", DDSD2)
LoadPicturefile.SetColorKey DDCKEY_SRCBLT, KEY
KEY.high = 0
KEY.low = 0


Kill App.Path & "\BitMap.bmp"
Set PICSURF = Nothing


End Function



and this is the render sub :


code :
Public Sub render(Optional Interval As Integer = 0, Optional ColorKey As COLOR_KEY = WITHOUT_BLACK_COLOR)


If GetTickCount > LAST_CHEK + CLng(fTime(CurFrame)) Then
'If GetTickCount > LAST_CHEK + Interval Then
Let LAST_CHEK = GetTickCount

CurFrame = CurFrame + 1

If CurFrame > NumFrames Then CurFrame = 0

End If

Dim T As CONST_DDBLTFASTFLAGS
T = ColorKey


Call BACK_BUFFER.BltFast(Pos.X, Pos.Y, Pic(CurFrame), MakeRect(0, 0, SizeX, SizeY), T)
End Sub


any other line make me away of eternity waiting ? :)

EDIT: Source tags!

[Edited by - jollyjeffers on January 27, 2006 2:28:35 PM]

Share this post


Link to post
Share on other sites

This topic is 4339 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this