test.pas 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. Unit Test;
  2. interface
  3. uses
  4. jmorecfg, jpeglib;
  5. const
  6. MaxWidth = 175;
  7. MaxLines = 4;
  8. type
  9. RGB_pixel = packed record
  10. Case byte of
  11. 0:(r,g,b : byte);
  12. 1:(color:array[0..2] of byte);
  13. 2:(cyan,magenta,yellow : byte);
  14. 3:(Y,Cb,Cr : byte);
  15. end;
  16. var
  17. image_line : array[0..MaxLines-1,0..MaxWidth-1] of RGB_pixel;
  18. var
  19. image_buffer : JSAMPROW; { Points to large array of R,G,B-order data }
  20. image_height : int; { Number of rows in image }
  21. image_width : int; { Number of columns in image }
  22. var
  23. current_line : int;
  24. type
  25. jmp_buf = pointer;
  26. { This routine does the output }
  27. procedure put_scanline_someplace(buffer : JSAMPROW; row_stride : int);
  28. { define an error recovery point. Return 0 when OK }
  29. function setjmp(setjmp_buffer : jmp_buf) : int;
  30. { Return control to the setjmp point }
  31. procedure longjmp(setjmp_buffer : jmp_buf; flag : int);
  32. procedure save_color_map(cinfo : j_decompress_ptr);
  33. procedure define_image_params;
  34. procedure pre_decode;
  35. procedure post_decode;
  36. implementation
  37. var
  38. outfile : file;
  39. { This routine does the output }
  40. procedure put_scanline_someplace(buffer : JSAMPROW; row_stride : int);
  41. var
  42. line_size : int;
  43. begin
  44. WriteLn(output, current_line:3, '. line of image data read');
  45. line_size := 3 * MaxWidth;
  46. BlockWrite(outfile, buffer^, row_stride);
  47. if line_size > row_stride then
  48. line_size := row_stride;
  49. if current_line < MaxLines then
  50. Move(buffer^, image_line[current_line], line_size);
  51. Inc(current_line);
  52. end;
  53. { define an error recovery point. Return 0 when OK }
  54. function setjmp(setjmp_buffer : jmp_buf) : int;
  55. begin
  56. setjmp := 0;
  57. current_line := 0;
  58. end;
  59. { Return control to the setjmp point }
  60. procedure longjmp(setjmp_buffer : jmp_buf; flag : int);
  61. begin
  62. Halt(2);
  63. end;
  64. procedure define_image_params;
  65. var
  66. i, j : JDIMENSION;
  67. r0, b0, g0 : byte;
  68. begin
  69. r0 := 255;
  70. g0 := 255;
  71. b0 := 255;
  72. for j := 0 to pred(MaxLines) do
  73. begin
  74. for i := 0 to Pred(MaxWidth) do
  75. with image_line[j][i] do
  76. begin
  77. r := r0;
  78. Dec(r0);
  79. g := g0;
  80. b := b0;
  81. end;
  82. Dec(b0, 16);
  83. end;
  84. image_buffer := JSAMPROW(@image_line);
  85. image_height := MaxLines;
  86. image_width := MaxWidth;
  87. end;
  88. procedure pre_decode;
  89. begin
  90. Assign(outfile, 'PasJpeg.raw');
  91. ReWrite(outfile, 1);
  92. end;
  93. procedure save_color_map(cinfo : j_decompress_ptr);
  94. var
  95. VGAPalette : Array[0..255] of RGB_pixel;
  96. i, count : int;
  97. begin
  98. count := cinfo^.actual_number_of_colors;
  99. if (cinfo^.colormap <> NIL) and (count > 0) then
  100. begin
  101. if count > 256 then
  102. count := 256;
  103. if (cinfo^.out_color_components = 3) then
  104. for i := 0 to pred(count) do
  105. begin
  106. VGAPalette[i].r := cinfo^.colormap^[0]^[i];
  107. VGAPalette[i].g := cinfo^.colormap^[1]^[i];
  108. VGAPalette[i].b := cinfo^.colormap^[2]^[i];
  109. end
  110. else { Grayscale colormap (only happens with grayscale quantization) }
  111. for i := 0 to pred(count) do
  112. begin
  113. VGAPalette[i].r := cinfo^.colormap^[0]^[i];
  114. VGAPalette[i].g := cinfo^.colormap^[0]^[i];
  115. VGAPalette[i].b := cinfo^.colormap^[0]^[i];
  116. end;
  117. BlockWrite(outfile, VGAPalette, 3*count);
  118. end;
  119. end;
  120. procedure post_decode;
  121. begin
  122. Close(outfile);
  123. end;
  124. end.