Subversion Repositories oidplus

Rev

Rev 1124 | Rev 1271 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1124 Rev 1130
Line 22... Line 22...
22
// phpcs:disable PSR1.Files.SideEffects
22
// phpcs:disable PSR1.Files.SideEffects
23
\defined('INSIDE_OIDPLUS') or die;
23
\defined('INSIDE_OIDPLUS') or die;
24
// phpcs:enable PSR1.Files.SideEffects
24
// phpcs:enable PSR1.Files.SideEffects
25
 
25
 
26
class OIDplusFourCC extends OIDplusObject {
26
class OIDplusFourCC extends OIDplusObject {
-
 
27
        /**
-
 
28
         * @var string
-
 
29
         */
27
        private $fourcc;
30
        private $fourcc;
28
 
31
 
29
        /**
32
        /**
30
         * FourCC Syntax examples:
33
         * FourCC Syntax examples:
31
         * fourcc_transform('8BIM')       === array(56,66,73,77);   // Adobe Photoshop
34
         * fourcc_transform('8BIM')       === array(56,66,73,77);   // Adobe Photoshop
Line 55... Line 58...
55
                if ($fourcc !== '') return false;
58
                if ($fourcc !== '') return false;
56
                return $out;
59
                return $out;
57
        }
60
        }
58
 
61
 
59
        /**
62
        /**
60
         * @param $fourcc
63
         * @param string $fourcc
61
         */
64
         */
62
        public function __construct($fourcc) {
65
        public function __construct(string $fourcc) {
63
                if (self::fourcc_transform($fourcc) !== false) {
66
                if (self::fourcc_transform($fourcc) !== false) {
64
                        $this->fourcc = $fourcc; // leaf node
67
                        $this->fourcc = $fourcc; // leaf node
65
                } else {
68
                } else {
66
                        $this->fourcc = $fourcc; // It is a category name
69
                        $this->fourcc = $fourcc; // It is a category name
67
                }
70
                }
Line 268... Line 271...
268
                // A FourCC is a FourCC, there is no hierarchy
271
                // A FourCC is a FourCC, there is no hierarchy
269
                return null;
272
                return null;
270
        }
273
        }
271
 
274
 
272
        /**
275
        /**
273
         * @param $to
276
         * @param OIDplusObject|string $to
274
         * @return null
277
         * @return int|null
275
         */
278
         */
276
        public function distance($to) {
279
        public function distance($to) {
277
                // Distance between FourCCs is not possible
280
                // Distance between FourCCs is not possible
278
                return null;
281
                return null;
279
        }
282
        }
Line 283... Line 286...
283
         * @throws OIDplusException
286
         * @throws OIDplusException
284
         */
287
         */
285
        public function getAltIds(): array {
288
        public function getAltIds(): array {
286
                if ($this->isRoot()) return array();
289
                if ($this->isRoot()) return array();
287
                if (!$this->isLeafNode()) return array();
290
                if (!$this->isLeafNode()) return array();
288
                $ids = parent::getAltIds();
291
                return parent::getAltIds();
289
                return $ids;
-
 
290
        }
292
        }
291
 
293
 
292
        /**
294
        /**
293
         * @param $big_endian
295
         * @param bool $big_endian
294
         * @return false|int|mixed
296
         * @return false|int
295
         */
297
         */
296
        private function getInt($big_endian) {
298
        private function getInt(bool $big_endian) {
297
                $type = self::fourcc_transform($this->fourcc);
299
                $type = self::fourcc_transform($this->fourcc);
298
                if ($type === false) return false;
300
                if ($type === false) return false;
299
                $dec = 0;
301
                $dec = 0;
300
                if (!$big_endian) $type = array_reverse($type);
302
                if (!$big_endian) $type = array_reverse($type);
301
                for ($i=0;$i<4;$i++) $dec = ($dec<<8) + $type[$i];
303
                for ($i=0;$i<4;$i++) $dec = ($dec<<8) + $type[$i];
302
                return $dec;
304
                return $dec;
303
        }
305
        }
304
 
306
 
305
        /**
307
        /**
306
         * @param $big_endian
308
         * @param bool $big_endian
307
         * @return string
309
         * @return string
308
         */
310
         */
309
        private function getHex($big_endian) {
311
        private function getHex(bool $big_endian): string {
310
                $dec = $this->getInt($big_endian);
312
                $dec = $this->getInt($big_endian);
311
                $hex = str_pad(dechex($dec), 8, "0", STR_PAD_LEFT);
313
                return str_pad(dechex($dec), 8, "0", STR_PAD_LEFT);
312
                return $hex;
-
 
313
        }
314
        }
314
 
315
 
315
        /**
316
        /**
316
         * @return false|string
317
         * @return false|string
317
         */
318
         */