5 unsigned char *
texTransform(
int &bpp,
int &color_type,
unsigned long &
width,
unsigned long &
height,
unsigned char **rp )
11 row_size = width*(bpp/8)*
sizeof (
unsigned char)*( (color_type&
PNG_HAS_ALPHA) ? 2 : 1 );
13 row_size = width*(bpp/8)*
sizeof (
unsigned char)*( (color_type&
PNG_HAS_ALPHA) ? 4 : 3 );
14 data = (
unsigned char*) malloc( row_size*height );
16 memcpy( data+
i*row_size, rp[
i], row_size );
24 unsigned char **row_pointers )
26 unsigned short *dat = (
unsigned short*) malloc(
sizeof (
unsigned short)*width*
height );
27 if ( (bpp == 8 && color_type
28 == PNG_COLOR_TYPE_RGB_ALPHA) || color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA ) {
29 if (bpp == 8 && color_type == PNG_COLOR_TYPE_GRAY) {
30 for (
unsigned int i = 0;
i <
height;
i++) {
31 unsigned long iwid =
i*
width;
32 for (
unsigned int j = 0;
j <
width;
j++)
33 dat[iwid+
j] = row_pointers[
i][
j];
36 if ( (bpp == 16 && color_type == PNG_COLOR_TYPE_GRAY) || (bpp == 8 && color_type == PNG_COLOR_TYPE_GRAY_ALPHA) ) {
38 memcpy( &dat[
i*width], row_pointers[
i],
sizeof (
unsigned short)*
width );
41 for (
unsigned int i = 0;
i <
height;
i++) {
42 unsigned long iwid =
i*
width;
43 for (
unsigned int j = 0;
j <
width;
j++)
44 dat[iwid+
j] = ( ( (
unsigned short*) row_pointers[
i] )[
j*2] );
49 if (color_type == PNG_COLOR_TYPE_RGB) {
50 unsigned int coloffset = (bpp == 8) ? 3 : 6;
51 for (
unsigned int i = 0;
i <
height;
i++) {
52 unsigned long iwid =
i*
width;
53 for (
unsigned int j = 0;
j <
width;
j++)
54 dat[iwid+
j] = *( (
unsigned short*) ( &(row_pointers[
i][
j*
coloffset]) ) );
56 }
else if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
58 for (
unsigned int i = 0;
i <
height;
i++) {
59 unsigned long iwid =
i*
width;
60 for (
unsigned int j = 0;
j <
width;
j++)
61 dat[iwid+
j] = ( ( (
unsigned short*) row_pointers[
i] )[
j*4] );
66 color_type = PNG_COLOR_TYPE_GRAY;
67 return (
unsigned char*) dat;
74 unsigned char **row_pointers )
76 unsigned char *dat = (
unsigned char*) malloc(
sizeof (
unsigned char)*width*
height );
77 if ( (bpp == 8 && color_type
78 == PNG_COLOR_TYPE_RGB_ALPHA) || color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA ) {
79 if (bpp == 8 && color_type == PNG_COLOR_TYPE_GRAY) {
81 memcpy( &dat[
i*width], row_pointers[
i],
sizeof (
unsigned char)*
width );
83 if ( (bpp == 16 && color_type == PNG_COLOR_TYPE_GRAY) || (bpp == 8 && color_type == PNG_COLOR_TYPE_GRAY_ALPHA) ) {
84 for (
unsigned int i = 0;
i <
height;
i++) {
85 unsigned long iwid =
i*
width;
86 for (
unsigned int j = 0;
j <
width;
j++)
87 dat[iwid+
j] = (row_pointers[
i])[
j*2];
91 for (
unsigned int i = 0;
i <
height;
i++) {
92 unsigned long iwid =
i*
width;
93 for (
unsigned int j = 0;
j <
width;
j++)
94 dat[iwid+
j] = ( (row_pointers[
i])[
j*4] );
99 if (color_type == PNG_COLOR_TYPE_RGB) {
100 unsigned int coloffset = (bpp == 8) ? 3 : 6;
101 for (
unsigned int i = 0;
i <
height;
i++) {
102 unsigned long iwid =
i*
width;
103 for (
unsigned int j = 0;
j <
width;
j++)
104 dat[iwid+
j] = *( (
unsigned char*) ( &(row_pointers[
i][
j*
coloffset]) ) );
106 }
else if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
108 for (
unsigned int i = 0;
i <
height;
i++) {
109 unsigned long iwid =
i*
width;
110 for (
unsigned int j = 0;
j <
width;
j++)
111 dat[iwid+
j] = ( ( (
unsigned short*) row_pointers[
i] )[
j*4] )/256;
116 color_type = PNG_COLOR_TYPE_GRAY;
118 return (
unsigned char*) dat;