1 /**************************************************************************
3 * Copyright 2010 VMware, Inc. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20 * IN NO EVENT SHALL THE AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 **************************************************************************/
28 #include "lp_tile_soa.h"
29 #include "lp_tile_image.h"
32 #define BYTES_PER_TILE (TILE_SIZE * TILE_SIZE * 4)
36 * Convert a tiled image into a linear image.
37 * \param src_stride source row stride in bytes (bytes per row of tiles)
38 * \param dst_stride dest row stride in bytes
41 lp_tiled_to_linear(const uint8_t *src
,
43 unsigned width
, unsigned height
,
44 enum pipe_format format
,
48 const unsigned tiles_per_row
= src_stride
/ BYTES_PER_TILE
;
51 for (j
= 0; j
< height
; j
+= TILE_SIZE
) {
52 for (i
= 0; i
< width
; i
+= TILE_SIZE
) {
53 unsigned tile_offset
=
54 ((j
/ TILE_SIZE
) * tiles_per_row
+ i
/ TILE_SIZE
);
55 unsigned byte_offset
= tile_offset
* BYTES_PER_TILE
;
56 const uint8_t *src_tile
= src
+ byte_offset
;
58 lp_tile_write_4ub(format
,
62 i
, j
, TILE_SIZE
, TILE_SIZE
);
69 * Convert a linear image into a tiled image.
70 * \param src_stride source row stride in bytes
71 * \param dst_stride dest row stride in bytes (bytes per row of tiles)
74 lp_linear_to_tiled(const uint8_t *src
,
76 unsigned width
, unsigned height
,
77 enum pipe_format format
,
81 const unsigned tiles_per_row
= dst_stride
/ BYTES_PER_TILE
;
84 for (j
= 0; j
< height
; j
+= TILE_SIZE
) {
85 for (i
= 0; i
< width
; i
+= TILE_SIZE
) {
86 unsigned tile_offset
=
87 ((j
/ TILE_SIZE
) * tiles_per_row
+ i
/ TILE_SIZE
);
88 unsigned byte_offset
= tile_offset
* BYTES_PER_TILE
;
89 uint8_t *dst_tile
= dst
+ byte_offset
;
91 lp_tile_read_4ub(format
,
95 i
, j
, TILE_SIZE
, TILE_SIZE
);
105 test_tiled_linear_conversion(uint8_t *data
,
106 enum pipe_format format
,
107 unsigned width
, unsigned height
,
111 unsigned wt
= (width
+ TILE_SIZE
- 1) / TILE_SIZE
;
112 unsigned ht
= (height
+ TILE_SIZE
- 1) / TILE_SIZE
;
114 uint8_t *tiled
= malloc(wt
* ht
* TILE_SIZE
* TILE_SIZE
* 4);
116 unsigned tiled_stride
= wt
* TILE_SIZE
* TILE_SIZE
* 4;
118 lp_linear_to_tiled(data
, tiled
, width
, height
, format
,
119 stride
, tiled_stride
);
121 lp_tiled_to_linear(tiled
, data
, width
, height
, format
,
122 tiled_stride
, stride
);