pixel.c revision 60c5ad80416e2e87984ea003fac07c55effa5939
/* Copyright (c) 2001, Stanford University
* All rights reserved
*
* See the file LICENSE.txt for information on redistributing this software.
*/
#include "cr_pixeldata.h"
#include "cr_error.h"
#include "cr_mem.h"
#include "cr_version.h"
/**
* Maybe export this someday.
*/
{
switch (type) {
#ifdef CR_OPENGL_VERSION_1_2
case GL_UNSIGNED_BYTE_3_3_2:
#endif
case GL_UNSIGNED_BYTE:
case GL_BYTE:
return 1;
case GL_BITMAP:
return 0; /* special case */
#ifdef CR_OPENGL_VERSION_1_2
case GL_UNSIGNED_SHORT_5_6_5:
#endif
case GL_UNSIGNED_SHORT:
case GL_SHORT:
return 2;
#ifdef CR_OPENGL_VERSION_1_2
case GL_UNSIGNED_INT_8_8_8_8:
#endif
case GL_UNSIGNED_INT:
case GL_INT:
case GL_FLOAT:
return 4;
case GL_DOUBLE:
return 8;
default:
return 0;
}
}
/**
* \return bytes per pixel or -1 for invalid format or type, 0 for bitmap data.
*/
{
switch (type) {
#ifdef CR_OPENGL_VERSION_1_2
case GL_UNSIGNED_BYTE_3_3_2:
return 1;
#endif
case GL_UNSIGNED_BYTE:
case GL_BYTE:
bytes = 1;
break;
case GL_BITMAP:
return 0; /* special case */
#ifdef CR_OPENGL_VERSION_1_2
case GL_UNSIGNED_SHORT_5_6_5:
return 2;
#endif
case GL_UNSIGNED_SHORT:
case GL_SHORT:
bytes = 2;
break;
#ifdef CR_OPENGL_VERSION_1_2
case GL_UNSIGNED_INT_8_8_8_8:
return 4;
#endif
case GL_UNSIGNED_INT:
case GL_INT:
case GL_FLOAT:
bytes = 4;
break;
default:
crWarning( "Unknown pixel type in crPixelSize: type:0x%x(fmt:0x%x)", (unsigned int) type, (unsigned int) format);
return 0;
}
switch (format) {
case GL_COLOR_INDEX:
case GL_STENCIL_INDEX:
case GL_DEPTH_COMPONENT:
case GL_RED:
case GL_GREEN:
case GL_BLUE:
case GL_ALPHA:
case GL_LUMINANCE:
case GL_INTENSITY:
break;
case GL_LUMINANCE_ALPHA:
bytes *= 2;
break;
case GL_RGB:
#ifdef CR_OPENGL_VERSION_1_2
case GL_BGR:
#endif
bytes *= 3;
break;
case GL_RGBA:
#ifdef GL_ABGR_EXT
case GL_ABGR_EXT:
#endif
#ifdef CR_OPENGL_VERSION_1_2
case GL_BGRA:
#endif
bytes *= 4;
break;
default:
crWarning( "Unknown pixel format in crPixelSize: type:0x%x(fmt:0x%x)", (unsigned int) type, (unsigned int) format);
return 0;
}
return bytes;
}
#ifdef _MSC_VER
* optimizations enabled. It varies a bit between 8.0/64 and 7.1/32 - the latter seems
* to be fine with just disabling opts for get_row, while the former needs both to be
* disabled to compile it a decent time. It seems this isn't important code after all,
* so we're not overly worried about the performance degration. Even so, we might want
* to look into it before long, perhaps checking with Visual C++ 9.0 (aka 2008). */
#endif
/*
* Pack src pixel data into tmpRow array as either GLfloat[][1] or
* GLfloat[][4] depending on whether the format is for colors.
*/
static void
{
int i;
switch (srcType) {
case GL_BYTE:
for (i = 0; i < width; i++)
break;
case GL_UNSIGNED_BYTE:
for (i = 0; i < width; i++)
break;
case GL_SHORT:
for (i = 0; i < width; i++)
break;
case GL_UNSIGNED_SHORT:
for (i = 0; i < width; i++)
break;
case GL_INT:
for (i = 0; i < width; i++)
break;
case GL_UNSIGNED_INT:
for (i = 0; i < width; i++)
break;
case GL_FLOAT:
for (i = 0; i < width; i++)
break;
case GL_DOUBLE:
for (i = 0; i < width; i++)
break;
default:
}
}
else if (srcFormat == GL_DEPTH_COMPONENT) {
switch (srcType) {
case GL_BYTE:
for (i = 0; i < width; i++)
break;
case GL_UNSIGNED_BYTE:
for (i = 0; i < width; i++)
break;
case GL_SHORT:
for (i = 0; i < width; i++)
break;
case GL_UNSIGNED_SHORT:
for (i = 0; i < width; i++)
break;
case GL_INT:
for (i = 0; i < width; i++)
break;
case GL_UNSIGNED_INT:
for (i = 0; i < width; i++)
break;
case GL_FLOAT:
for (i = 0; i < width; i++)
break;
case GL_DOUBLE:
for (i = 0; i < width; i++)
break;
default:
}
}
int dst;
dst = 0;
dst = 1;
dst = 2;
else
dst = 3;
for (i = 0; i < width; i++) {
}
switch (srcType) {
case GL_BYTE:
break;
case GL_UNSIGNED_BYTE:
break;
case GL_SHORT:
break;
case GL_UNSIGNED_SHORT:
break;
case GL_INT:
break;
case GL_UNSIGNED_INT:
break;
case GL_FLOAT:
break;
case GL_DOUBLE:
break;
default:
}
}
else if (srcFormat == GL_LUMINANCE) {
switch (srcType) {
case GL_BYTE:
for (i = 0; i < width; i++) {
}
break;
case GL_UNSIGNED_BYTE:
for (i = 0; i < width; i++) {
}
break;
case GL_SHORT:
for (i = 0; i < width; i++) {
}
break;
case GL_UNSIGNED_SHORT:
for (i = 0; i < width; i++) {
}
break;
case GL_INT:
for (i = 0; i < width; i++) {
}
break;
case GL_UNSIGNED_INT:
for (i = 0; i < width; i++) {
}
break;
case GL_FLOAT:
for (i = 0; i < width; i++) {
}
break;
case GL_DOUBLE:
for (i = 0; i < width; i++) {
}
break;
default:
}
}
else if (srcFormat == GL_INTENSITY) {
switch (srcType) {
case GL_BYTE:
for (i = 0; i < width; i++)
break;
case GL_UNSIGNED_BYTE:
for (i = 0; i < width; i++)
break;
case GL_SHORT:
for (i = 0; i < width; i++)
break;
case GL_UNSIGNED_SHORT:
for (i = 0; i < width; i++)
break;
case GL_INT:
for (i = 0; i < width; i++)
break;
case GL_UNSIGNED_INT:
for (i = 0; i < width; i++)
= UINT_TO_FLOAT(uiSrc[i]);
break;
case GL_FLOAT:
for (i = 0; i < width; i++)
= fSrc[i];
break;
case GL_DOUBLE:
for (i = 0; i < width; i++)
break;
default:
}
}
else if (srcFormat == GL_LUMINANCE_ALPHA) {
switch (srcType) {
case GL_BYTE:
for (i = 0; i < width; i++) {
}
break;
case GL_UNSIGNED_BYTE:
for (i = 0; i < width; i++) {
}
break;
case GL_SHORT:
for (i = 0; i < width; i++) {
}
break;
case GL_UNSIGNED_SHORT:
for (i = 0; i < width; i++) {
}
break;
case GL_INT:
for (i = 0; i < width; i++) {
}
break;
case GL_UNSIGNED_INT:
for (i = 0; i < width; i++) {
}
break;
case GL_FLOAT:
for (i = 0; i < width; i++) {
}
break;
case GL_DOUBLE:
for (i = 0; i < width; i++) {
}
break;
default:
}
}
#ifdef CR_OPENGL_VERSION_1_2
#endif
) {
int r, b;
r = 0; b = 2;
}
else {
r = 2; b = 0;
}
switch (srcType) {
case GL_BYTE:
for (i = 0; i < width; i++) {
}
break;
case GL_UNSIGNED_BYTE:
for (i = 0; i < width; i++) {
}
break;
case GL_SHORT:
for (i = 0; i < width; i++) {
}
break;
case GL_UNSIGNED_SHORT:
for (i = 0; i < width; i++) {
}
break;
case GL_INT:
for (i = 0; i < width; i++) {
}
break;
case GL_UNSIGNED_INT:
for (i = 0; i < width; i++) {
}
break;
case GL_FLOAT:
for (i = 0; i < width; i++) {
}
break;
case GL_DOUBLE:
for (i = 0; i < width; i++) {
}
break;
#ifdef CR_OPENGL_VERSION_1_2
case GL_UNSIGNED_BYTE_3_3_2:
for (i = 0; i < width; i++) {
}
break;
for (i = 0; i < width; i++) {
}
break;
case GL_UNSIGNED_SHORT_5_6_5:
for (i = 0; i < width; i++) {
}
break;
for (i = 0; i < width; i++) {
}
break;
#endif
default:
}
}
#ifdef CR_OPENGL_VERSION_1_2
#endif
) {
int r, b;
r = 0; b = 2;
}
else {
r = 2; b = 0;
}
switch (srcType) {
case GL_BYTE:
for (i = 0; i < width; i++) {
}
break;
case GL_UNSIGNED_BYTE:
for (i = 0; i < width; i++) {
}
break;
case GL_SHORT:
for (i = 0; i < width; i++) {
}
break;
case GL_UNSIGNED_SHORT:
for (i = 0; i < width; i++) {
}
break;
case GL_INT:
for (i = 0; i < width; i++) {
}
break;
case GL_UNSIGNED_INT:
for (i = 0; i < width; i++) {
}
break;
case GL_FLOAT:
for (i = 0; i < width; i++) {
}
break;
case GL_DOUBLE:
for (i = 0; i < width; i++) {
}
break;
#ifdef CR_OPENGL_VERSION_1_2
for (i = 0; i < width; i++) {
}
break;
for (i = 0; i < width; i++) {
}
break;
for (i = 0; i < width; i++) {
}
break;
for (i = 0; i < width; i++) {
}
break;
case GL_UNSIGNED_INT_8_8_8_8:
for (i = 0; i < width; i++) {
}
break;
for (i = 0; i < width; i++) {
}
break;
for (i = 0; i < width; i++) {
}
break;
for (i = 0; i < width; i++) {
}
break;
#endif
default:
}
}
else{
}
}
{
int i;
switch (dstType) {
case GL_BYTE:
for (i = 0; i < width; i++)
break;
case GL_UNSIGNED_BYTE:
for (i = 0; i < width; i++)
break;
case GL_SHORT:
for (i = 0; i < width; i++)
break;
case GL_UNSIGNED_SHORT:
for (i = 0; i < width; i++)
break;
case GL_INT:
for (i = 0; i < width; i++)
break;
case GL_UNSIGNED_INT:
for (i = 0; i < width; i++)
break;
case GL_FLOAT:
for (i = 0; i < width; i++)
break;
case GL_DOUBLE:
for (i = 0; i < width; i++)
break;
default:
}
}
else if (dstFormat == GL_DEPTH_COMPONENT) {
switch (dstType) {
case GL_BYTE:
for (i = 0; i < width; i++)
break;
case GL_UNSIGNED_BYTE:
for (i = 0; i < width; i++)
break;
case GL_SHORT:
for (i = 0; i < width; i++)
break;
case GL_UNSIGNED_SHORT:
for (i = 0; i < width; i++)
break;
case GL_INT:
for (i = 0; i < width; i++)
break;
case GL_UNSIGNED_INT:
for (i = 0; i < width; i++)
break;
case GL_FLOAT:
for (i = 0; i < width; i++)
break;
case GL_DOUBLE:
for (i = 0; i < width; i++)
break;
default:
}
}
int index;
index = 0;
else if (dstFormat == GL_LUMINANCE)
index = 0;
else if (dstFormat == GL_INTENSITY)
index = 0;
index = 1;
index = 2;
else
index = 3;
switch (dstType) {
case GL_BYTE:
for (i = 0; i < width; i++)
break;
case GL_UNSIGNED_BYTE:
for (i = 0; i < width; i++)
break;
case GL_SHORT:
for (i = 0; i < width; i++)
break;
case GL_UNSIGNED_SHORT:
for (i = 0; i < width; i++)
break;
case GL_INT:
for (i = 0; i < width; i++)
break;
case GL_UNSIGNED_INT:
for (i = 0; i < width; i++)
break;
case GL_FLOAT:
for (i = 0; i < width; i++)
break;
case GL_DOUBLE:
for (i = 0; i < width; i++)
break;
default:
}
}
else if (dstFormat == GL_LUMINANCE_ALPHA) {
switch (dstType) {
case GL_BYTE:
for (i = 0; i < width; i++) {
}
break;
case GL_UNSIGNED_BYTE:
for (i = 0; i < width; i++) {
}
break;
case GL_SHORT:
for (i = 0; i < width; i++) {
}
break;
case GL_UNSIGNED_SHORT:
for (i = 0; i < width; i++) {
}
break;
case GL_INT:
for (i = 0; i < width; i++) {
}
break;
case GL_UNSIGNED_INT:
for (i = 0; i < width; i++) {
}
break;
case GL_FLOAT:
for (i = 0; i < width; i++) {
}
break;
case GL_DOUBLE:
for (i = 0; i < width; i++) {
}
break;
default:
}
}
#ifdef CR_OPENGL_VERSION_1_2
#endif
) {
int r, b;
r = 0; b = 2;
}
else {
r = 2; b = 0;
}
switch (dstType) {
case GL_BYTE:
for (i = 0; i < width; i++) {
}
break;
case GL_UNSIGNED_BYTE:
for (i = 0; i < width; i++) {
}
break;
case GL_SHORT:
for (i = 0; i < width; i++) {
}
break;
case GL_UNSIGNED_SHORT:
for (i = 0; i < width; i++) {
}
break;
case GL_INT:
for (i = 0; i < width; i++) {
}
break;
case GL_UNSIGNED_INT:
for (i = 0; i < width; i++) {
}
break;
case GL_FLOAT:
for (i = 0; i < width; i++) {
}
break;
case GL_DOUBLE:
for (i = 0; i < width; i++) {
}
break;
#ifdef CR_OPENGL_VERSION_1_2
case GL_UNSIGNED_BYTE_3_3_2:
for (i = 0; i < width; i++) {
}
break;
for (i = 0; i < width; i++) {
}
break;
case GL_UNSIGNED_SHORT_5_6_5:
for (i = 0; i < width; i++) {
}
break;
for (i = 0; i < width; i++) {
}
break;
#endif
default:
}
}
#ifdef CR_OPENGL_VERSION_1_2
#endif
) {
int r, b;
r = 0; b = 2;
}
else {
r = 2; b = 0;
}
switch (dstType) {
case GL_BYTE:
for (i = 0; i < width; i++) {
}
break;
case GL_UNSIGNED_BYTE:
for (i = 0; i < width; i++) {
}
break;
case GL_SHORT:
for (i = 0; i < width; i++) {
}
break;
case GL_UNSIGNED_SHORT:
for (i = 0; i < width; i++) {
}
break;
case GL_INT:
for (i = 0; i < width; i++) {
}
break;
case GL_UNSIGNED_INT:
for (i = 0; i < width; i++) {
}
break;
case GL_FLOAT:
for (i = 0; i < width; i++) {
}
break;
case GL_DOUBLE:
for (i = 0; i < width; i++) {
}
break;
#ifdef CR_OPENGL_VERSION_1_2
for (i = 0; i < width; i++) {
}
break;
for (i = 0; i < width; i++) {
}
break;
for (i = 0; i < width; i++) {
}
break;
for (i = 0; i < width; i++) {
}
break;
case GL_UNSIGNED_INT_8_8_8_8:
for (i = 0; i < width; i++) {
}
break;
for (i = 0; i < width; i++) {
}
break;
for (i = 0; i < width; i++) {
}
break;
for (i = 0; i < width; i++) {
}
break;
#endif
default:
}
}
else{
}
}
#ifdef _MSC_VER
#endif
/**
* Byte-swap an array of GLushorts
*/
static void
{
GLuint i;
for (i = 0; i < n; i++) {
}
}
/**
* Byte-swap an array of GLuints
*/
static void
{
GLuint i;
for (i = 0; i < n; i++) {
ui[i] = (b >> 24)
| ((b >> 8) & 0xff00)
| ((b << 8) & 0xff0000)
| ((b << 24) & 0xff000000);
}
}
/**
* Return number of bytes of storage needed to accomodate an
* image with the given format, type, and size.
* \return size in bytes or -1 if bad format or type
*/
{
{
/* This was wrong in the old code! */
}
{
/*GL_DEPTH_COMPONENT with GL_UNSIGNED_BYTE seems is more that 1 byte per pixel*/
}
else
{
}
return bytes;
}
/**
* Return number of bytes of storage needed to accomodate a
* 3D texture with the give format, type, and size.
* \return size in bytes or -1 if bad format or type
*/
unsigned int crTextureSize( GLenum format, GLenum type, GLsizei width, GLsizei height, GLsizei depth )
{
{
/*
* Not sure about this one, so just multiply
* by the depth?
*/
}
else
{
}
return bytes;
}
static const CRPixelPackState defaultPacking = {
0, /* rowLength */
0, /* skipRows */
0, /* skipPixels */
1, /* alignment */
0, /* imageHeight */
0, /* skipImages */
GL_FALSE, /* swapBytes */
GL_FALSE /* psLSBFirst */
};
{
}
const CRPixelPackState *dstPacking,
const CRPixelPackState *srcPacking )
{
int srcBytesPerPixel;
int dstBytesPerPixel;
int srcBytesPerRow;
int dstBytesPerRow;
int srcRowStrideBytes;
int dstRowStrideBytes;
int bytesPerRow;
int i;
if (!dstPacking)
if (!srcPacking)
{
if (srcPacking->rowLength > 0)
else
for (i=0; i<height; i++) {
dst += dstRowStrideBytes;
src += srcRowStrideBytes;
}
}
else
{
if (srcBytesPerPixel < 0 || dstBytesPerPixel < 0)
return;
/* Stride between rows (in bytes) */
if (srcPacking->rowLength > 0)
else
if (dstPacking->rowLength > 0)
else
/* bytes per row */
/* handle the alignment */
if (i)
if (i)
}
if (i)
if (i)
}
/* handle skip rows */
/* handle skip pixels */
/* we don't do LSBFirst yet */
if (srcPacking->psLSBFirst)
crError( "Sorry, no lsbfirst for you" );
if (dstPacking->psLSBFirst)
crError( "Sorry, no lsbfirst for you" );
{
{
}
else
//crDebug("Sending texture, BytesPerRow!=RowStrideBytes");
for (i = 0; i < height; i++)
{
#if 0
/* check if src XOR dst swapping */
if (size == 2) {
}
else if (size == 4) {
}
}
#endif
dst += dstRowStrideBytes;
src += srcRowStrideBytes;
}
}
else
{
crDebug("Converting texture format");
if (!tmpRow)
crError("Out of memory in crPixelCopy2D");
if (srcPacking->swapBytes) {
if (!swapRow) {
crError("Out of memory in crPixelCopy2D");
}
}
for (i = 0; i < height; i++)
{
/* get src row as floats */
if (srcPacking->swapBytes) {
if (size == 2)
else if (size == 4)
}
else {
}
/* store floats in dest row */
if (dstPacking->swapBytes) {
if (size == 2)
else if (size == 4)
}
else {
}
/* increment pointers for next row */
dst += dstRowStrideBytes;
src += srcRowStrideBytes;
}
if (swapRow)
}
}
}
const CRPixelPackState *dstPacking,
const CRPixelPackState *srcPacking )
{
int tex_size = 0;
(void)srcPacking;
(void)srcType;
(void)srcFormat;
(void)dstPacking;
/*@todo this should be implemented properly*/
crWarning( "crPixelCopy3D: simply crMemcpy'ing from srcPtr to dstPtr" );
crWarning( "crPixelCopy3D: formats don't match!" );
crWarning( "crPixelCopy3D: formats don't match!" );
}
/* Round N up to the next multiple of 8 */
{
srcPacking->skipRows == 0 &&
srcPacking->skipPixels == 0 &&
/* simple case */
}
else {
/* general case */
GLint i, j;
if (srcPacking->rowLength > 0)
else
switch (srcPacking->alignment) {
case 1:
break;
case 2:
break;
case 4:
break;
case 8:
break;
default:
crError( "Invalid unpack alignment in crBitmapCopy");
return;
}
/* src_row_length and dst_row_length are in bytes */
if (srcPacking->psLSBFirst) {
for (j = 0; j < height; j++) {
for (i = 0; i < width; i++) {
if (b & (1 << iBit))
}
srcRow += src_row_length;
dstRow += dst_row_length;
}
}
else {
/* unpack MSB first */
for (j = 0; j < height; j++) {
for (i = 0; i < width; i++) {
if (b & (128 >> iBit))
}
srcRow += src_row_length;
dstRow += dst_row_length;
}
}
}
}