43 |
43 |
44 static my_error_exit(cinfo) |
44 static my_error_exit(cinfo) |
45 j_common_ptr cinfo; |
45 j_common_ptr cinfo; |
46 { |
46 { |
47 struct my_error_mgr *myerrPtr = (struct my_error_mgr *) cinfo->err; |
47 struct my_error_mgr *myerrPtr = (struct my_error_mgr *) cinfo->err; |
|
48 |
|
49 if (@global(ErrorPrinting) == true) { |
|
50 fprintf(stderr, "JPEGReader [warning]: jpeg error\n"); |
|
51 } |
48 longjmp(myerrPtr->setjmp_buffer, 1); |
52 longjmp(myerrPtr->setjmp_buffer, 1); |
49 } |
53 } |
50 |
54 |
51 %} |
55 %} |
52 ! ! |
56 ! ! |
393 RETURN (true); |
397 RETURN (true); |
394 } |
398 } |
395 %} |
399 %} |
396 ! |
400 ! |
397 |
401 |
|
402 get_error_message |
|
403 %{ |
|
404 struct jpeg_decompress *cinfoPtr; |
|
405 OBJ j_d_s = __INST(jpeg_decompress_struct); |
|
406 char buffer[JMSG_LENGTH_MAX+1]; |
|
407 |
|
408 if (__isExternalBytes(j_d_s)) { |
|
409 cinfoPtr = (struct jpeg_decompress *)(__externalBytesAddress(j_d_s)); |
|
410 |
|
411 (*cinfoPtr->err->format_message) (cinfoPtr, buffer); |
|
412 buffer[JMSG_LENGTH_MAX] = '\0'; |
|
413 RETURN ( __MKSTRING(buffer)); |
|
414 } |
|
415 %}. |
|
416 ^ nil |
|
417 ! |
|
418 |
398 start_decompress |
419 start_decompress |
399 %{ |
420 %{ |
400 struct jpeg_decompress *cinfoPtr; |
421 struct jpeg_decompress *cinfoPtr; |
401 struct my_error_mgr *jerrPtr; |
422 struct my_error_mgr *jerrPtr; |
402 OBJ j_d_s = __INST(jpeg_decompress_struct); |
423 OBJ j_d_s = __INST(jpeg_decompress_struct); |
426 |
447 |
427 |dataIdx bytesPerRow returnCode| |
448 |dataIdx bytesPerRow returnCode| |
428 |
449 |
429 inStream := aStream. |
450 inStream := aStream. |
430 |
451 |
431 (self create_jpeg_decompress_struct) ifFalse:[^ nil]. |
452 (self create_jpeg_decompress_struct not |
432 (self start_decompress) ifFalse:[^ nil]. |
453 or:[self start_decompress not]) ifTrue:[ |
|
454 'JPEGReader [info]: jpeg error: ' infoPrint. self get_error_message infoPrintCR. |
|
455 ^ nil |
|
456 ]. |
433 |
457 |
434 data := ByteArray uninitializedNew:(width * height * colorComponents). |
458 data := ByteArray uninitializedNew:(width * height * colorComponents). |
435 dataIdx := 1. |
459 dataIdx := 1. |
436 bytesPerRow := colorComponents * width. |
460 bytesPerRow := colorComponents * width. |
437 |
461 |
438 [(returnCode := self decompressChunkInto:data startingAt:dataIdx) > 0] whileTrue:[ |
462 [(returnCode := self decompressChunkInto:data startingAt:dataIdx) > 0] whileTrue:[ |
439 "/ got a row in the buffer ... |
463 "/ got a row in the buffer ... |
440 dataIdx := dataIdx + bytesPerRow |
464 dataIdx := dataIdx + bytesPerRow |
441 ]. |
465 ]. |
442 returnCode < 0 ifTrue:[ |
466 returnCode < 0 ifTrue:[ |
|
467 'JPEGReader [info]: jpeg error: ' infoPrint. self get_error_message infoPrintCR. |
443 ^ nil |
468 ^ nil |
444 ]. |
469 ]. |
445 |
470 |
446 (self finish_decompress) ifFalse:[^ nil]. |
471 (self finish_decompress) ifFalse:[ |
|
472 'JPEGReader [info]: jpeg error: ' infoPrint. self get_error_message infoPrintCR. |
|
473 ^ nil |
|
474 ]. |
447 |
475 |
448 colorComponents == 3 ifTrue:[ |
476 colorComponents == 3 ifTrue:[ |
449 photometric := #rgb. |
477 photometric := #rgb. |
450 samplesPerPixel := 3. |
478 samplesPerPixel := 3. |
451 bitsPerSample := #(8 8 8). |
479 bitsPerSample := #(8 8 8). |
452 ] ifFalse:[ |
480 ] ifFalse:[ |
453 self halt:'unexpected value' |
481 photometric := #blackIs0. |
|
482 samplesPerPixel := 1. |
|
483 bitsPerSample := #(8). |
454 ]. |
484 ]. |
455 |
485 |
456 " |
486 " |
457 JPEGReader fromFile:'../../support/libjpeg-6a/testimg.jpg' |
487 JPEGReader fromFile:'../../support/libjpeg-6a/testimg.jpg' |
458 " |
488 " |