|
Folgendes ist ein Antwort auf eine Anfrage von Martin Weiß: >From: Martin Weiß <albus@XXXXXXX.com> >To: "'dmug@XXXXXXX.ch'" <dmug@XXXXXXX.ch> >Subject: Bilder >Date: Sat, 20 Dec 1997 13:19:10 +0100 >Sender: owner-dmug@XXXXXXX.ch > >Hallo! >Ich muß für die Anwendung von verschiedenen Bildkompressionsverfahren Bilder in >Mathematica laden. > >Ist es möglich , BMP- oder JPEG- Bilder direkt einzulesen, oder ist euch >irgendein Programm bekannt, daß die Bilder in "verdauliche Daten" umzuwandeln? > >Danke, > >Martin Weiß. > Es war zu finden auf "MathGroup" (mathgroup@XXXXXXX.net oder news:comp.soft-sys.math.mathematica/8868-8968 ) Anfang der Meldung : ******************************************************* Date: Sun, 28 Dec 1997 02:23:09 -0500 From: "Barthelet, Luc" <lucb@XXXXXXX.com> To: mathgroup@XXXXXXX.net Subject: [mg10232] Code to read BMP This reads and display BMPs in Mathematica 3.0 it only reads 8 bits and 24 bits BMPs and uncompressed. I welcome anyone to write a more detailed package supporting all BMP formats. typical usage is: ShowBMP[ReadBMPfile["filename"],1] ReadBMPfile[filename_]:=Module[ {afile,data,validFile,width,height,planes,bitPerPixel,compression, sizeOfBitmap,horzRes,vertRes,numOfColors,colorsImportant,bitmap, firstImageByte,palette}, toDWORD[l_]:= Apply[Plus,l {1,256, 65536, 16777216}]; toWORD[l_]:= Apply[Plus,l {1,256}]; afile = OpenRead[filename,DOSTextFormat->False]; data = ReadList[afile,Byte]; Close[afile]; bitPerPixel = toWORD[data[[{29,30}]] ]; firstImageByte = toDWORD[ data[[ {11,12,13,14} ]] ]; numOfColors = toDWORD[ data[[ {47,48,49,50} ]] ]; compression = toDWORD[ data[[ {31,32,33,34} ]] ]; validFile = (compression==0)&& (data[[{1,2}]] == {66,77}) && (data[[ {7,8,9,10}]] == {0,0,0,0})&& ( toDWORD[ data[[ {3,4,5,6}]]] == Length[data] ) && (firstImageByte == 54 + 4 numOfColors)&& ((bitPerPixel==24)|| (bitPerPixel==8)); If[validFile , width = toDWORD[ data[[ {19,20,21,22} ]] ]; height = toDWORD[ data[[ {23,24,25,26} ]] ]; (* don't need any of those values planes = toWORD[data[[{27,28}]] ]; sizeOfBitmap = toDWORD[ data[[ {35,36,37,38} ]] ]; horzRes = toDWORD[ data[[ {39,40,41,42} ]] ]; vertRes = toDWORD[ data[[ {43,44,45,46} ]] ]; colorsImportant = toDWORD[ data[[ {51,52,53,54} ]] ]; *) If[(bitPerPixel==24), (* 24 bit stuff *) bitmap = Take[data,{firstImageByte+1,firstImageByte+width height 3}]; bitmap = Map[Reverse,Partition[Partition[bitmap,3],width],{2}]; {bitmap,{}}, (* 8 bit stuff *) palette = Rest /@ (Reverse /@ Partition[Take[data,{55,54+4 numOfColors}],4]); bitmap = Partition[ Take[data,{firstImageByte+1,firstImageByte+width height }], width]; (* return the bitmap and the palette *) {bitmap,palette} ], Print["wrong format for BMP file, write more code..."]; ] ](*Module *); ShowBMP[{bitmap_,palette_},scale_]:=Module[ {width,height,copyPalette}, If[Length[bitmap]>0, {height,width} = Dimensions[bitmap][[{1,2}]]; Show[Graphics[ If[palette=={}, (* for 24 bit images *) RasterArray[ Map[Apply[RGBColor,# ]&, bitmap/255.,{2}]], (* for 8 bit images *) copyPalette=Map[Apply[RGBColor,# ]&, palette/255.,{1}]; RasterArray[Map[copyPalette[[#+1]]&,bitmap,{2}] ] ] ],ImageSize->{scale*width+9,scale*height+9}, AspectRatio->(scale*height+9)/(scale*width+9)]; ]; ](*Module *); ------------------------------------------------------------- Luc Barthelet General Manager Maxis ******************************************** Ende der Meldung. Ich habe es getestet, und es lief problemlos und schnell. Es zeigt auch ganz net wie solche BMP bilder zusammengestelt sind. Empfelenswert! wouter. Dr. Wouter L. J. MEEUSSEN w.meeussen.vdmcc@XXXXXXX.be eu000949@XXXXXXX.be |