Guest User

Untitled

a guest
Jan 19th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.94 KB | None | 0 0
  1. public class InitActivity extends Activity {
  2. Application APP = new Application();
  3. private GifView gifView;
  4.  
  5. @Override
  6. public void onCreate(Bundle savedInstanceState) {
  7. setFullScreen();
  8. super.onCreate(savedInstanceState);
  9. setContentView(R.layout.layout_activity_init);
  10. gifView = (GifView) findViewById(R.id.app_init_preloaderHolder);
  11. gifView.setGif(R.drawable.p);
  12. gifView.play();
  13.  
  14.  
  15. }
  16.  
  17. public void setFullScreen(){
  18. requestWindowFeature(Window.FEATURE_NO_TITLE);
  19. getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
  20. }
  21.  
  22.  
  23.  
  24.  
  25. }
  26.  
  27. public static final int IMAGE_TYPE_UNKNOWN = 0;
  28. public static final int IMAGE_TYPE_STATIC = 1;
  29. public static final int IMAGE_TYPE_DYNAMIC = 2;
  30.  
  31. public static final int DECODE_STATUS_UNDECODE = 0;
  32. public static final int DECODE_STATUS_DECODING = 1;
  33. public static final int DECODE_STATUS_DECODED = 2;
  34.  
  35. private GifDecoder decoder;
  36. private Bitmap bitmap;
  37.  
  38. public int imageType = IMAGE_TYPE_UNKNOWN;
  39. public int decodeStatus = DECODE_STATUS_UNDECODE;
  40.  
  41. private int width;
  42. private int height;
  43.  
  44. private long time;
  45. private int index;
  46.  
  47. private int resId;
  48. private String filePath;
  49.  
  50. private boolean playFlag = false;
  51.  
  52. public GifView(Context context, AttributeSet attrs) {
  53. super(context, attrs);
  54. }
  55.  
  56. /**
  57. * Constructor
  58. */
  59. public GifView(Context context) {
  60. super(context);
  61. }
  62.  
  63. private InputStream getInputStream() {
  64. if (filePath != null)
  65. try {
  66. return new FileInputStream(filePath);
  67. } catch (FileNotFoundException e) {
  68. }
  69. if (resId > 0)
  70. return getContext().getResources().openRawResource(resId);
  71. return null;
  72. }
  73.  
  74. /**
  75. * set gif file path
  76. *
  77. * @param filePath
  78. */
  79. public void setGif(String filePath) {
  80. Bitmap bitmap = BitmapFactory.decodeFile(filePath);
  81. setGif(filePath, bitmap);
  82. }
  83.  
  84. /**
  85. * set gif file path and cache image
  86. *
  87. * @param filePath
  88. * @param cacheImage
  89. */
  90. public void setGif(String filePath, Bitmap cacheImage) {
  91. this.resId = 0;
  92. this.filePath = filePath;
  93. imageType = IMAGE_TYPE_UNKNOWN;
  94. decodeStatus = DECODE_STATUS_UNDECODE;
  95. playFlag = false;
  96. bitmap = cacheImage;
  97. width = bitmap.getWidth();
  98. height = bitmap.getHeight();
  99. setLayoutParams(new LayoutParams(width, height));
  100. }
  101.  
  102. /**
  103. * set gif resource id
  104. *
  105. * @param resId
  106. */
  107. public void setGif(int resId) {
  108. Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resId);
  109. setGif(resId, bitmap);
  110. }
  111.  
  112. /**
  113. * set gif resource id and cache image
  114. *
  115. * @param resId
  116. * @param cacheImage
  117. */
  118. public void setGif(int resId, Bitmap cacheImage) {
  119. this.filePath = null;
  120. this.resId = resId;
  121. imageType = IMAGE_TYPE_UNKNOWN;
  122. decodeStatus = DECODE_STATUS_UNDECODE;
  123. playFlag = false;
  124. bitmap = cacheImage;
  125. width = bitmap.getWidth();
  126. height = bitmap.getHeight();
  127. setLayoutParams(new LayoutParams(width, height));
  128. }
  129.  
  130. private void decode() {
  131. release();
  132. index = 0;
  133.  
  134. decodeStatus = DECODE_STATUS_DECODING;
  135.  
  136. new Thread() {
  137. @Override
  138. public void run() {
  139. decoder = new GifDecoder();
  140. decoder.read(getInputStream());
  141. if (decoder.width == 0 || decoder.height == 0) {
  142. imageType = IMAGE_TYPE_STATIC;
  143. } else {
  144. imageType = IMAGE_TYPE_DYNAMIC;
  145. }
  146. postInvalidate();
  147. time = System.currentTimeMillis();
  148. decodeStatus = DECODE_STATUS_DECODED;
  149. }
  150. }.start();
  151. }
  152.  
  153. public void release() {
  154. decoder = null;
  155. }
  156.  
  157. @Override
  158. protected void onDraw(Canvas canvas) {
  159. super.onDraw(canvas);
  160.  
  161. if (decodeStatus == DECODE_STATUS_UNDECODE) {
  162. canvas.drawBitmap(bitmap, 0, 0, null);
  163. if (playFlag) {
  164. decode();
  165. invalidate();
  166. }
  167. } else if (decodeStatus == DECODE_STATUS_DECODING) {
  168. canvas.drawBitmap(bitmap, 0, 0, null);
  169. invalidate();
  170. } else if (decodeStatus == DECODE_STATUS_DECODED) {
  171. if (imageType == IMAGE_TYPE_STATIC) {
  172. canvas.drawBitmap(bitmap, 0, 0, null);
  173. } else if (imageType == IMAGE_TYPE_DYNAMIC) {
  174. if (playFlag) {
  175. long now = System.currentTimeMillis();
  176.  
  177. if (time + decoder.getDelay(index) < now) {
  178. time += decoder.getDelay(index);
  179. incrementFrameIndex();
  180. }
  181. Bitmap bitmap = decoder.getFrame(index);
  182. if (bitmap != null) {
  183. canvas.drawBitmap(bitmap, 0, 0, null);
  184. }
  185. invalidate();
  186. } else {
  187. Bitmap bitmap = decoder.getFrame(index);
  188. canvas.drawBitmap(bitmap, 0, 0, null);
  189. }
  190. } else {
  191. canvas.drawBitmap(bitmap, 0, 0, null);
  192. }
  193. }
  194. }
  195.  
  196. private void incrementFrameIndex() {
  197. index++;
  198. if (index >= decoder.getFrameCount()) {
  199. index = 0;
  200. }
  201. }
  202.  
  203. private void decrementFrameIndex() {
  204. index--;
  205. if (index < 0) {
  206. index = decoder.getFrameCount() - 1;
  207. }
  208. }
  209.  
  210. public void play() {
  211. time = System.currentTimeMillis();
  212. playFlag = true;
  213. invalidate();
  214. }
  215.  
  216. public void pause() {
  217. playFlag = false;
  218. invalidate();
  219. }
  220.  
  221. public void stop() {
  222. playFlag = false;
  223. index = 0;
  224. invalidate();
  225. }
  226.  
  227. public void nextFrame() {
  228. if (decodeStatus == DECODE_STATUS_DECODED) {
  229. incrementFrameIndex();
  230. invalidate();
  231. }
  232. }
  233.  
  234. public void prevFrame() {
  235. if (decodeStatus == DECODE_STATUS_DECODED) {
  236. decrementFrameIndex();
  237. invalidate();
  238. }
  239. }
  240.  
  241. public class GifDecoder {
  242. /**
  243. * File read status: No errors.
  244. */
  245. public static final int STATUS_OK = 0;
  246. /**
  247. * File read status: Error decoding file (may be partially decoded)
  248. */
  249. public static final int STATUS_FORMAT_ERROR = 1;
  250. /**
  251. * File read status: Unable to open source.
  252. */
  253. public static final int STATUS_OPEN_ERROR = 2;
  254. /** max decoder pixel stack size */
  255. protected static final int MAX_STACK_SIZE = 4096;
  256. protected InputStream in;
  257. protected int status;
  258. protected int width; // full image width
  259. protected int height; // full image height
  260. protected boolean gctFlag; // global color table used
  261. protected int gctSize; // size of global color table
  262. protected int loopCount = 1; // iterations; 0 = repeat forever
  263. protected int[] gct; // global color table
  264. protected int[] lct; // local color table
  265. protected int[] act; // active color table
  266. protected int bgIndex; // background color index
  267. protected int bgColor; // background color
  268. protected int lastBgColor; // previous bg color
  269. protected int pixelAspect; // pixel aspect ratio
  270. protected boolean lctFlag; // local color table flag
  271. protected boolean interlace; // interlace flag
  272. protected int lctSize; // local color table size
  273. protected int ix, iy, iw, ih; // current image rectangle
  274. protected int lrx, lry, lrw, lrh;
  275. protected Bitmap image; // current frame
  276. protected Bitmap lastBitmap; // previous frame
  277. protected byte[] block = new byte[256]; // current data block
  278. protected int blockSize = 0; // block size last graphic control extension info
  279. protected int dispose = 0; // 0=no action; 1=leave in place; 2=restore to bg; 3=restore to prev
  280. protected int lastDispose = 0;
  281. protected boolean transparency = false; // use transparent color
  282. protected int delay = 0; // delay in milliseconds
  283. protected int transIndex; // transparent color index
  284. // LZW decoder working arrays
  285. protected short[] prefix;
  286. protected byte[] suffix;
  287. protected byte[] pixelStack;
  288. protected byte[] pixels;
  289. protected Vector<GifFrame> frames; // frames read from current file
  290. protected int frameCount;
  291.  
  292. private static class GifFrame {
  293. public GifFrame(Bitmap im, int del) {
  294. image = im;
  295. delay = del;
  296. }
  297.  
  298. public Bitmap image;
  299. public int delay;
  300. }
  301.  
  302. /**
  303. * Gets display duration for specified frame.
  304. *
  305. * @param n
  306. * int index of frame
  307. * @return delay in milliseconds
  308. */
  309. public int getDelay(int n) {
  310. delay = -1;
  311. if ((n >= 0) && (n < frameCount)) {
  312. delay = frames.elementAt(n).delay;
  313. }
  314. return delay;
  315. }
  316.  
  317. /**
  318. * Gets the number of frames read from file.
  319. *
  320. * @return frame count
  321. */
  322. public int getFrameCount() {
  323. return frameCount;
  324. }
  325.  
  326. /**
  327. * Gets the first (or only) image read.
  328. *
  329. * @return BufferedBitmap containing first frame, or null if none.
  330. */
  331. public Bitmap getBitmap() {
  332. return getFrame(0);
  333. }
  334.  
  335. /**
  336. * Gets the "Netscape" iteration count, if any. A count of 0 means repeat indefinitiely.
  337. *
  338. * @return iteration count if one was specified, else 1.
  339. */
  340. public int getLoopCount() {
  341. return loopCount;
  342. }
  343.  
  344. /**
  345. * Creates new frame image from current data (and previous frames as specified by their disposition codes).
  346. */
  347. protected void setPixels() {
  348. // expose destination image's pixels as int array
  349. int[] dest = new int[width * height];
  350. // fill in starting image contents based on last image's dispose code
  351. if (lastDispose > 0) {
  352. if (lastDispose == 3) {
  353. // use image before last
  354. int n = frameCount - 2;
  355. if (n > 0) {
  356. lastBitmap = getFrame(n - 1);
  357. } else {
  358. lastBitmap = null;
  359. }
  360. }
  361. if (lastBitmap != null) {
  362. lastBitmap.getPixels(dest, 0, width, 0, 0, width, height);
  363. // copy pixels
  364. if (lastDispose == 2) {
  365. // fill last image rect area with background color
  366. int c = 0;
  367. if (!transparency) {
  368. c = lastBgColor;
  369. }
  370. for (int i = 0; i < lrh; i++) {
  371. int n1 = (lry + i) * width + lrx;
  372. int n2 = n1 + lrw;
  373. for (int k = n1; k < n2; k++) {
  374. dest[k] = c;
  375. }
  376. }
  377. }
  378. }
  379. }
  380. // copy each source line to the appropriate place in the destination
  381. int pass = 1;
  382. int inc = 8;
  383. int iline = 0;
  384. for (int i = 0; i < ih; i++) {
  385. int line = i;
  386. if (interlace) {
  387. if (iline >= ih) {
  388. pass++;
  389. switch (pass) {
  390. case 2:
  391. iline = 4;
  392. break;
  393. case 3:
  394. iline = 2;
  395. inc = 4;
  396. break;
  397. case 4:
  398. iline = 1;
  399. inc = 2;
  400. break;
  401. default:
  402. break;
  403. }
  404. }
  405. line = iline;
  406. iline += inc;
  407. }
  408. line += iy;
  409. if (line < height) {
  410. int k = line * width;
  411. int dx = k + ix; // start of line in dest
  412. int dlim = dx + iw; // end of dest line
  413. if ((k + width) < dlim) {
  414. dlim = k + width; // past dest edge
  415. }
  416. int sx = i * iw; // start of line in source
  417. while (dx < dlim) {
  418. // map color and insert in destination
  419. int index = ((int) pixels[sx++]) & 0xff;
  420. int c = act[index];
  421. if (c != 0) {
  422. dest[dx] = c;
  423. }
  424. dx++;
  425. }
  426. }
  427. }
  428.  
  429. image = Bitmap.createBitmap(dest, width, height, Config.ARGB_8888);
  430. }
  431.  
  432. /**
  433. * Gets the image contents of frame n.
  434. *
  435. * @return BufferedBitmap representation of frame, or null if n is invalid.
  436. */
  437. public Bitmap getFrame(int n) {
  438. if (frameCount <= 0)
  439. return null;
  440. n = n % frameCount;
  441. return ((GifFrame) frames.elementAt(n)).image;
  442. }
  443.  
  444. /**
  445. * Reads GIF image from stream
  446. *
  447. * @param is
  448. * containing GIF file.
  449. * @return read status code (0 = no errors)
  450. */
  451. public int read(InputStream is) {
  452. init();
  453. if (is != null) {
  454. in = is;
  455. readHeader();
  456. if (!err()) {
  457. readContents();
  458. if (frameCount < 0) {
  459. status = STATUS_FORMAT_ERROR;
  460. }
  461. }
  462. } else {
  463. status = STATUS_OPEN_ERROR;
  464. }
  465. try {
  466. is.close();
  467. } catch (Exception e) {
  468. }
  469. return status;
  470. }
  471.  
  472. /**
  473. * Decodes LZW image data into pixel array. Adapted from John Cristy's BitmapMagick.
  474. */
  475. protected void decodeBitmapData() {
  476. int nullCode = -1;
  477. int npix = iw * ih;
  478. int available, clear, code_mask, code_size, end_of_information, in_code, old_code, bits, code, count, i, datum, data_size, first, top, bi, pi;
  479. if ((pixels == null) || (pixels.length < npix)) {
  480. pixels = new byte[npix]; // allocate new pixel array
  481. }
  482. if (prefix == null) {
  483. prefix = new short[MAX_STACK_SIZE];
  484. }
  485. if (suffix == null) {
  486. suffix = new byte[MAX_STACK_SIZE];
  487. }
  488. if (pixelStack == null) {
  489. pixelStack = new byte[MAX_STACK_SIZE + 1];
  490. }
  491. // Initialize GIF data stream decoder.
  492. data_size = read();
  493. clear = 1 << data_size;
  494. end_of_information = clear + 1;
  495. available = clear + 2;
  496. old_code = nullCode;
  497. code_size = data_size + 1;
  498. code_mask = (1 << code_size) - 1;
  499. for (code = 0; code < clear; code++) {
  500. prefix[code] = 0; // XXX ArrayIndexOutOfBoundsException
  501. suffix[code] = (byte) code;
  502. }
  503. // Decode GIF pixel stream.
  504. datum = bits = count = first = top = pi = bi = 0;
  505. for (i = 0; i < npix;) {
  506. if (top == 0) {
  507. if (bits < code_size) {
  508. // Load bytes until there are enough bits for a code.
  509. if (count == 0) {
  510. // Read a new data block.
  511. count = readBlock();
  512. if (count <= 0) {
  513. break;
  514. }
  515. bi = 0;
  516. }
  517. datum += (((int) block[bi]) & 0xff) << bits;
  518. bits += 8;
  519. bi++;
  520. count--;
  521. continue;
  522. }
  523. // Get the next code.
  524. code = datum & code_mask;
  525. datum >>= code_size;
  526. bits -= code_size;
  527. // Interpret the code
  528. if ((code > available) || (code == end_of_information)) {
  529. break;
  530. }
  531. if (code == clear) {
  532. // Reset decoder.
  533. code_size = data_size + 1;
  534. code_mask = (1 << code_size) - 1;
  535. available = clear + 2;
  536. old_code = nullCode;
  537. continue;
  538. }
  539. if (old_code == nullCode) {
  540. pixelStack[top++] = suffix[code];
  541. old_code = code;
  542. first = code;
  543. continue;
  544. }
  545. in_code = code;
  546. if (code == available) {
  547. pixelStack[top++] = (byte) first;
  548. code = old_code;
  549. }
  550. while (code > clear) {
  551. pixelStack[top++] = suffix[code];
  552. code = prefix[code];
  553. }
  554. first = ((int) suffix[code]) & 0xff;
  555. // Add a new string to the string table,
  556. if (available >= MAX_STACK_SIZE) {
  557. break;
  558. }
  559. pixelStack[top++] = (byte) first;
  560. prefix[available] = (short) old_code;
  561. suffix[available] = (byte) first;
  562. available++;
  563. if (((available & code_mask) == 0) && (available < MAX_STACK_SIZE)) {
  564. code_size++;
  565. code_mask += available;
  566. }
  567. old_code = in_code;
  568. }
  569. // Pop a pixel off the pixel stack.
  570. top--;
  571. pixels[pi++] = pixelStack[top];
  572. i++;
  573. }
  574. for (i = pi; i < npix; i++) {
  575. pixels[i] = 0; // clear missing pixels
  576. }
  577. }
  578.  
  579. /**
  580. * Returns true if an error was encountered during reading/decoding
  581. */
  582. protected boolean err() {
  583. return status != STATUS_OK;
  584. }
  585.  
  586. /**
  587. * Initializes or re-initializes reader
  588. */
  589. protected void init() {
  590. status = STATUS_OK;
  591. frameCount = 0;
  592. frames = new Vector<GifFrame>();
  593. gct = null;
  594. lct = null;
  595. }
  596.  
  597. /**
  598. * Reads a single byte from the input stream.
  599. */
  600. protected int read() {
  601. int curByte = 0;
  602. try {
  603. curByte = in.read();
  604. } catch (Exception e) {
  605. status = STATUS_FORMAT_ERROR;
  606. }
  607. return curByte;
  608. }
  609.  
  610. /**
  611. * Reads next variable length block from input.
  612. *
  613. * @return number of bytes stored in "buffer"
  614. */
  615. protected int readBlock() {
  616. blockSize = read();
  617. int n = 0;
  618. if (blockSize > 0) {
  619. try {
  620. int count = 0;
  621. while (n < blockSize) {
  622. count = in.read(block, n, blockSize - n);
  623. if (count == -1) {
  624. break;
  625. }
  626. n += count;
  627. }
  628. } catch (Exception e) {
  629. e.printStackTrace();
  630. }
  631. if (n < blockSize) {
  632. status = STATUS_FORMAT_ERROR;
  633. }
  634. }
  635. return n;
  636. }
  637.  
  638. /**
  639. * Reads color table as 256 RGB integer values
  640. *
  641. * @param ncolors
  642. * int number of colors to read
  643. * @return int array containing 256 colors (packed ARGB with full alpha)
  644. */
  645. protected int[] readColorTable(int ncolors) {
  646. int nbytes = 3 * ncolors;
  647. int[] tab = null;
  648. byte[] c = new byte[nbytes];
  649. int n = 0;
  650. try {
  651. n = in.read(c);
  652. } catch (Exception e) {
  653. e.printStackTrace();
  654. }
  655. if (n < nbytes) {
  656. status = STATUS_FORMAT_ERROR;
  657. } else {
  658. tab = new int[256]; // max size to avoid bounds checks
  659. int i = 0;
  660. int j = 0;
  661. while (i < ncolors) {
  662. int r = ((int) c[j++]) & 0xff;
  663. int g = ((int) c[j++]) & 0xff;
  664. int b = ((int) c[j++]) & 0xff;
  665. tab[i++] = 0xff000000 | (r << 16) | (g << 8) | b;
  666. }
  667. }
  668. return tab;
  669. }
  670.  
  671. /**
  672. * Main file parser. Reads GIF content blocks.
  673. */
  674. protected void readContents() {
  675. // read GIF file content blocks
  676. boolean done = false;
  677. while (!(done || err())) {
  678. int code = read();
  679. switch (code) {
  680. case 0x2C: // image separator
  681. readBitmap();
  682. break;
  683. case 0x21: // extension
  684. code = read();
  685. switch (code) {
  686. case 0xf9: // graphics control extension
  687. readGraphicControlExt();
  688. break;
  689. case 0xff: // application extension
  690. readBlock();
  691. String app = "";
  692. for (int i = 0; i < 11; i++) {
  693. app += (char) block[i];
  694. }
  695. if (app.equals("NETSCAPE2.0")) {
  696. readNetscapeExt();
  697. } else {
  698. skip(); // don't care
  699. }
  700. break;
  701. case 0xfe:// comment extension
  702. skip();
  703. break;
  704. case 0x01:// plain text extension
  705. skip();
  706. break;
  707. default: // uninteresting extension
  708. skip();
  709. }
  710. break;
  711. case 0x3b: // terminator
  712. done = true;
  713. break;
  714. case 0x00: // bad byte, but keep going and see what happens break;
  715. default:
  716. status = STATUS_FORMAT_ERROR;
  717. }
  718. }
  719. }
  720.  
  721. /**
  722. * Reads Graphics Control Extension values
  723. */
  724. protected void readGraphicControlExt() {
  725. read(); // block size
  726. int packed = read(); // packed fields
  727. dispose = (packed & 0x1c) >> 2; // disposal method
  728. if (dispose == 0) {
  729. dispose = 1; // elect to keep old image if discretionary
  730. }
  731. transparency = (packed & 1) != 0;
  732. delay = readShort() * 10; // delay in milliseconds
  733. transIndex = read(); // transparent color index
  734. read(); // block terminator
  735. }
  736.  
  737. /**
  738. * Reads GIF file header information.
  739. */
  740. protected void readHeader() {
  741. String id = "";
  742. for (int i = 0; i < 6; i++) {
  743. id += (char) read();
  744. }
  745. if (!id.startsWith("GIF")) {
  746. status = STATUS_FORMAT_ERROR;
  747. return;
  748. }
  749. readLSD();
  750. if (gctFlag && !err()) {
  751. gct = readColorTable(gctSize);
  752. bgColor = gct[bgIndex];
  753. }
  754. }
  755.  
  756. /**
  757. * Reads next frame image
  758. */
  759. protected void readBitmap() {
  760. ix = readShort(); // (sub)image position & size
  761. iy = readShort();
  762. iw = readShort();
  763. ih = readShort();
  764. int packed = read();
  765. lctFlag = (packed & 0x80) != 0; // 1 - local color table flag interlace
  766. lctSize = (int) Math.pow(2, (packed & 0x07) + 1);
  767. // 3 - sort flag
  768. // 4-5 - reserved lctSize = 2 << (packed & 7); // 6-8 - local color
  769. // table size
  770. interlace = (packed & 0x40) != 0;
  771. if (lctFlag) {
  772. lct = readColorTable(lctSize); // read table
  773. act = lct; // make local table active
  774. } else {
  775. act = gct; // make global table active
  776. if (bgIndex == transIndex) {
  777. bgColor = 0;
  778. }
  779. }
  780. int save = 0;
  781. if (transparency) {
  782. save = act[transIndex];
  783. act[transIndex] = 0; // set transparent color if specified
  784. }
  785. if (act == null) {
  786. status = STATUS_FORMAT_ERROR; // no color table defined
  787. }
  788. if (err()) {
  789. return;
  790. }
  791. decodeBitmapData(); // decode pixel data
  792. skip();
  793. if (err()) {
  794. return;
  795. }
  796. frameCount++;
  797. // create new image to receive frame data
  798. image = Bitmap.createBitmap(width, height, Config.ARGB_8888);
  799. setPixels(); // transfer pixel data to image
  800. frames.addElement(new GifFrame(image, delay)); // add image to frame
  801. // list
  802. if (transparency) {
  803. act[transIndex] = save;
  804. }
  805. resetFrame();
  806. }
  807.  
  808. /**
  809. * Reads Logical Screen Descriptor
  810. */
  811. protected void readLSD() {
  812. // logical screen size
  813. width = readShort();
  814. height = readShort();
  815. // packed fields
  816. int packed = read();
  817. gctFlag = (packed & 0x80) != 0; // 1 : global color table flag
  818. // 2-4 : color resolution
  819. // 5 : gct sort flag
  820. gctSize = 2 << (packed & 7); // 6-8 : gct size
  821. bgIndex = read(); // background color index
  822. pixelAspect = read(); // pixel aspect ratio
  823. }
  824.  
  825. /**
  826. * Reads Netscape extenstion to obtain iteration count
  827. */
  828. protected void readNetscapeExt() {
  829. do {
  830. readBlock();
  831. if (block[0] == 1) {
  832. // loop count sub-block
  833. int b1 = ((int) block[1]) & 0xff;
  834. int b2 = ((int) block[2]) & 0xff;
  835. loopCount = (b2 << 8) | b1;
  836. }
  837. } while ((blockSize > 0) && !err());
  838. }
  839.  
  840. /**
  841. * Reads next 16-bit value, LSB first
  842. */
  843. protected int readShort() {
  844. // read 16-bit value, LSB first
  845. return read() | (read() << 8);
  846. }
  847.  
  848. /**
  849. * Resets frame state for reading next image.
  850. */
  851. protected void resetFrame() {
  852. lastDispose = dispose;
  853. lrx = ix;
  854. lry = iy;
  855. lrw = iw;
  856. lrh = ih;
  857. lastBitmap = image;
  858. lastBgColor = bgColor;
  859. dispose = 0;
  860. transparency = false;
  861. delay = 0;
  862. lct = null;
  863. }
  864.  
  865. /**
  866. * Skips variable length blocks up to and including next zero length block.
  867. */
  868. protected void skip() {
  869. do {
  870. readBlock();
  871. } while ((blockSize > 0) && !err());
  872. }
  873. }
Add Comment
Please, Sign In to add comment