Page 1 of 1
extracting mpo-files
Posted: Sun Oct 12, 2014 10:45 am
by high key
high key wrote:mpo is an extended version of JPG to save multiple images in one file, for example for 3D Fotos
Would it be possible to extend the UseJPEGImageDecoder() for loading these additional images with
loadimage(1,mpofile$,#picindex)
?
I posted this as a feature request some time ago.
But it would be sufficient for me, if I knew how to get the index list (start addresses and bytelength of each image) in the mpo file.
Re: extracting mpo-files
Posted: Sun Oct 12, 2014 2:46 pm
by Crusiatus Black
Re: extracting mpo-files
Posted: Sun Oct 12, 2014 6:16 pm
by netmaestro
Here's something to play with, it extracts images from a .mpo file. The first time you run it it will be slow because it has to download a 10m image. Subsequent runs will use the previously downloaded file. This code is extracting six images from the test mpo file.
Code: Select all
UseJPEGImageDecoder()
InitNetwork()
file$ = "DSCF0036.MPO"
If FileSize(GetTemporaryDirectory()+file$) = -1
ReceiveHTTPFile("http://lloydsplace.com/"+file$, GetTemporaryDirectory()+file$)
EndIf
If FileSize(GetTemporaryDirectory()+file$) = 10039442
ReadFile(0, GetTemporaryDirectory()+file$)
length=Lof(0)
*pic = AllocateMemory(length)
ReadData(0, *pic, length)
CloseFile(0)
*pos=*pic
*end=*pic+length-3
nextimage=0
While *pos < *end
If CompareMemory(*pos, ?test, 3)
If CatchImage(nextimage, *pos)
Debug "loaded image "+Str(nextimage)
nextimage+1
EndIf
EndIf
*pos+1
Wend
ShowLibraryViewer("image", 0)
CallDebugger
Else
Debug "couldn't download the file"
EndIf
DataSection
test:
Data.a $ff,$d8,$ff
EndDataSection
Re: extracting mpo-files
Posted: Sun Oct 12, 2014 6:27 pm
by Thade
I used this Blitz3D Code years ago to split MPO Files made with my Fuji W3 in a Blitz3D Anaglyph program
Not professional, but it worked ...
Code: Select all
;- SplitMPO
.SplitMPO
If FileType(File.s)=1
FLen=FileSize(File.s)
Bank=CreateBank(FLen)
fi=ReadFile(File.s)
If fi
Exif=Asc("f")*256*256*256 + Asc("i")*256*256 + Asc("x")*256 + Asc("E")
ReadBytes(Bank, fi, 0, FLen)
CloseFile(fi)
Test=PeekInt(Bank,0)
Gef=0
For i=Flen/2-Flen/5 To Flen
If PeekInt(Bank, i) = Test
If PeekInt(Bank, i+6) =Exif
PicL.s=GetFilenamePart(File, False)+"_l.jpg"
fo=WriteFile(PicL.s)
WriteBytes(Bank, fo, 0, i)
CloseFile(fo)
PicR.s=GetFilenamePart(File, False)+"_r.jpg"
fo=WriteFile(PicR.s)
WriteBytes(Bank, fo, i, FLen-i)
CloseFile(fo)
MerkI=i
Exit ;Break in PB
EndIf
EndIf
Next
EndIf
FreeBank(Bank)
EndIf
Return;
;!
Re: extracting mpo-files
Posted: Sun Oct 12, 2014 8:29 pm
by high key
Thade wrote:I used this Blitz3D Code years ago to split MPO Files made with my Fuji W3 in a Blitz3D Anaglyph program
Not professional, but it worked ...
Thade, I love this approach! Just searching for the "Exif"s should do the job.
I think, that's all I need

Re: extracting mpo-files
Posted: Sun Oct 12, 2014 8:43 pm
by Thade
Actually it searches for the first 4 bytes of each of the 2 main jpgs inside and then makes shure that its the beginning of the second file (and not random code inside the picture) by checking if the Exif follows at byte 6 after start as in every MPO File the Fuji shoots.

Re: extracting mpo-files
Posted: Mon Oct 13, 2014 9:37 am
by high key
Now here's my code
Code: Select all
pic$="E:\test.mpo"
fsize=FileSize(pic$)
If fsize<100
error$="no picfile"
Goto errortrap
EndIf
*mpostart=AllocateMemory(fsize)
If *mpostart=0
error$="couldn't allocate memory"
Goto errortrap
EndIf
ok=ReadFile(1,pic$)
If ok=0
error$="couldn't read picdata"
Goto errortrap
EndIf
ReadData(1,*mpostart,fsize)
CloseFile(1)
phalf=*mpostart+fsize/2 ; we expect an Exif somewhere in the mid of the mpo file
splitpoint=0
testtime=GetTickCount_()
For i=0 To fsize/4 ; searching from the midst forwards and backwards
If PeekB(phalf+i)=$45 ;"E"
adr=phalf+i
If PeekS(adr,4,#PB_Ascii )="Exif"
If PeekS(adr-6,4,#PB_Ascii )= "ÿØÿá"
splitpoint=adr-6
Break
EndIf
EndIf
EndIf
If PeekB(phalf-i)=$45;"E"
adr=phalf-i
If PeekS(adr,4,#PB_Ascii )="Exif"
If PeekS(adr-6,4,#PB_Ascii )="ÿØÿá"
splitpoint=adr-6
Break
EndIf
EndIf
EndIf
Next i
Debug "*mpostart="+Str(*mpostart)+" fsize="+Str(fsize)+" phalf="+Str(phalf)+" splitpoint="+Str(splitpoint)
Debug "Searchtime for Exif was "+Str(GetTickCount_()-testtime)+" millisecs"
If splitpoint=0
error$="splitpoint not found"
Goto errortrap
EndIf
size1=splitpoint-*mpostart+1
size2=*mpostart+fsize-splitpoint
ext$=GetExtensionPart(pic$)
L=Len(pic$)-Len(ext$)-1
outfileL$=Left(pic$,L)+"_L.jpg"
outfileR$=Left(pic$,L)+"_R.jpg"
Debug "outfileL$="+outfileL$+" outfileR$="+outfileR$
saved=0
If CreateFile(1,outfileL$)
WriteData(1,*mpostart,size1) ; first image is LEFT? I'm not sure
CloseFile(1)
saved+1
EndIf
If CreateFile(1,outfileR$)
WriteData(1,splitpoint,size2) ; second image is RIGHT?
CloseFile(1)
saved+1
EndIf
Debug Str(saved)+" pic(s) saved"
progend:
;-------
End
errortrap:
;---------
Debug error$
End
Re: extracting mpo-files
Posted: Mon Jan 27, 2025 9:20 pm
by mpz
Hi,
i know it is an old topic, but i have the "Fujifilm FinePix Real 3D W1" kamera with the "mpo" 3d files.
Now i am printing the following 3d Stereoskop <
https://www.thingiverse.com/thing:5446241> (with Bambulabs) and need the pictures for printing as jpg.
Here comes the actualized program for PB 6.20, grettings
Code: Select all
UseJPEGImageDecoder()
UseJPEGImageEncoder()
file$ = "mpotest.mpo"
If FileSize(file$)
ReadFile(0, file$)
length=Lof(0)
*pic = AllocateMemory(length)
ReadData(0, *pic, length)
CloseFile(0)
*pos=*pic
*end=*pic+length-3
nextimage=0
While *pos < *end
If CompareMemory(*pos, ?test, 4)
If CatchImage(nextimage, *pos-6)
Debug "loaded image "+Str(nextimage)
nextimage+1
EndIf
EndIf
*pos+1
Wend
CreateImage(2, ImageWidth(0)*2, ImageHeight(0))
StartDrawing(ImageOutput(2))
DrawImage(ImageID(0), 0, 0 )
DrawImage(ImageID(1), ImageWidth(0), 0 )
StopDrawing()
SaveImage(2, "mpotest.jpg", #PB_ImagePlugin_JPEG )
ShowLibraryViewer("image", 0)
CallDebugger
Else
Debug "couldn't download the file"
EndIf
DataSection
test:
Data.a $45,$78,$69,$66
EndDataSection