You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ManagedPixelBuffer.java 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. * Copyright 2016-2019 Brian P. Hinz
  3. *
  4. * This is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This software is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this software; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
  17. * USA.
  18. */
  19. package com.tigervnc.rfb;
  20. import java.awt.image.*;
  21. public class ManagedPixelBuffer extends FullFramePixelBuffer {
  22. public ManagedPixelBuffer() {
  23. datasize = 0;
  24. checkDataSize();
  25. }
  26. public ManagedPixelBuffer(PixelFormat pf, int w, int h)
  27. {
  28. super(pf, w, h, null);
  29. datasize = 0;
  30. checkDataSize();
  31. }
  32. public void setPF(PixelFormat pf) {
  33. format = pf; checkDataSize();
  34. }
  35. public void setSize(int w, int h) {
  36. width_ = w; height_ = h; checkDataSize();
  37. }
  38. final void checkDataSize() {
  39. int new_datasize = width_ * height_;
  40. if (datasize < new_datasize) {
  41. if (data != null) {
  42. datasize = 0; data = null;
  43. }
  44. if (new_datasize > 0) {
  45. ColorModel cm = format.getColorModel();
  46. data = cm.createCompatibleWritableRaster(width_, height_);
  47. image = new BufferedImage(cm, data, cm.isAlphaPremultiplied(), null);
  48. datasize = new_datasize;
  49. }
  50. }
  51. }
  52. protected int datasize;
  53. static LogWriter vlog = new LogWriter("ManagedPixelBuffer");
  54. }