In order to get color in MPEGs you must use a 24 bit truecolor image.
This can be done as follows (using a function from Dave Fanning).
First, code that only produces black and white MPEG ......
pro xanim
openr,unit,filepath('abnorm.dat',subdir=['examples','data']) ,/get_lun
h=bytarr(64,64,16)
readu,unit,h
close,unit
free_lun,unit
h=rebin(h,128,128,16)
window,0,xsize=128,ysize=128
loadct,3
mpegID=mpeg_open([128,128])
for i=0,15 do begin
tvscl,h[*,*,i]
mpeg_put,mpegID,frame=i,image=h[*,*,i]
endfor
mpeg_save,mpegID,filename='xanim.mpg'
mpeg_close,mpegID
end
Now fixed code ....
function pseudo8_to_true24, image8
; This function is from Dave Fanning
s = SIZE(image8)
width = s(1)
height = s(2)
TVLCT, red, green, blue, /GET
image24 = BYTARR(3,width, height)
image24(0,*,*) = red(image8(*,*))
image24(1,*,*) = green(image8(*,*))
image24(2,*,*) = blue(image8(*,*))
RETURN, image24
end
pro xanim4
openr,unit,filepath('abnorm.dat',subdir=['examples','data']) ,/get_lun
h=bytarr(64,64,16)
readu,unit,h
close,unit
free_lun,unit
h=rebin(h,128,128,16)
window,0,xsize=128,ysize=128
loadct,3
mpegID=mpeg_open([128,128])
for i=0,15 do begin
image8=h[*,*,i]
tvscl,image8
image24=pseudo8_to_true24(image8)
; 8-bit image converted to 24-bit image
mpeg_put,mpegID,frame=i,image=image24,order=1
endfor
mpeg_save,mpegID,filename='Quark:Documents:xanim4.mpg'
mpeg_close,mpegID
end
Works great.
Thanks to everyone for suggestions and ideas and thanks to Dave
Fanning for a really great WEB site.
John Boccio
boccio@swarthmore.edu
|