SimpleImageBuffer.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* vim:set ts=4 sw=4 sts=4 ci et: */
  3. /* This Source Code Form is subject to the terms of the Mozilla Public
  4. * License, v. 2.0. If a copy of the MPL was not distributed with this
  5. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  6. #include "SimpleImageBuffer.h"
  7. #include "mozilla/NullPtr.h"
  8. namespace mozilla {
  9. void
  10. SimpleImageBuffer::SetImage(const unsigned char* frame, unsigned int size, int width, int height)
  11. {
  12. mWidth = width;
  13. mHeight = height;
  14. if (!mBuffer || (size > mBufferSize)) {
  15. if (mBuffer) {
  16. delete[] mBuffer;
  17. mBuffer = nullptr;
  18. }
  19. mBufferSize = size;
  20. if (size > 0) {
  21. mBuffer = new unsigned char[size];
  22. }
  23. }
  24. if (mBuffer) {
  25. if (frame && (size > 0)) {
  26. memcpy((void *)mBuffer, (const void*)frame, size);
  27. }
  28. mSize = size;
  29. }
  30. }
  31. void
  32. SimpleImageBuffer::Copy(const SimpleImageBuffer* aImage)
  33. {
  34. if (aImage) {
  35. SetImage(aImage->mBuffer, aImage->mSize, aImage->mWidth, aImage->mHeight);
  36. }
  37. }
  38. const unsigned char*
  39. SimpleImageBuffer::GetImage(unsigned int* size) const
  40. {
  41. if (size) {
  42. *size = mSize;
  43. }
  44. return mBuffer;
  45. }
  46. } // namespace mozilla