1. mem_copy / foul-or-fu

Hello folks,

I have run into something that is strange dealing with a mem_copy.

Below is a snippet of code that should explain, It may be something
I overlooked. I have a work around to this problem but, I wanted to 
get some kind of idea why this doesnt work.....

some of this code will look familiar because it is (inplaces) the same as
CreateDIB from Win32lib. 

BTW, I do have multiple images that have identical palettes.

    -- get the address of the first rgb tuple    
    at = address( memBitmapInfo, 40 )
    
    if  pal_exist = 0 then -- have we been here before?

    -- copy the pal to memory    
    for i = 1 to palSize do

        -- store values
        poke( at + 2, pal[i][1] )
        poke( at + 1, pal[i][2] )
        poke( at + 0, pal[i][3] )
        poke( at + 3, 0 )
       
        -- move to next quad
        at = at + 4

    end for
        
    -- copy logical palette to this image
    pokew(ple + 0, #300) -- poke word
    pokew(ple + 2, 256)   -- poke word

    palinfo = allocate_struct(1024)

    poke4(ple + 4, palinfo)

    mem_copy(palinfo, at - 1024, 1024) -- this one worked

    newpal = c_func(xCreatePalette,{ple}) 

    junk = c_func(xSelectPalette,{hdc, newpal, 0})
    junk = c_func(xRealizePalette,{hdc}) 

    free(palinfo)
    
    pal_exist = 1
           
    else

-- This doesnt copy the bits as they appear to be, starting at 
-- address ple+4 because, from the second image the palette
-- is not the same as if I were to poke the individual bits
-- as above.

    mem_copy(at, ple + 4, 1024) 

    end if

Ok, Ok, I took the CreatePalette, SelectPalette and RealizePalette out
and guess what, the problem still existed.'

hmmmm!

So, I tried a flush of the 1024 bits to a file and guess what, the bits are'nt
the same......

Either something is wrong with mem_copy or I just overlooked something.

Any Suggestions>?

Euman
euman at bellsouth.net

new topic     » topic index » view message » categorize

2. Re: mem_copy / foul-or-fu

>
>     mem_copy(at, ple + 4, 1024)
>

Perhaps you should do:

  mem_copy(at, peek4u(ple+4), 1024)

instead ?

new topic     » goto parent     » topic index » view message » categorize

3. Re: mem_copy / foul-or-fu

Thanks Mic,

The address for ple is open at this point in the code.
Sorry, I should've included this. 

I did however find the problem, 
I was free'ing palinfo and because it's tied to 
a structure as reference to an array of structures, 
free'ing this canceled the struct data for ple + 4.

Thanks again,

Euman
euman at bellsouth.net

> Stabmaster Mic wrote>

> >     mem_copy(at, ple + 4, 1024)
> >
> 
> Perhaps you should do:
> 
>   mem_copy(at, peek4u(ple+4), 1024)
> 
> instead ?

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu