98 " |
98 " |
99 WindowsIconReader isValidImageFile:'/phys/clam2/LocalLibrary/Images/OS2_icons/dos.ico' |
99 WindowsIconReader isValidImageFile:'/phys/clam2/LocalLibrary/Images/OS2_icons/dos.ico' |
100 " |
100 " |
101 |
101 |
102 "Created: 17.9.1995 / 17:14:20 / claus" |
102 "Created: 17.9.1995 / 17:14:20 / claus" |
|
103 ! ! |
|
104 |
|
105 !WindowsIconReader methodsFor:'private'! |
|
106 |
|
107 loadBMPWidth:w height:h depth:d compression:c from:aStream into:data |
|
108 d == 8 ifTrue:[ |
|
109 (self class loadBMP8Width:w height:h compression:c from:aStream into:data) ifFalse:[ |
|
110 'BMP: read/decompression failed' errorPrintNL. |
|
111 ^ false |
|
112 ] |
|
113 ] ifFalse:[ |
|
114 d == 4 ifTrue:[ |
|
115 (self class loadBMP4to8Width:w height:h compression:c from:aStream into:data) ifFalse:[ |
|
116 'BMP: read/decompression failed' errorPrintNL. |
|
117 ^ false |
|
118 ] |
|
119 ] ifFalse:[ |
|
120 d == 2 ifTrue:[ |
|
121 (self class loadBMP2to8Width:w height:h from:aStream into:data) ifFalse:[ |
|
122 'BMP: read failed' errorPrintNL. |
|
123 ^ false |
|
124 ] |
|
125 ] ifFalse:[ |
|
126 d == 1 ifTrue:[ |
|
127 (self class loadBMP1to8Width:w height:h from:aStream into:data) ifFalse:[ |
|
128 'BMP: read failed' errorPrintNL. |
|
129 ^ false |
|
130 ] |
|
131 ] ifFalse:[ |
|
132 'BMP: unsupported depth:' errorPrint. d errorPrintNL. |
|
133 ^ false |
|
134 ] |
|
135 ] |
|
136 ] |
|
137 ]. |
|
138 ^ true |
|
139 |
|
140 "Created: 17.9.1995 / 18:48:11 / claus" |
103 ! ! |
141 ! ! |
104 |
142 |
105 !WindowsIconReader methodsFor:'reading from file'! |
143 !WindowsIconReader methodsFor:'reading from file'! |
106 |
144 |
107 fromOS2File: aFilename |
145 fromOS2File: aFilename |
225 |
263 |
226 fromWindowsBMPStream:aStream |
264 fromWindowsBMPStream:aStream |
227 | fileSize header inDepth inPlanes compression |
265 | fileSize header inDepth inPlanes compression |
228 imgSize resH resV numColor numImportantColor |
266 imgSize resH resV numColor numImportantColor |
229 dataStart |
267 dataStart |
230 rawMap rMap gMap bMap srcIndex dstIndex |
268 rawMap rMap gMap bMap srcIndex dstIndex inBytesPerRow |
231 data4 mask tmp bytesPerRow fourBytesPerColorInfo| |
269 data4 mask tmp bytesPerRow fourBytesPerColorInfo| |
232 |
270 |
233 inStream := aStream. |
271 inStream := aStream. |
234 aStream binary. |
272 aStream binary. |
235 |
273 |
351 "/ with:data4 startingAt:srcIndex. |
389 "/ with:data4 startingAt:srcIndex. |
352 "/ srcIndex := srcIndex + bytesPerRow. |
390 "/ srcIndex := srcIndex + bytesPerRow. |
353 "/ dstIndex := dstIndex - bytesPerRow. |
391 "/ dstIndex := dstIndex - bytesPerRow. |
354 "/ ]. |
392 "/ ]. |
355 "/ data4 := tmp. |
393 "/ data4 := tmp. |
|
394 "/ data := ByteArray new:(width * height). |
|
395 "/ data4 expandPixels:inDepth width:width height:height |
|
396 "/ into:data mapping:nil. |
|
397 "/ |
356 |
398 |
357 compression ~~ 0 ifTrue:[ |
399 compression ~~ 0 ifTrue:[ |
358 "/ some compression |
400 "/ some compression |
359 compression == 1 ifTrue:[ |
401 compression == 1 ifTrue:[ |
360 "/ RLE8 - must be depth-8 |
402 "/ RLE8 - must be depth-8 |
381 "/ bmp data is always 32bit aligned; if required, |
423 "/ bmp data is always 32bit aligned; if required, |
382 inBytesPerRow := ((bytesPerRow + 3) // 4) * 4. |
424 inBytesPerRow := ((bytesPerRow + 3) // 4) * 4. |
383 aStream position:(dataStart + 1). |
425 aStream position:(dataStart + 1). |
384 |
426 |
385 data := ByteArray uninitializedNew:(height * width "bytesPerRow"). |
427 data := ByteArray uninitializedNew:(height * width "bytesPerRow"). |
386 inDepth == 8 ifTrue:[ |
428 (self loadBMPWidth:width height:height depth:inDepth compression:compression from:aStream into:data) ifFalse:[ |
387 (self class loadBMP8Width:width height:height compression:compression from:aStream into:data) ifFalse:[ |
429 ^ nil |
388 'BMP: read/decompression failed' errorPrintNL. |
|
389 ^ nil |
|
390 ] |
|
391 ] ifFalse:[ |
|
392 inDepth == 4 ifTrue:[ |
|
393 (self class loadBMP4to8Width:width height:height compression:compression from:aStream into:data) ifFalse:[ |
|
394 'BMP: read/decompression failed' errorPrintNL. |
|
395 ^ nil |
|
396 ] |
|
397 ] ifFalse:[ |
|
398 inDepth == 1 ifTrue:[ |
|
399 (self class loadBMP1to8Width:width height:height from:aStream into:data) ifFalse:[ |
|
400 'BMP: read failed' errorPrintNL. |
|
401 ^ nil |
|
402 ] |
|
403 ] ifFalse:[ |
|
404 'BMP: unsupported depth:' errorPrint. inDepth errorPrintNL. |
|
405 ^ nil |
|
406 ] |
|
407 ] |
|
408 ]. |
430 ]. |
409 "expand into bytes" |
431 "expand into bytes" |
410 |
|
411 data := ByteArray new:(width * height). |
|
412 data4 expandPixels:inDepth width:width height:height |
|
413 into:data mapping:nil. |
|
414 |
432 |
415 photometric := #palette. |
433 photometric := #palette. |
416 samplesPerPixel := 1. |
434 samplesPerPixel := 1. |
417 bitsPerSample := #(8). |
435 bitsPerSample := #(8). |
418 colorMap := Colormap redVector:rMap greenVector:gMap blueVector:bMap. |
436 colorMap := Colormap redVector:rMap greenVector:gMap blueVector:bMap. |
|
437 |
|
438 "Modified: 17.9.1995 / 18:48:46 / claus" |
419 ! |
439 ! |
420 |
440 |
421 fromStream:aStream |
441 fromStream:aStream |
422 | fileSize header | |
442 | fileSize header | |
423 |
443 |
452 (header startsWith:#(80 84)) ifTrue:[ "PT" |
472 (header startsWith:#(80 84)) ifTrue:[ "PT" |
453 aStream position:1. |
473 aStream position:1. |
454 'WINREADER: OS/2 PT format' errorPrintNL. |
474 'WINREADER: OS/2 PT format' errorPrintNL. |
455 ^ self fromOS2Stream:aStream |
475 ^ self fromOS2Stream:aStream |
456 ]. |
476 ]. |
|
477 (header startsWith:#(16r53 16r5A)) ifTrue:[ "SZ" |
|
478 'WINREADER: SZ format not supported:' errorPrintNL. |
|
479 ^ nil. |
|
480 aStream position:1. |
|
481 'WINREADER: OS/2 PT format' errorPrintNL. |
|
482 ^ self fromOS2Stream:aStream |
|
483 ]. |
457 (header startsWith:#(0 0 1 0)) ifTrue:[ |
484 (header startsWith:#(0 0 1 0)) ifTrue:[ |
458 aStream position:1. |
485 aStream position:1. |
459 'WINREADER: Win3.x ICO format' errorPrintNL. |
486 'WINREADER: Win3.x ICO format' errorPrintNL. |
460 ^ self fromWindowsICOStream:aStream |
487 ^ self fromWindowsICOStream:aStream |
461 ]. |
488 ]. |
462 'WINREADER: format not supported' errorPrintNL. |
489 'WINREADER: format not supported:' errorPrint. |
|
490 ((header at:1) printStringRadix:16) errorPrint. |
|
491 ' ' errorPrint. |
|
492 ((header at:2) printStringRadix:16) errorPrintNL. |
463 ^ nil |
493 ^ nil |
464 |
494 |
465 " |
495 " |
466 Image fromFile:'/phys/clam//LocalLibrary/Images/OS2_icons/dos.ico' |
496 Image fromFile:'/phys/clam//LocalLibrary/Images/OS2_icons/dos.ico' |
467 " |
497 " |
|
498 |
|
499 "Modified: 17.9.1995 / 18:59:07 / claus" |
468 ! |
500 ! |
469 |
501 |
470 fromOS2Stream:aStream |
502 fromOS2Stream:aStream |
471 | header inDepth |
503 | header inDepth |
472 rawMap rMap gMap bMap srcIndex dstIndex |
504 rawMap rMap gMap bMap srcIndex dstIndex inBytesPerRow |
473 data4 mask tmp bytesPerRow nColors nByte| |
505 data4 mask tmp bytesPerRow nColors nByte| |
474 |
506 |
475 inStream := aStream. |
507 inStream := aStream. |
476 aStream binary. |
508 aStream binary. |
477 |
509 |
520 |
552 |
521 "what is this" |
553 "what is this" |
522 |
554 |
523 aStream nextBytes:nByte into:mask. |
555 aStream nextBytes:nByte into:mask. |
524 |
556 |
525 "read the data bits" |
557 "/ "read the data bits" |
|
558 "/ |
|
559 "/ bytesPerRow := width * inDepth + 7 // 8. |
|
560 "/ data4 := ByteArray uninitializedNew:(height * bytesPerRow). |
|
561 "/ inDepth == 8 ifTrue:[ |
|
562 "/ ]. |
|
563 "/ aStream nextBytes:(height * bytesPerRow) into:data4. |
|
564 "/ |
|
565 "/ "stupid: last row first" |
|
566 "/ |
|
567 "/ tmp := ByteArray new:(height * bytesPerRow). |
|
568 "/ srcIndex := 1. |
|
569 "/ dstIndex := (height - 1) * bytesPerRow + 1. |
|
570 "/ 1 to:height do:[:row | |
|
571 "/ tmp replaceFrom:dstIndex to:(dstIndex + bytesPerRow - 1) |
|
572 "/ with:data4 startingAt:srcIndex. |
|
573 "/ srcIndex := srcIndex + bytesPerRow. |
|
574 "/ dstIndex := dstIndex - bytesPerRow. |
|
575 "/ ]. |
|
576 "/ data4 := tmp. |
|
577 "/ |
|
578 "/ "expand into bytes" |
|
579 "/ |
|
580 "/ data := ByteArray new:(width * height). |
|
581 "/ data4 expandPixels:inDepth width:width height:height |
|
582 "/ into:data mapping:nil. |
|
583 "/ |
526 |
584 |
527 bytesPerRow := width * inDepth + 7 // 8. |
585 bytesPerRow := width * inDepth + 7 // 8. |
528 data4 := ByteArray uninitializedNew:(height * bytesPerRow). |
586 "/ bmp data is always 32bit aligned; if required, |
529 aStream nextBytes:(height * bytesPerRow) into:data4. |
587 inBytesPerRow := ((bytesPerRow + 3) // 4) * 4. |
530 |
588 |
531 "stupid: last row first" |
589 data := ByteArray uninitializedNew:(height * width "bytesPerRow"). |
532 |
590 (self loadBMPWidth:width height:height depth:inDepth compression:0 from:aStream into:data) ifFalse:[ |
533 tmp := ByteArray new:(height * bytesPerRow). |
591 ^ nil |
534 srcIndex := 1. |
592 ]. |
535 dstIndex := (height - 1) * bytesPerRow + 1. |
|
536 1 to:height do:[:row | |
|
537 tmp replaceFrom:dstIndex to:(dstIndex + bytesPerRow - 1) |
|
538 with:data4 startingAt:srcIndex. |
|
539 srcIndex := srcIndex + bytesPerRow. |
|
540 dstIndex := dstIndex - bytesPerRow. |
|
541 ]. |
|
542 data4 := tmp. |
|
543 |
|
544 "expand into bytes" |
|
545 |
|
546 data := ByteArray new:(width * height). |
|
547 data4 expandPixels:inDepth width:width height:height |
|
548 into:data mapping:nil. |
|
549 |
|
550 photometric := #palette. |
593 photometric := #palette. |
551 samplesPerPixel := 1. |
594 samplesPerPixel := 1. |
552 bitsPerSample := #(8). |
595 bitsPerSample := #(8). |
553 colorMap := Colormap redVector:rMap greenVector:gMap blueVector:bMap. |
596 colorMap := Colormap redVector:rMap greenVector:gMap blueVector:bMap. |
554 |
597 |