985 aStream binary. |
985 aStream binary. |
986 |
986 |
987 "read the header" |
987 "read the header" |
988 |
988 |
989 header := ByteArray uninitializedNew:(6 + 16 + 40). |
989 header := ByteArray uninitializedNew:(6 + 16 + 40). |
990 bytesAlreadyRead size > 0 ifTrue:[ |
990 bytesAlreadyRead notEmptyOrNil ifTrue:[ |
991 header replaceFrom:1 with:bytesAlreadyRead |
991 header replaceFrom:1 with:bytesAlreadyRead |
992 ]. |
992 ]. |
993 aStream nextBytes:((6 + 16 + 40)-bytesAlreadyRead size) into:header startingAt:(1+bytesAlreadyRead size). |
993 aStream nextBytes:((6 + 16 + 40)-bytesAlreadyRead size) into:header startingAt:(1+bytesAlreadyRead size). |
994 |
994 |
995 width := header at:(6+1). |
995 width := header at:(6+1). |
996 height := header at:(7+1). |
996 height := header at:(7+1). |
1004 "23, ... , 62 ?" |
1004 "23, ... , 62 ?" |
1005 |
1005 |
1006 inDepth := header at:16r25. |
1006 inDepth := header at:16r25. |
1007 "/ mhmh - some depth4 icons seem to have a 0 in the depth field ... |
1007 "/ mhmh - some depth4 icons seem to have a 0 in the depth field ... |
1008 inDepth == 0 ifTrue:[ |
1008 inDepth == 0 ifTrue:[ |
1009 inDepth := 4 |
1009 inDepth := 4 |
1010 ]. |
1010 ]. |
1011 (#(4 8) includes:inDepth) ifFalse:[ |
1011 (#(4 8 32) includes:inDepth) ifFalse:[ |
1012 "/ only tested for depth 4/8 images. |
1012 "/ only tested for depth 4/8 images. |
1013 ^ self fileFormatError:'only depth 4/8 ico-images supported (depth is ' , inDepth printString , ')'. |
1013 ^ self fileFormatError:'only depth 4/8/32 ico-images supported (depth is ' , inDepth printString , ')'. |
1014 "/ self halt:'only depth 4 ico-images supported (depth is ' , inDepth printString , ')'. |
1014 "/ self halt:'only depth 4 ico-images supported (depth is ' , inDepth printString , ')'. |
1015 ]. |
1015 ]. |
1016 self reportDimension. |
1016 self reportDimension. |
1017 |
1017 |
1018 "read the colormap" |
1018 nColor > 0 ifTrue:[ |
1019 cmapSize := (1 bitShift:inDepth). |
1019 "read the colormap" |
1020 |
1020 cmapSize := (1 bitShift:inDepth). |
1021 colorMap := self |
1021 |
1022 readColorMap:cmapSize |
1022 colorMap := self readColorMap:cmapSize numBytesPerColor:4 from:aStream. |
1023 numBytesPerColor:4 |
1023 ]. |
1024 from:aStream. |
|
1025 |
1024 |
1026 "read the data bits" |
1025 "read the data bits" |
1027 |
1026 |
1028 bytesPerRow := ((width * inDepth) + 7) // 8. |
1027 bytesPerRow := ((width * inDepth) + 7) // 8. |
1029 rawData := ByteArray uninitializedNew:(height * bytesPerRow). |
1028 rawData := ByteArray uninitializedNew:(height * bytesPerRow). |
1040 |
1039 |
1041 tmp := ByteArray uninitializedNew:(height * bytesPerRow). |
1040 tmp := ByteArray uninitializedNew:(height * bytesPerRow). |
1042 srcIndex := 1. |
1041 srcIndex := 1. |
1043 dstIndex := (height - 1) * bytesPerRow + 1. |
1042 dstIndex := (height - 1) * bytesPerRow + 1. |
1044 1 to:height do:[:row | |
1043 1 to:height do:[:row | |
1045 tmp replaceFrom:dstIndex to:(dstIndex + bytesPerRow - 1) |
1044 tmp replaceFrom:dstIndex to:(dstIndex + bytesPerRow - 1) |
1046 with:rawData startingAt:srcIndex. |
1045 with:rawData startingAt:srcIndex. |
1047 srcIndex := srcIndex + bytesPerRow. |
1046 srcIndex := srcIndex + bytesPerRow. |
1048 dstIndex := dstIndex - bytesPerRow. |
1047 dstIndex := dstIndex - bytesPerRow. |
1049 ]. |
1048 ]. |
1050 rawData := tmp. |
1049 rawData := tmp. |
1051 |
1050 |
1052 photometric := #palette. |
1051 nColor > 0 ifTrue:[ |
1053 samplesPerPixel := 1. |
1052 photometric := #palette. |
1054 |
1053 samplesPerPixel := 1. |
1055 false ifTrue:[ |
1054 bitsPerSample := (Array with:inDepth). |
1056 "expand into bytes" |
|
1057 |
|
1058 data := ByteArray new:(width * height). |
|
1059 rawData expandPixels:inDepth width:width height:height |
|
1060 into:data mapping:nil. |
|
1061 bitsPerSample := #(8). |
|
1062 ] ifFalse:[ |
1055 ] ifFalse:[ |
1063 data := rawData. |
1056 inDepth == 32 ifTrue:[ |
1064 bitsPerSample := (Array with:inDepth). |
1057 photometric := #rgba. |
1065 ]. |
1058 samplesPerPixel := 4. |
|
1059 bitsPerSample := #(8 8 8 8). |
|
1060 ] ifFalse:[ |
|
1061 ^ self fileFormatError:'unsupported image depth: ' , inDepth printString. |
|
1062 ] |
|
1063 ]. |
|
1064 |
|
1065 data := rawData. |
1066 ^ self image |
1066 ^ self image |
1067 |
1067 |
1068 " |
1068 " |
1069 WindowsIconReader new fromWindowsICOFile:'/phys/clam2//LocalLibrary/Images/WIN_icons/ibm.ico'. |
1069 WindowsIconReader new fromWindowsICOFile:'/phys/clam2//LocalLibrary/Images/WIN_icons/ibm.ico'. |
1070 " |
1070 " |
1316 ! ! |
1316 ! ! |
1317 |
1317 |
1318 !WindowsIconReader class methodsFor:'documentation'! |
1318 !WindowsIconReader class methodsFor:'documentation'! |
1319 |
1319 |
1320 version |
1320 version |
1321 ^ '$Header: /cvs/stx/stx/libview2/WindowsIconReader.st,v 1.67 2013-08-10 11:25:55 stefan Exp $' |
1321 ^ '$Header: /cvs/stx/stx/libview2/WindowsIconReader.st,v 1.68 2014-11-26 12:45:44 cg Exp $' |
1322 ! |
1322 ! |
1323 |
1323 |
1324 version_CVS |
1324 version_CVS |
1325 ^ '$Header: /cvs/stx/stx/libview2/WindowsIconReader.st,v 1.67 2013-08-10 11:25:55 stefan Exp $' |
1325 ^ '$Header: /cvs/stx/stx/libview2/WindowsIconReader.st,v 1.68 2014-11-26 12:45:44 cg Exp $' |
1326 ! ! |
1326 ! ! |
1327 |
1327 |
1328 |
1328 |
1329 WindowsIconReader initialize! |
1329 WindowsIconReader initialize! |