wrbmp.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. /*
  2. * wrbmp.c
  3. *
  4. * This file was part of the Independent JPEG Group's software:
  5. * Copyright (C) 1994-1996, Thomas G. Lane.
  6. * libjpeg-turbo Modifications:
  7. * Copyright (C) 2013, Linaro Limited.
  8. * Copyright (C) 2014-2015, 2017, 2019, 2022, D. R. Commander.
  9. * For conditions of distribution and use, see the accompanying README.ijg
  10. * file.
  11. *
  12. * This file contains routines to write output images in Microsoft "BMP"
  13. * format (MS Windows 3.x and OS/2 1.x flavors).
  14. * Either 8-bit colormapped or 24-bit full-color format can be written.
  15. * No compression is supported.
  16. *
  17. * These routines may need modification for non-Unix environments or
  18. * specialized applications. As they stand, they assume output to
  19. * an ordinary stdio stream.
  20. *
  21. * This code contributed by James Arthur Boucher.
  22. */
  23. #include "cmyk.h"
  24. #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
  25. #include "jconfigint.h"
  26. #ifdef BMP_SUPPORTED
  27. /*
  28. * To support 12-bit JPEG data, we'd have to scale output down to 8 bits.
  29. * This is not yet implemented.
  30. */
  31. #if BITS_IN_JSAMPLE != 8
  32. Sorry, this code only copes with 8-bit JSAMPLEs. /* deliberate syntax err */
  33. #endif
  34. /*
  35. * Since BMP stores scanlines bottom-to-top, we have to invert the image
  36. * from JPEG's top-to-bottom order. To do this, we save the outgoing data
  37. * in a virtual array during put_pixel_row calls, then actually emit the
  38. * BMP file during finish_output. The virtual array contains one JSAMPLE per
  39. * pixel if the output is grayscale or colormapped, three if it is full color.
  40. */
  41. /* Private version of data destination object */
  42. typedef struct {
  43. struct djpeg_dest_struct pub; /* public fields */
  44. boolean is_os2; /* saves the OS2 format request flag */
  45. jvirt_sarray_ptr whole_image; /* needed to reverse row order */
  46. JDIMENSION data_width; /* JSAMPLEs per row */
  47. JDIMENSION row_width; /* physical width of one row in the BMP file */
  48. int pad_bytes; /* number of padding bytes needed per row */
  49. JDIMENSION cur_output_row; /* next row# to write to virtual array */
  50. boolean use_inversion_array; /* TRUE = buffer the whole image, which is
  51. stored to disk in bottom-up order, and
  52. receive rows from the calling program in
  53. top-down order
  54. FALSE = the calling program will maintain
  55. its own image buffer and write the rows in
  56. bottom-up order */
  57. JSAMPLE *iobuffer; /* I/O buffer (used to buffer a single row to
  58. disk if use_inversion_array == FALSE) */
  59. } bmp_dest_struct;
  60. typedef bmp_dest_struct *bmp_dest_ptr;
  61. /* Forward declarations */
  62. LOCAL(void) write_colormap(j_decompress_ptr cinfo, bmp_dest_ptr dest,
  63. int map_colors, int map_entry_size);
  64. static INLINE boolean is_big_endian(void)
  65. {
  66. int test_value = 1;
  67. if (*(char *)&test_value != 1)
  68. return TRUE;
  69. return FALSE;
  70. }
  71. /*
  72. * Write some pixel data.
  73. * In this module rows_supplied will always be 1.
  74. */
  75. METHODDEF(void)
  76. put_pixel_rows(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
  77. JDIMENSION rows_supplied)
  78. /* This version is for writing 24-bit pixels */
  79. {
  80. bmp_dest_ptr dest = (bmp_dest_ptr)dinfo;
  81. JSAMPARRAY image_ptr;
  82. register JSAMPROW inptr, outptr;
  83. register JDIMENSION col;
  84. int pad;
  85. if (dest->use_inversion_array) {
  86. /* Access next row in virtual array */
  87. image_ptr = (*cinfo->mem->access_virt_sarray)
  88. ((j_common_ptr)cinfo, dest->whole_image,
  89. dest->cur_output_row, (JDIMENSION)1, TRUE);
  90. dest->cur_output_row++;
  91. outptr = image_ptr[0];
  92. } else {
  93. outptr = dest->iobuffer;
  94. }
  95. /* Transfer data. Note destination values must be in BGR order
  96. * (even though Microsoft's own documents say the opposite).
  97. */
  98. inptr = dest->pub.buffer[0];
  99. if (cinfo->out_color_space == JCS_EXT_BGR) {
  100. memcpy(outptr, inptr, dest->row_width);
  101. outptr += cinfo->output_width * 3;
  102. } else if (cinfo->out_color_space == JCS_RGB565) {
  103. boolean big_endian = is_big_endian();
  104. unsigned short *inptr2 = (unsigned short *)inptr;
  105. for (col = cinfo->output_width; col > 0; col--) {
  106. if (big_endian) {
  107. outptr[0] = (*inptr2 >> 5) & 0xF8;
  108. outptr[1] = ((*inptr2 << 5) & 0xE0) | ((*inptr2 >> 11) & 0x1C);
  109. outptr[2] = *inptr2 & 0xF8;
  110. } else {
  111. outptr[0] = (*inptr2 << 3) & 0xF8;
  112. outptr[1] = (*inptr2 >> 3) & 0xFC;
  113. outptr[2] = (*inptr2 >> 8) & 0xF8;
  114. }
  115. outptr += 3;
  116. inptr2++;
  117. }
  118. } else if (cinfo->out_color_space == JCS_CMYK) {
  119. for (col = cinfo->output_width; col > 0; col--) {
  120. JSAMPLE c = *inptr++, m = *inptr++, y = *inptr++, k = *inptr++;
  121. cmyk_to_rgb(c, m, y, k, outptr + 2, outptr + 1, outptr);
  122. outptr += 3;
  123. }
  124. } else {
  125. register int rindex = rgb_red[cinfo->out_color_space];
  126. register int gindex = rgb_green[cinfo->out_color_space];
  127. register int bindex = rgb_blue[cinfo->out_color_space];
  128. register int ps = rgb_pixelsize[cinfo->out_color_space];
  129. for (col = cinfo->output_width; col > 0; col--) {
  130. outptr[0] = inptr[bindex];
  131. outptr[1] = inptr[gindex];
  132. outptr[2] = inptr[rindex];
  133. outptr += 3; inptr += ps;
  134. }
  135. }
  136. /* Zero out the pad bytes. */
  137. pad = dest->pad_bytes;
  138. while (--pad >= 0)
  139. *outptr++ = 0;
  140. if (!dest->use_inversion_array)
  141. fwrite(dest->iobuffer, 1, dest->row_width, dest->pub.output_file);
  142. }
  143. METHODDEF(void)
  144. put_gray_rows(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
  145. JDIMENSION rows_supplied)
  146. /* This version is for grayscale OR quantized color output */
  147. {
  148. bmp_dest_ptr dest = (bmp_dest_ptr)dinfo;
  149. JSAMPARRAY image_ptr;
  150. register JSAMPROW inptr, outptr;
  151. int pad;
  152. if (dest->use_inversion_array) {
  153. /* Access next row in virtual array */
  154. image_ptr = (*cinfo->mem->access_virt_sarray)
  155. ((j_common_ptr)cinfo, dest->whole_image,
  156. dest->cur_output_row, (JDIMENSION)1, TRUE);
  157. dest->cur_output_row++;
  158. outptr = image_ptr[0];
  159. } else {
  160. outptr = dest->iobuffer;
  161. }
  162. /* Transfer data. */
  163. inptr = dest->pub.buffer[0];
  164. memcpy(outptr, inptr, cinfo->output_width);
  165. outptr += cinfo->output_width;
  166. /* Zero out the pad bytes. */
  167. pad = dest->pad_bytes;
  168. while (--pad >= 0)
  169. *outptr++ = 0;
  170. if (!dest->use_inversion_array)
  171. fwrite(dest->iobuffer, 1, dest->row_width, dest->pub.output_file);
  172. }
  173. /*
  174. * Finish up at the end of the file.
  175. *
  176. * Here is where we really output the BMP file.
  177. *
  178. * First, routines to write the Windows and OS/2 variants of the file header.
  179. */
  180. LOCAL(void)
  181. write_bmp_header(j_decompress_ptr cinfo, bmp_dest_ptr dest)
  182. /* Write a Windows-style BMP file header, including colormap if needed */
  183. {
  184. char bmpfileheader[14];
  185. char bmpinfoheader[40];
  186. #define PUT_2B(array, offset, value) \
  187. (array[offset] = (char)((value) & 0xFF), \
  188. array[offset + 1] = (char)(((value) >> 8) & 0xFF))
  189. #define PUT_4B(array, offset, value) \
  190. (array[offset] = (char)((value) & 0xFF), \
  191. array[offset + 1] = (char)(((value) >> 8) & 0xFF), \
  192. array[offset + 2] = (char)(((value) >> 16) & 0xFF), \
  193. array[offset + 3] = (char)(((value) >> 24) & 0xFF))
  194. long headersize, bfSize;
  195. int bits_per_pixel, cmap_entries;
  196. /* Compute colormap size and total file size */
  197. if (IsExtRGB(cinfo->out_color_space)) {
  198. if (cinfo->quantize_colors) {
  199. /* Colormapped RGB */
  200. bits_per_pixel = 8;
  201. cmap_entries = 256;
  202. } else {
  203. /* Unquantized, full color RGB */
  204. bits_per_pixel = 24;
  205. cmap_entries = 0;
  206. }
  207. } else if (cinfo->out_color_space == JCS_RGB565 ||
  208. cinfo->out_color_space == JCS_CMYK) {
  209. bits_per_pixel = 24;
  210. cmap_entries = 0;
  211. } else {
  212. /* Grayscale output. We need to fake a 256-entry colormap. */
  213. bits_per_pixel = 8;
  214. cmap_entries = 256;
  215. }
  216. /* File size */
  217. headersize = 14 + 40 + cmap_entries * 4; /* Header and colormap */
  218. bfSize = headersize + (long)dest->row_width * (long)cinfo->output_height;
  219. /* Set unused fields of header to 0 */
  220. memset(bmpfileheader, 0, sizeof(bmpfileheader));
  221. memset(bmpinfoheader, 0, sizeof(bmpinfoheader));
  222. /* Fill the file header */
  223. bmpfileheader[0] = 0x42; /* first 2 bytes are ASCII 'B', 'M' */
  224. bmpfileheader[1] = 0x4D;
  225. PUT_4B(bmpfileheader, 2, bfSize); /* bfSize */
  226. /* we leave bfReserved1 & bfReserved2 = 0 */
  227. PUT_4B(bmpfileheader, 10, headersize); /* bfOffBits */
  228. /* Fill the info header (Microsoft calls this a BITMAPINFOHEADER) */
  229. PUT_2B(bmpinfoheader, 0, 40); /* biSize */
  230. PUT_4B(bmpinfoheader, 4, cinfo->output_width); /* biWidth */
  231. PUT_4B(bmpinfoheader, 8, cinfo->output_height); /* biHeight */
  232. PUT_2B(bmpinfoheader, 12, 1); /* biPlanes - must be 1 */
  233. PUT_2B(bmpinfoheader, 14, bits_per_pixel); /* biBitCount */
  234. /* we leave biCompression = 0, for none */
  235. /* we leave biSizeImage = 0; this is correct for uncompressed data */
  236. if (cinfo->density_unit == 2) { /* if have density in dots/cm, then */
  237. PUT_4B(bmpinfoheader, 24, (long)(cinfo->X_density * 100)); /* XPels/M */
  238. PUT_4B(bmpinfoheader, 28, (long)(cinfo->Y_density * 100)); /* XPels/M */
  239. }
  240. PUT_2B(bmpinfoheader, 32, cmap_entries); /* biClrUsed */
  241. /* we leave biClrImportant = 0 */
  242. if (fwrite(bmpfileheader, 1, 14, dest->pub.output_file) != (size_t)14)
  243. ERREXIT(cinfo, JERR_FILE_WRITE);
  244. if (fwrite(bmpinfoheader, 1, 40, dest->pub.output_file) != (size_t)40)
  245. ERREXIT(cinfo, JERR_FILE_WRITE);
  246. if (cmap_entries > 0)
  247. write_colormap(cinfo, dest, cmap_entries, 4);
  248. }
  249. LOCAL(void)
  250. write_os2_header(j_decompress_ptr cinfo, bmp_dest_ptr dest)
  251. /* Write an OS2-style BMP file header, including colormap if needed */
  252. {
  253. char bmpfileheader[14];
  254. char bmpcoreheader[12];
  255. long headersize, bfSize;
  256. int bits_per_pixel, cmap_entries;
  257. /* Compute colormap size and total file size */
  258. if (IsExtRGB(cinfo->out_color_space)) {
  259. if (cinfo->quantize_colors) {
  260. /* Colormapped RGB */
  261. bits_per_pixel = 8;
  262. cmap_entries = 256;
  263. } else {
  264. /* Unquantized, full color RGB */
  265. bits_per_pixel = 24;
  266. cmap_entries = 0;
  267. }
  268. } else if (cinfo->out_color_space == JCS_RGB565 ||
  269. cinfo->out_color_space == JCS_CMYK) {
  270. bits_per_pixel = 24;
  271. cmap_entries = 0;
  272. } else {
  273. /* Grayscale output. We need to fake a 256-entry colormap. */
  274. bits_per_pixel = 8;
  275. cmap_entries = 256;
  276. }
  277. /* File size */
  278. headersize = 14 + 12 + cmap_entries * 3; /* Header and colormap */
  279. bfSize = headersize + (long)dest->row_width * (long)cinfo->output_height;
  280. /* Set unused fields of header to 0 */
  281. memset(bmpfileheader, 0, sizeof(bmpfileheader));
  282. memset(bmpcoreheader, 0, sizeof(bmpcoreheader));
  283. /* Fill the file header */
  284. bmpfileheader[0] = 0x42; /* first 2 bytes are ASCII 'B', 'M' */
  285. bmpfileheader[1] = 0x4D;
  286. PUT_4B(bmpfileheader, 2, bfSize); /* bfSize */
  287. /* we leave bfReserved1 & bfReserved2 = 0 */
  288. PUT_4B(bmpfileheader, 10, headersize); /* bfOffBits */
  289. /* Fill the info header (Microsoft calls this a BITMAPCOREHEADER) */
  290. PUT_2B(bmpcoreheader, 0, 12); /* bcSize */
  291. PUT_2B(bmpcoreheader, 4, cinfo->output_width); /* bcWidth */
  292. PUT_2B(bmpcoreheader, 6, cinfo->output_height); /* bcHeight */
  293. PUT_2B(bmpcoreheader, 8, 1); /* bcPlanes - must be 1 */
  294. PUT_2B(bmpcoreheader, 10, bits_per_pixel); /* bcBitCount */
  295. if (fwrite(bmpfileheader, 1, 14, dest->pub.output_file) != (size_t)14)
  296. ERREXIT(cinfo, JERR_FILE_WRITE);
  297. if (fwrite(bmpcoreheader, 1, 12, dest->pub.output_file) != (size_t)12)
  298. ERREXIT(cinfo, JERR_FILE_WRITE);
  299. if (cmap_entries > 0)
  300. write_colormap(cinfo, dest, cmap_entries, 3);
  301. }
  302. /*
  303. * Write the colormap.
  304. * Windows uses BGR0 map entries; OS/2 uses BGR entries.
  305. */
  306. LOCAL(void)
  307. write_colormap(j_decompress_ptr cinfo, bmp_dest_ptr dest, int map_colors,
  308. int map_entry_size)
  309. {
  310. JSAMPARRAY colormap = cinfo->colormap;
  311. int num_colors = cinfo->actual_number_of_colors;
  312. FILE *outfile = dest->pub.output_file;
  313. int i;
  314. if (colormap != NULL) {
  315. if (cinfo->out_color_components == 3) {
  316. /* Normal case with RGB colormap */
  317. for (i = 0; i < num_colors; i++) {
  318. putc(colormap[2][i], outfile);
  319. putc(colormap[1][i], outfile);
  320. putc(colormap[0][i], outfile);
  321. if (map_entry_size == 4)
  322. putc(0, outfile);
  323. }
  324. } else {
  325. /* Grayscale colormap (only happens with grayscale quantization) */
  326. for (i = 0; i < num_colors; i++) {
  327. putc(colormap[0][i], outfile);
  328. putc(colormap[0][i], outfile);
  329. putc(colormap[0][i], outfile);
  330. if (map_entry_size == 4)
  331. putc(0, outfile);
  332. }
  333. }
  334. } else {
  335. /* If no colormap, must be grayscale data. Generate a linear "map". */
  336. for (i = 0; i < 256; i++) {
  337. putc(i, outfile);
  338. putc(i, outfile);
  339. putc(i, outfile);
  340. if (map_entry_size == 4)
  341. putc(0, outfile);
  342. }
  343. }
  344. /* Pad colormap with zeros to ensure specified number of colormap entries */
  345. if (i > map_colors)
  346. ERREXIT1(cinfo, JERR_TOO_MANY_COLORS, i);
  347. for (; i < map_colors; i++) {
  348. putc(0, outfile);
  349. putc(0, outfile);
  350. putc(0, outfile);
  351. if (map_entry_size == 4)
  352. putc(0, outfile);
  353. }
  354. }
  355. /*
  356. * Startup: write the file header unless the inversion array is being used.
  357. */
  358. METHODDEF(void)
  359. start_output_bmp(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
  360. {
  361. bmp_dest_ptr dest = (bmp_dest_ptr)dinfo;
  362. if (!dest->use_inversion_array) {
  363. /* Write the header and colormap */
  364. if (dest->is_os2)
  365. write_os2_header(cinfo, dest);
  366. else
  367. write_bmp_header(cinfo, dest);
  368. }
  369. }
  370. METHODDEF(void)
  371. finish_output_bmp(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
  372. {
  373. bmp_dest_ptr dest = (bmp_dest_ptr)dinfo;
  374. register FILE *outfile = dest->pub.output_file;
  375. JSAMPARRAY image_ptr;
  376. register JSAMPROW data_ptr;
  377. JDIMENSION row;
  378. cd_progress_ptr progress = (cd_progress_ptr)cinfo->progress;
  379. if (dest->use_inversion_array) {
  380. /* Write the header and colormap */
  381. if (dest->is_os2)
  382. write_os2_header(cinfo, dest);
  383. else
  384. write_bmp_header(cinfo, dest);
  385. /* Write the file body from our virtual array */
  386. for (row = cinfo->output_height; row > 0; row--) {
  387. if (progress != NULL) {
  388. progress->pub.pass_counter = (long)(cinfo->output_height - row);
  389. progress->pub.pass_limit = (long)cinfo->output_height;
  390. (*progress->pub.progress_monitor) ((j_common_ptr)cinfo);
  391. }
  392. image_ptr = (*cinfo->mem->access_virt_sarray)
  393. ((j_common_ptr)cinfo, dest->whole_image, row - 1, (JDIMENSION)1,
  394. FALSE);
  395. data_ptr = image_ptr[0];
  396. fwrite(data_ptr, 1, dest->row_width, outfile);
  397. }
  398. if (progress != NULL)
  399. progress->completed_extra_passes++;
  400. }
  401. /* Make sure we wrote the output file OK */
  402. fflush(outfile);
  403. if (ferror(outfile))
  404. ERREXIT(cinfo, JERR_FILE_WRITE);
  405. }
  406. /*
  407. * The module selection routine for BMP format output.
  408. */
  409. GLOBAL(djpeg_dest_ptr)
  410. jinit_write_bmp(j_decompress_ptr cinfo, boolean is_os2,
  411. boolean use_inversion_array)
  412. {
  413. bmp_dest_ptr dest;
  414. JDIMENSION row_width;
  415. /* Create module interface object, fill in method pointers */
  416. dest = (bmp_dest_ptr)
  417. (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
  418. sizeof(bmp_dest_struct));
  419. dest->pub.start_output = start_output_bmp;
  420. dest->pub.finish_output = finish_output_bmp;
  421. dest->pub.calc_buffer_dimensions = NULL;
  422. dest->is_os2 = is_os2;
  423. if (cinfo->out_color_space == JCS_GRAYSCALE) {
  424. dest->pub.put_pixel_rows = put_gray_rows;
  425. } else if (IsExtRGB(cinfo->out_color_space)) {
  426. if (cinfo->quantize_colors)
  427. dest->pub.put_pixel_rows = put_gray_rows;
  428. else
  429. dest->pub.put_pixel_rows = put_pixel_rows;
  430. } else if (!cinfo->quantize_colors &&
  431. (cinfo->out_color_space == JCS_RGB565 ||
  432. cinfo->out_color_space == JCS_CMYK)) {
  433. dest->pub.put_pixel_rows = put_pixel_rows;
  434. } else {
  435. ERREXIT(cinfo, JERR_BMP_COLORSPACE);
  436. }
  437. /* Calculate output image dimensions so we can allocate space */
  438. jpeg_calc_output_dimensions(cinfo);
  439. /* Determine width of rows in the BMP file (padded to 4-byte boundary). */
  440. if (cinfo->out_color_space == JCS_RGB565) {
  441. row_width = cinfo->output_width * 2;
  442. dest->row_width = dest->data_width = cinfo->output_width * 3;
  443. while ((row_width & 3) != 0) row_width++;
  444. } else if (!cinfo->quantize_colors &&
  445. (IsExtRGB(cinfo->out_color_space) ||
  446. cinfo->out_color_space == JCS_CMYK)) {
  447. row_width = cinfo->output_width * cinfo->output_components;
  448. dest->row_width = dest->data_width = cinfo->output_width * 3;
  449. } else {
  450. row_width = cinfo->output_width * cinfo->output_components;
  451. dest->row_width = dest->data_width = row_width;
  452. }
  453. while ((dest->row_width & 3) != 0) dest->row_width++;
  454. dest->pad_bytes = (int)(dest->row_width - dest->data_width);
  455. if (use_inversion_array) {
  456. /* Allocate space for inversion array, prepare for write pass */
  457. dest->whole_image = (*cinfo->mem->request_virt_sarray)
  458. ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
  459. dest->row_width, cinfo->output_height, (JDIMENSION)1);
  460. dest->cur_output_row = 0;
  461. if (cinfo->progress != NULL) {
  462. cd_progress_ptr progress = (cd_progress_ptr)cinfo->progress;
  463. progress->total_extra_passes++; /* count file input as separate pass */
  464. }
  465. } else {
  466. dest->iobuffer = (JSAMPLE *)(*cinfo->mem->alloc_small)
  467. ((j_common_ptr)cinfo, JPOOL_IMAGE, dest->row_width);
  468. }
  469. dest->use_inversion_array = use_inversion_array;
  470. /* Create decompressor output buffer. */
  471. dest->pub.buffer = (*cinfo->mem->alloc_sarray)
  472. ((j_common_ptr)cinfo, JPOOL_IMAGE, row_width, (JDIMENSION)1);
  473. dest->pub.buffer_height = 1;
  474. return (djpeg_dest_ptr)dest;
  475. }
  476. #endif /* BMP_SUPPORTED */