block->height = desc->block.height;
}
+/**
+ * Return total bits needed for the pixel format.
+ */
+static INLINE uint
+util_format_get_bits(enum pipe_format format)
+{
+ const struct util_format_description *desc = util_format_description(format);
+
+ assert(format);
+ if (!format) {
+ return 0;
+ }
+
+ return desc->block.bits / (desc->block.width * desc->block.height);
+}
+
+/**
+ * Return bytes per pixel for the given format.
+ */
+static INLINE uint
+util_format_get_size(enum pipe_format format)
+{
+ uint bits = util_format_get_bits(format);
+
+ assert(bits % 8 == 0);
+
+ return bits / 8;
+}
+
/*
* Format access functions.
#include "pipe/p_shader_tokens.h"
#include "pipe/p_state.h"
+#include "util/u_format.h"
#include "util/u_memory.h"
#include "util/u_draw_quad.h"
#include "util/u_gen_mipmap.h"
{
enum dtype datatype;
uint comps;
- const int bpt = pf_get_size(pformat);
+ const int bpt = util_format_get_size(pformat);
const ubyte *srcA, *srcB;
ubyte *dst;
int row;
int dstWidth, int dstHeight, int dstDepth,
int dstRowStride, ubyte *dstPtr)
{
- const int bpt = pf_get_size(pformat);
+ const int bpt = util_format_get_size(pformat);
const int border = 0;
int img, row;
int bytesPerSrcImage, bytesPerDstImage;
#include "pipe/p_defines.h"
#include "pipe/p_inlines.h"
#include "pipe/internal/p_winsys_screen.h"
+
+#include "util/u_format.h"
#include "util/u_math.h"
#include "util/u_memory.h"
if (transfer->usage & PIPE_TRANSFER_READ) {
/* need to untwiddle the texture to make a linear version */
- const uint bpp = pf_get_size(ct->base.format);
+ const uint bpp = util_format_get_size(ct->base.format);
if (bpp == 4) {
const uint *src = (uint *) (ct->mapped + ctrans->offset);
uint *dst = ctrans->map;
/* The user wrote new texture data into the mapped buffer.
* We need to convert the new linear data into the twiddled/tiled format.
*/
- const uint bpp = pf_get_size(ct->base.format);
+ const uint bpp = util_format_get_size(ct->base.format);
if (bpp == 4) {
const uint *src = ctrans->map;
uint *dst = (uint *) (ct->mapped + ctrans->offset);
/* r300_emit: Functions for emitting state. */
+#include "util/u_format.h"
#include "util/u_math.h"
#include "r300_context.h"
for (i = 0; i < aos_count - 1; i += 2) {
int buf_num1 = velem[i].vertex_buffer_index;
int buf_num2 = velem[i+1].vertex_buffer_index;
- assert(vbuf[buf_num1].stride % 4 == 0 && pf_get_size(velem[i].src_format) % 4 == 0);
- assert(vbuf[buf_num2].stride % 4 == 0 && pf_get_size(velem[i+1].src_format) % 4 == 0);
- OUT_CS((pf_get_size(velem[i].src_format) >> 2) | (vbuf[buf_num1].stride << 6) |
- (pf_get_size(velem[i+1].src_format) << 14) | (vbuf[buf_num2].stride << 22));
+ assert(vbuf[buf_num1].stride % 4 == 0 && util_format_get_size(velem[i].src_format) % 4 == 0);
+ assert(vbuf[buf_num2].stride % 4 == 0 && util_format_get_size(velem[i+1].src_format) % 4 == 0);
+ OUT_CS((util_format_get_size(velem[i].src_format) >> 2) | (vbuf[buf_num1].stride << 6) |
+ (util_format_get_size(velem[i+1].src_format) << 14) | (vbuf[buf_num2].stride << 22));
OUT_CS(vbuf[buf_num1].buffer_offset + velem[i].src_offset +
offset * vbuf[buf_num1].stride);
OUT_CS(vbuf[buf_num2].buffer_offset + velem[i+1].src_offset +
}
if (aos_count & 1) {
int buf_num = velem[i].vertex_buffer_index;
- assert(vbuf[buf_num].stride % 4 == 0 && pf_get_size(velem[i].src_format) % 4 == 0);
- OUT_CS((pf_get_size(velem[i].src_format) >> 2) | (vbuf[buf_num].stride << 6));
+ assert(vbuf[buf_num].stride % 4 == 0 && util_format_get_size(velem[i].src_format) % 4 == 0);
+ OUT_CS((util_format_get_size(velem[i].src_format) >> 2) | (vbuf[buf_num].stride << 6));
OUT_CS(vbuf[buf_num].buffer_offset + velem[i].src_offset +
offset * vbuf[buf_num].stride);
}
*/
#include "pipe/p_inlines.h"
+#include "util/u_format.h"
#include "util/u_memory.h"
#include "util/u_tile.h"
#include "sp_tile_cache.h"
{
uint i, j;
- switch (pf_get_size(format)) {
+ switch (util_format_get_size(format)) {
case 1:
memset(tile->data.any, clear_value, TILE_SIZE * TILE_SIZE);
break;
#include "pipe/p_inlines.h"
#include "pipe/p_defines.h"
+#include "util/u_format.h"
#include "util/u_math.h"
#include "translate/translate.h"
mapped_buffer = pipe_buffer_map_range(svga->pipe.screen,
vbuffer->buffer,
vel->src_offset,
- pf_get_size(vel->src_format),
+ util_format_get_size(vel->src_format),
PIPE_BUFFER_USAGE_CPU_READ);
translate->set_buffer(translate, vel->vertex_buffer_index,
mapped_buffer,
return size << (pf_mixed_scale8( format ) * 3);
}
-/**
- * Return total bits needed for the pixel format.
- */
-static INLINE uint pf_get_bits( enum pipe_format format )
-{
- switch (pf_layout(format)) {
- case PIPE_FORMAT_LAYOUT_RGBAZS:
- case PIPE_FORMAT_LAYOUT_MIXED:
- return
- pf_get_component_bits( format, PIPE_FORMAT_COMP_0 ) +
- pf_get_component_bits( format, PIPE_FORMAT_COMP_1 ) +
- pf_get_component_bits( format, PIPE_FORMAT_COMP_R ) +
- pf_get_component_bits( format, PIPE_FORMAT_COMP_G ) +
- pf_get_component_bits( format, PIPE_FORMAT_COMP_B ) +
- pf_get_component_bits( format, PIPE_FORMAT_COMP_A ) +
- pf_get_component_bits( format, PIPE_FORMAT_COMP_Z ) +
- pf_get_component_bits( format, PIPE_FORMAT_COMP_S );
- case PIPE_FORMAT_LAYOUT_YCBCR:
- assert( format == PIPE_FORMAT_YCBCR || format == PIPE_FORMAT_YCBCR_REV );
- /* return effective bits per pixel */
- return 16;
- default:
- assert( 0 );
- return 0;
- }
-}
-
-/**
- * Return bytes per pixel for the given format.
- */
-static INLINE uint pf_get_size( enum pipe_format format )
-{
- assert(pf_get_bits(format) % 8 == 0);
- return pf_get_bits(format) / 8;
-}
-
/**
* Describe accurately the pixel format.
*
#include "pipe/p_format.h"
#include "pipe/p_context.h"
#include "pipe/p_inlines.h"
+#include "util/u_format.h"
#include "util/u_math.h"
#include "util/u_memory.h"
#include "llvmpipe/lp_winsys.h"
gdt->width = width;
gdt->height = height;
- bpp = pf_get_bits(format);
- cpp = pf_get_size(format);
+ bpp = util_format_get_bits(format);
+ cpp = util_format_get_size(format);
gdt->stride = round_up(width * cpp, alignment);
gdt->size = gdt->stride * height;
memset(&bmi, 0, sizeof(BITMAPINFO));
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
- bmi.bmiHeader.biWidth = texture->stride[surface->level] / pf_get_size(surface->format);
+ bmi.bmiHeader.biWidth = texture->stride[surface->level] / util_format_get_size(surface->format);
bmi.bmiHeader.biHeight= -(long)surface->height;
bmi.bmiHeader.biPlanes = 1;
- bmi.bmiHeader.biBitCount = pf_get_bits(surface->format);
+ bmi.bmiHeader.biBitCount = util_format_get_bits(surface->format);
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biSizeImage = 0;
bmi.bmiHeader.biXPelsPerMeter = 0;
/* copy/pack data into user buffer */
if (st_equal_formats(stImage->pt->format, format, type)) {
/* memcpy */
- const uint bytesPerRow = width * pf_get_size(stImage->pt->format);
+ const uint bytesPerRow = width * util_format_get_size(stImage->pt->format);
ubyte *map = screen->transfer_map(screen, tex_xfer);
GLuint row;
for (row = 0; row < height; row++) {