Beispiel #1
0
function ReadIcon($filename, $id, &$Ikona)
{
    global $CurrentBit;
    $f = fopen($filename, "rb");
    fseek($f, 6 + $id * 16);
    $Width = freadbyte($f);
    $Height = freadbyte($f);
    fseek($f, 6 + $id * 16 + 12);
    $OffSet = freaddword($f);
    fseek($f, $OffSet);
    $p = $id;
    $Ikona[$p]["Info"]["HeaderSize"] = freadlngint($f);
    $Ikona[$p]["Info"]["ImageWidth"] = freadlngint($f);
    $Ikona[$p]["Info"]["ImageHeight"] = freadlngint($f);
    $Ikona[$p]["Info"]["NumberOfImagePlanes"] = freadword($f);
    $Ikona[$p]["Info"]["BitsPerPixel"] = freadword($f);
    $Ikona[$p]["Info"]["CompressionMethod"] = freadlngint($f);
    $Ikona[$p]["Info"]["SizeOfBitmap"] = freadlngint($f);
    $Ikona[$p]["Info"]["HorzResolution"] = freadlngint($f);
    $Ikona[$p]["Info"]["VertResolution"] = freadlngint($f);
    $Ikona[$p]["Info"]["NumColorUsed"] = freadlngint($f);
    $Ikona[$p]["Info"]["NumSignificantColors"] = freadlngint($f);
    $biBitCount = $Ikona[$p]["Info"]["BitsPerPixel"];
    if ($Ikona[$p]["Info"]["BitsPerPixel"] <= 8) {
        $barev = pow(2, $biBitCount);
        for ($b = 0; $b < $barev; $b++) {
            $Ikona[$p]["Paleta"][$b]["b"] = freadbyte($f);
            $Ikona[$p]["Paleta"][$b]["g"] = freadbyte($f);
            $Ikona[$p]["Paleta"][$b]["r"] = freadbyte($f);
            freadbyte($f);
        }
        $Zbytek = (4 - ceil($Width / (8 / $biBitCount)) % 4) % 4;
        for ($y = $Height - 1; $y >= 0; $y--) {
            $CurrentBit = 0;
            for ($x = 0; $x < $Width; $x++) {
                $C = freadbits($f, $biBitCount);
                $Ikona[$p]["Data"][$x][$y] = $C;
            }
            if ($CurrentBit != 0) {
                freadbyte($f);
            }
            for ($g = 0; $g < $Zbytek; $g++) {
                freadbyte($f);
            }
        }
    } elseif ($biBitCount == 24) {
        $Zbytek = $Width % 4;
        for ($y = $Height - 1; $y >= 0; $y--) {
            for ($x = 0; $x < $Width; $x++) {
                $B = freadbyte($f);
                $G = freadbyte($f);
                $R = freadbyte($f);
                $Ikona[$p]["Data"][$x][$y]["r"] = $R;
                $Ikona[$p]["Data"][$x][$y]["g"] = $G;
                $Ikona[$p]["Data"][$x][$y]["b"] = $B;
            }
            for ($z = 0; $z < $Zbytek; $z++) {
                freadbyte($f);
            }
        }
    } elseif ($biBitCount == 32) {
        $Zbytek = $Width % 4;
        for ($y = $Height - 1; $y >= 0; $y--) {
            for ($x = 0; $x < $Width; $x++) {
                $B = freadbyte($f);
                $G = freadbyte($f);
                $R = freadbyte($f);
                $Alpha = freadbyte($f);
                $Ikona[$p]["Data"][$x][$y]["r"] = $R;
                $Ikona[$p]["Data"][$x][$y]["g"] = $G;
                $Ikona[$p]["Data"][$x][$y]["b"] = $B;
                $Ikona[$p]["Data"][$x][$y]["alpha"] = $Alpha;
            }
            for ($z = 0; $z < $Zbytek; $z++) {
                freadbyte($f);
            }
        }
    }
    //Maska
    $Zbytek = (4 - ceil($Width / 8) % 4) % 4;
    for ($y = $Height - 1; $y >= 0; $y--) {
        $CurrentBit = 0;
        for ($x = 0; $x < $Width; $x++) {
            $C = freadbits($f, 1);
            $Ikona[$p]["Maska"][$x][$y] = $C;
        }
        if ($CurrentBit != 0) {
            freadbyte($f);
        }
        for ($g = 0; $g < $Zbytek; $g++) {
            freadbyte($f);
        }
    }
    //--------------
    fclose($f);
}
Beispiel #2
0
function imagecreatefromani($filename, $imageid)
{
    $Info = ReadAniInfo($filename);
    $f = fopen($filename, "r");
    fseek($f, $Info["Icon"][$imageid]);
    $IconSize = freaddword($f);
    $Reserved = freadword($f);
    $Type = freadword($f);
    $Count = freadword($f);
    $Ikona["Width"] = freadbyte($f);
    $Ikona["Height"] = freadbyte($f);
    $Ikona["ColorCount"] = freadword($f);
    if ($Ikona["ColorCount"] == 0) {
        $Ikona["ColorCount"] = 256;
    }
    $Ikona["Planes"] = freadword($f);
    $Ikona["BitCount"] = freadword($f);
    $Ikona["BytesInRes"] = freaddword($f);
    $Ikona["ImageOffset"] = freaddword($f);
    $Ikona["Info"]["HeaderSize"] = freadlngint($f);
    $Ikona["Info"]["ImageWidth"] = freadlngint($f);
    $Ikona["Info"]["ImageHeight"] = freadlngint($f);
    $Ikona["Info"]["NumberOfImagePlanes"] = freadword($f);
    $Ikona["Info"]["BitsPerPixel"] = freadword($f);
    $Ikona["Info"]["CompressionMethod"] = freadlngint($f);
    $Ikona["Info"]["SizeOfBitmap"] = freadlngint($f);
    $Ikona["Info"]["HorzResolution"] = freadlngint($f);
    $Ikona["Info"]["VertResolution"] = freadlngint($f);
    $Ikona["Info"]["NumColorUsed"] = freadlngint($f);
    $Ikona["Info"]["NumSignificantColors"] = freadlngint($f);
    $biBitCount = $Ikona["Info"]["BitsPerPixel"];
    $Width = $Ikona["Width"];
    $Height = $Ikona["Height"];
    $img = imagecreatetruecolor($Ikona["Width"], $Ikona["Height"]);
    if ($biBitCount <= 8) {
        $barev = pow(2, $biBitCount);
        for ($b = 0; $b < $barev; $b++) {
            $B = freadbyte($f);
            $G = freadbyte($f);
            $R = freadbyte($f);
            $Palette[] = imagecolorallocate($img, $R, $G, $B);
            freadbyte($f);
        }
        $Zbytek = (4 - ceil($Width / (8 / $biBitCount)) % 4) % 4;
        for ($y = $Height - 1; $y >= 0; $y--) {
            $CurrentBit = 0;
            for ($x = 0; $x < $Width; $x++) {
                $C = freadbits($f, $biBitCount);
                imagesetpixel($img, $x, $y, $Palette[$C]);
            }
            if ($CurrentBit != 0) {
                freadbyte($f);
            }
            for ($g = 0; $g < $Zbytek; $g++) {
                freadbyte($f);
            }
        }
    } elseif ($biBitCount == 24) {
        $Zbytek = $Width % 4;
        for ($y = $Height - 1; $y >= 0; $y--) {
            for ($x = 0; $x < $Width; $x++) {
                $B = freadbyte($f);
                $G = freadbyte($f);
                $R = freadbyte($f);
                $color = imagecolorexact($img, $R, $G, $B);
                if ($color == -1) {
                    $color = imagecolorallocate($img, $R, $G, $B);
                }
                imagesetpixel($img, $x, $y, $color);
            }
            for ($z = 0; $z < $Zbytek; $z++) {
                freadbyte($f);
            }
        }
    } elseif ($biBitCount == 32) {
        $Zbytek = $Width % 4;
        for ($y = $Height - 1; $y >= 0; $y--) {
            for ($x = 0; $x < $Width; $x++) {
                $B = freadbyte($f);
                $G = freadbyte($f);
                $R = freadbyte($f);
                $Alpha = freadbyte($f);
                $color = imagecolorexactalpha($img, $R, $G, $B, $Alpha);
                if ($color == -1) {
                    $color = imagecolorallocatealpha($img, $R, $G, $B, $Alpha);
                }
                imagesetpixel($img, $x, $y, $color);
            }
            for ($z = 0; $z < $Zbytek; $z++) {
                freadbyte($f);
            }
        }
    }
    //Maska
    $Zbytek = (4 - ceil($Width / 8) % 4) % 4;
    for ($y = $Height - 1; $y >= 0; $y--) {
        $CurrentBit = 0;
        for ($x = 0; $x < $Width; $x++) {
            $C = freadbits($f, 1);
            if ($C == 1) {
                if (!$IsTransparent) {
                    if ($biBitCount >= 24 or imagecolorstotal($img) >= 256 or imagecolorstotal($img) == 0) {
                        $img2 = imagecreatetruecolor(imagesx($img), imagesy($img));
                        imagecopy($img2, $img, 0, 0, 0, 0, imagesx($img), imagesy($img));
                        imagedestroy($img);
                        $img = $img2;
                        imagetruecolortopalette($img, true, 255);
                    }
                    $Pruhledna = imagecolorallocate($img, 0, 0, 0);
                }
                $IsTransparent = true;
                imagesetpixel($img, $x, $y, $Pruhledna);
            }
        }
        if ($CurrentBit != 0) {
            freadbyte($f);
        }
        for ($g = 0; $g < $Zbytek; $g++) {
            freadbyte($f);
        }
    }
    if ($IsTransparent) {
        imagecolortransparent($img, $Pruhledna);
    }
    fclose($f);
    return $img;
}