note 87763 modified in function.imagesetpixel by danbrown

From: Date: Sat, 20 Dec 2008 17:18:27 +0000
Subject: note 87763 modified in function.imagesetpixel by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-148386@lists.php.net to get a copy of this message
Re: imagecreatefromtga() .. I just did some testing with what I think are valid Targa-24 and Targa-32 bit images, and modified the inner logic as follows: <?php if ($bytes_per_pixel == 2) // TARGA 16 - ARRRRRGG GGGBBBBB { $word = fileint($data, $pointer, 2); $r = ($word & 0x7C00) >> 7; $g = ($word & 0x03E0) >> 2; $b = ($word & 0x001F) << 3; $a = ($word & 0x8000) ? 127 : 0; $color = imagecolorallocatealpha($image, $r, $g, $b, $a); imagesetpixel($image, $x, $y, $color); } else if ($bytes_per_pixel == 3) // TARGA 24 - BBBBBBBB GGGGGGGG RRRRRRRR { $r = fileint($data, $pointer, 1); $b = fileint($data, $pointer+1, 1); $g = fileint($data, $pointer+2, 1); $color = imagecolorallocate($image, $r, $g, $b); imagesetpixel($image, $x, $y, $color); } else if ($bytes_per_pixel == 4) // TARGA 32 - BBBBBBBB GGGGGGGG RRRRRRRR AAAAAAAA { $b = fileint($data, $pointer, 1); $g = fileint($data, $pointer+1, 1); $r = fileint($data, $pointer+2, 1); $a = (255 - fileint($data, $pointer+3, 1)) >> 1; $color = imagecolorallocatealpha($image, $r, $g, $b, $a); imagesetpixel($image, $x, $y, $color); } ?> The red and blue tint issue seems to be fixed by this... --was-- Re: imagecreatefromtga() .. I just did some testing with what I think are valid Targa-24 and Targa-32 bit images, and modified the inner logic as follows: if ($bytes_per_pixel == 2) // TARGA 16 - ARRRRRGG GGGBBBBB { $word = fileint($data, $pointer, 2); $r = ($word & 0x7C00) >> 7; $g = ($word & 0x03E0) >> 2; $b = ($word & 0x001F) << 3; $a = ($word & 0x8000) ? 127 : 0; $color = imagecolorallocatealpha($image, $r, $g, $b, $a); imagesetpixel($image, $x, $y, $color); } else if ($bytes_per_pixel == 3) // TARGA 24 - BBBBBBBB GGGGGGGG RRRRRRRR { $r = fileint($data, $pointer, 1); $b = fileint($data, $pointer+1, 1); $g = fileint($data, $pointer+2, 1); $color = imagecolorallocate($image, $r, $g, $b); imagesetpixel($image, $x, $y, $color); } else if ($bytes_per_pixel == 4) // TARGA 32 - BBBBBBBB GGGGGGGG RRRRRRRR AAAAAAAA { $b = fileint($data, $pointer, 1); $g = fileint($data, $pointer+1, 1); $r = fileint($data, $pointer+2, 1); $a = (255 - fileint($data, $pointer+3, 1)) >> 1; $color = imagecolorallocatealpha($image, $r, $g, $b, $a); imagesetpixel($image, $x, $y, $color); } The red and blue tint issue seems to be fixed by this... http://php.net/manual/en/function.imagesetpixel.php

« previous php.notes (#148386) next »