当前位置: 首页>>代码示例>>C++>>正文


C++ BytesPerPixel函数代码示例

本文整理汇总了C++中BytesPerPixel函数的典型用法代码示例。如果您正苦于以下问题:C++ BytesPerPixel函数的具体用法?C++ BytesPerPixel怎么用?C++ BytesPerPixel使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了BytesPerPixel函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: NearestSampler

void NearestSampler(PixelBox& dest, const PixelBox& src) {
	size_t bytesPerPix = BytesPerPixel(src.format);
	NEX_ASSERT(bytesPerPix == BytesPerPixel(dest.format));

	float dstep = ((float) src.GetDepth() / (float) dest.GetDepth()) * .5f;
	float hstep = ((float) src.GetHeight() / (float) dest.GetHeight()) * .5f;
	float wstep = ((float) src.GetWidth() / (float) dest.GetWidth()) * .5f;

	for (uint32 d = dest.front; d < dest.back; ++d) {
		size_t doff = (uint32) (dstep * (src.slicePixelPitch * d * 2 + 1));
		NEX_ASSERT(doff >= 0 && doff <= src.slicePixelPitch * d);
		void* destPlane = reinterpret_cast<uint8*>(dest.data)
				+ d * dest.slicePixelPitch * bytesPerPix;
		for (uint32 h = dest.top; h < dest.bottom; ++h) {

			size_t hoff = (uint32) ((2 * h * src.rowPixelPitch + 1) * hstep);
			NEX_ASSERT(hoff >= 0 && hoff <= src.rowPixelPitch * h);
			uint8* destRow = reinterpret_cast<uint8*>(destPlane)
					+ h * dest.rowPixelPitch * bytesPerPix;
			for (uint32 w = dest.left; w < dest.right; ++w) {
				size_t woff = (size_t) ((2 * w + 1) * wstep);
				NEX_ASSERT(woff >= 0 && woff <= w);
				uint8* srcData = reinterpret_cast<uint8*>(src.data)
						+ (doff + hoff + woff) * bytesPerPix;
				// src offset
				uint8* destData = (destRow + w * bytesPerPix);
				for (uint32 j = 0; j < bytesPerPix; ++j)
					destData[j] = srcData[j];
			}
		}
	}
}
开发者ID:obhi-d,项目名称:nextar,代码行数:32,代码来源:PixelFormat.cpp

示例2: MOZ_ASSERT

void
SourceSurfaceD2D1::DrawTargetWillChange()
{
  // At this point in time this should always be true here.
  MOZ_ASSERT(mRealizedBitmap);

  RefPtr<ID2D1Bitmap1> oldBitmap = mRealizedBitmap;

  D2D1_BITMAP_PROPERTIES1 props;
  props.dpiX = 96;
  props.dpiY = 96;
  props.pixelFormat = D2DPixelFormat(mFormat);
  props.colorContext = nullptr;
  props.bitmapOptions = D2D1_BITMAP_OPTIONS_TARGET;
  HRESULT hr = mDC->CreateBitmap(D2DIntSize(mSize), nullptr, 0, props, (ID2D1Bitmap1**)getter_AddRefs(mRealizedBitmap));

  if (FAILED(hr)) {
    gfxCriticalError() << "Failed to create bitmap to make DrawTarget copy. Size: " << mSize << " Code: " << hexa(hr);
    MarkIndependent();
    return;
  }

  D2D1_POINT_2U point = D2D1::Point2U(0, 0);
  D2D1_RECT_U rect = D2D1::RectU(0, 0, mSize.width, mSize.height);
  mRealizedBitmap->CopyFromBitmap(&point, oldBitmap, &rect);
  mImage = mRealizedBitmap;

  DrawTargetD2D1::mVRAMUsageSS += mSize.width * mSize.height * BytesPerPixel(mFormat);

  // We now no longer depend on the source surface content remaining the same.
  MarkIndependent();
}
开发者ID:bgrins,项目名称:gecko-dev,代码行数:32,代码来源:SourceSurfaceD2D1.cpp

示例3: ClearDataSourceSurface

void
ClearDataSourceSurface(DataSourceSurface *aSurface)
{
  DataSourceSurface::MappedSurface map;
  if (!aSurface->Map(DataSourceSurface::MapType::WRITE, &map)) {
    MOZ_ASSERT(false, "Failed to map DataSourceSurface");
    return;
  }

  // We avoid writing into the gaps between the rows here since we can't be
  // sure that some drivers don't use those bytes.

  uint32_t width = aSurface->GetSize().width;
  uint32_t bytesPerRow = width * BytesPerPixel(aSurface->GetFormat());
  uint8_t* row = map.mData;
  // converting to size_t here because otherwise the temporaries can overflow
  // and we can end up with |end| being a bad address!
  uint8_t* end = row + size_t(map.mStride) * size_t(aSurface->GetSize().height);

  while (row != end) {
    memset(row, 0, bytesPerRow);
    row += map.mStride;
  }

  aSurface->Unmap();
}
开发者ID:ednapiranha,项目名称:gecko-dev,代码行数:26,代码来源:DataSurfaceHelpers.cpp

示例4: SharedSurface_GL

SharedSurface_Basic::SharedSurface_Basic(GLContext* gl,
                                         const IntSize& size,
                                         bool hasAlpha,
                                         SurfaceFormat format,
                                         GLuint tex)
    : SharedSurface_GL(SharedSurfaceType::Basic,
                       AttachmentType::GLTexture,
                       gl,
                       size,
                       hasAlpha)
    , mTex(tex), mFB(0)
{
    mGL->MakeCurrent();
    mGL->fGenFramebuffers(1, &mFB);

    ScopedBindFramebuffer autoFB(mGL, mFB);
    mGL->fFramebufferTexture2D(LOCAL_GL_FRAMEBUFFER,
                              LOCAL_GL_COLOR_ATTACHMENT0,
                              LOCAL_GL_TEXTURE_2D,
                              mTex,
                              0);

    GLenum status = mGL->fCheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER);
    if (status != LOCAL_GL_FRAMEBUFFER_COMPLETE) {
        mGL->fDeleteFramebuffers(1, &mFB);
        mFB = 0;
    }

    mData = Factory::CreateDataSourceSurfaceWithStride(size, format,
              GetAlignedStride<4>(size.width * BytesPerPixel(format)));
}
开发者ID:JuannyWang,项目名称:gecko-dev,代码行数:31,代码来源:SharedSurfaceGL.cpp

示例5: byRef

void
SourceSurfaceD2DTarget::DrawTargetWillChange()
{
  RefPtr<ID3D10Texture2D> oldTexture = mTexture;

  D3D10_TEXTURE2D_DESC desc;
  mTexture->GetDesc(&desc);

  // Our original texture might implement the keyed mutex flag. We shouldn't
  // need that here. We actually specifically don't want it since we don't lock
  // our texture for usage!
  desc.MiscFlags = 0;

  // Get a copy of the surface data so the content at snapshot time was saved.
  Factory::GetDirect3D10Device()->CreateTexture2D(&desc, nullptr, byRef(mTexture));
  Factory::GetDirect3D10Device()->CopyResource(mTexture, oldTexture);

  mBitmap = nullptr;

  DrawTargetD2D::mVRAMUsageSS += desc.Width * desc.Height * BytesPerPixel(mFormat);
  mOwnsCopy = true;

  // We now no longer depend on the source surface content remaining the same.
  MarkIndependent();
}
开发者ID:gp-b2g,项目名称:gp-revolution-gecko,代码行数:25,代码来源:SourceSurfaceD2DTarget.cpp

示例6: GetSrcImage

BBitmap*
ImageProcessor::CreateDestImage(BBitmap* /* srcImage */)
{
	color_space cs;
	BBitmap* bm;
	BRect rect;

	if (GetSrcImage() == NULL) return NULL;

	cs = GetSrcImage()->ColorSpace();
	fBPP = BytesPerPixel(cs);
	if (fBPP < 1) return NULL;

	fWidth = GetSrcImage()->Bounds().IntegerWidth();
	fHeight = GetSrcImage()->Bounds().IntegerHeight();

	if (fOp == kRotateClockwise || fOp == kRotateCounterClockwise) {
		rect.Set(0, 0, fHeight, fWidth);
	} else {
		rect.Set(0, 0, fWidth, fHeight);
	}

	bm = new BBitmap(rect, cs);
	if (!IsBitmapValid(bm)) {
		delete bm;
		return NULL;
	}

	fSrcBPR = GetSrcImage()->BytesPerRow();
	fDestBPR = bm->BytesPerRow();

	return bm;
}
开发者ID:nielx,项目名称:haiku-serviceskit,代码行数:33,代码来源:Filter.cpp

示例7: BufferSizeFromStrideAndHeight

bool
DataSourceSurfaceCG::InitFromData(unsigned char *aData,
                               const IntSize &aSize,
                               int32_t aStride,
                               SurfaceFormat aFormat)
{
  if (aSize.width <= 0 || aSize.height <= 0) {
    return false;
  }

  size_t bufLen = BufferSizeFromStrideAndHeight(aStride, aSize.height);
  if (bufLen == 0) {
    mImage = nullptr;
    return false;
  }

  void *data = malloc(bufLen);
  memcpy(data, aData, bufLen - aStride + (aSize.width * BytesPerPixel(aFormat)));

  mFormat = aFormat;
  mImage = CreateCGImage(data, data, aSize, aStride, aFormat);

  if (!mImage) {
    free(data);
    return false;
  }

  return true;
}
开发者ID:Belxjander,项目名称:tenfourfox,代码行数:29,代码来源:SourceSurfaceCG.cpp

示例8: DataOffset

static unsigned int
DataOffset(const IntPoint& aPoint, int32_t aStride, SurfaceFormat aFormat)
{
  unsigned int data = aPoint.y * aStride;
  data += aPoint.x * BytesPerPixel(aFormat);
  return data;
}
开发者ID:bgrins,项目名称:gecko-dev,代码行数:7,代码来源:GLUploadHelpers.cpp

示例9: MOZ_ASSERT

void
SourceSurfaceD2D1::DrawTargetWillChange()
{
  // At this point in time this should always be true here.
  MOZ_ASSERT(mRealizedBitmap);

  RefPtr<ID2D1Bitmap1> oldBitmap = mRealizedBitmap;

  D2D1_BITMAP_PROPERTIES1 props;
  props.dpiX = 96;
  props.dpiY = 96;
  props.pixelFormat = D2DPixelFormat(mFormat);
  props.colorContext = nullptr;
  props.bitmapOptions = D2D1_BITMAP_OPTIONS_TARGET;
  mDC->CreateBitmap(D2DIntSize(mSize), nullptr, 0, props, (ID2D1Bitmap1**)byRef(mRealizedBitmap));

  D2D1_POINT_2U point = D2D1::Point2U(0, 0);
  D2D1_RECT_U rect = D2D1::RectU(0, 0, mSize.width, mSize.height);
  mRealizedBitmap->CopyFromBitmap(&point, oldBitmap, &rect);
  mImage = mRealizedBitmap;

  DrawTargetD2D1::mVRAMUsageSS += mSize.width * mSize.height * BytesPerPixel(mFormat);
  mDrawTarget = nullptr;

  // We now no longer depend on the source surface content remaining the same.
  MarkIndependent();
}
开发者ID:Gabuzo,项目名称:mozilla-central,代码行数:27,代码来源:SourceSurfaceD2D1.cpp

示例10: BytesPerPixel

bool
SourceSurfaceAlignedRawData::Init(const IntSize &aSize,
                                  SurfaceFormat aFormat,
                                  bool aClearMem,
                                  uint8_t aClearValue,
                                  int32_t aStride)
{
  mFormat = aFormat;
  mStride = aStride ? aStride : GetAlignedStride<16>(aSize.width * BytesPerPixel(aFormat));

  size_t bufLen = BufferSizeFromStrideAndHeight(mStride, aSize.height);
  if (bufLen > 0) {
    bool zeroMem = aClearMem && !aClearValue;
    static_assert(sizeof(decltype(mArray[0])) == 1,
                  "mArray.Realloc() takes an object count, so its objects must be 1-byte sized if we use bufLen");

    // AlignedArray uses cmalloc to zero mem for a fast path.
    mArray.Realloc(/* actually an object count */ bufLen, zeroMem);
    mSize = aSize;

    if (mArray && aClearMem && aClearValue) {
      memset(mArray, aClearValue, mStride * aSize.height);
    }
  } else {
    mArray.Dealloc();
    mSize.SizeTo(0, 0);
  }

  return mArray != nullptr;
}
开发者ID:cliqz-oss,项目名称:browser-f,代码行数:30,代码来源:SourceSurfaceRawData.cpp

示例11: BufferSizeFromDimensions

void
TextureHostFileMapping::UpdatedInternal(const nsIntRegion* aRegion)
{
  if (!mProvider) {
    // This can happen if we send textures to a compositable that isn't yet
    // attached to a layer.
    return;
  }

  if (!mTextureSource) {
    mTextureSource = mProvider->CreateDataTextureSource(mFlags);
  }

  uint8_t* data = nullptr;
  int32_t totalBytes = BufferSizeFromDimensions(mSize.width, mSize.height, BytesPerPixel(mFormat));
  if (totalBytes > 0) {
    data = (uint8_t*)::MapViewOfFile(mFileMapping, FILE_MAP_READ, 0, 0, totalBytes);
  }

  if (data) {
    RefPtr<DataSourceSurface> surf = Factory::CreateWrappingDataSourceSurface(data, mSize.width * BytesPerPixel(mFormat), mSize, mFormat);
    if (surf) {
        surf->AddUserData(&kFileMappingKey, data, UnmapFileData);
        if (!mTextureSource->Update(surf, const_cast<nsIntRegion*>(aRegion))) {
          mTextureSource = nullptr;
        }
    } else {
      mTextureSource = nullptr;
    }
  } else {
    mTextureSource = nullptr;
  }

  ReadUnlock();
}
开发者ID:Wafflespeanut,项目名称:gecko-dev,代码行数:35,代码来源:TextureDIB.cpp

示例12: gfxCriticalError

bool
MemoryDIBTextureData::UpdateFromSurface(gfx::SourceSurface* aSurface)
{
  RefPtr<gfxImageSurface> imgSurf = mSurface->GetAsImageSurface();

  RefPtr<DataSourceSurface> srcSurf = aSurface->GetDataSurface();

  if (!srcSurf) {
    gfxCriticalError() << "Failed to GetDataSurface in UpdateFromSurface (DIB).";
    return false;
  }

  DataSourceSurface::MappedSurface sourceMap;
  if (!srcSurf->Map(gfx::DataSourceSurface::READ, &sourceMap)) {
    gfxCriticalError() << "Failed to map source surface for UpdateFromSurface.";
    return false;
  }

  for (int y = 0; y < srcSurf->GetSize().height; y++) {
    memcpy(imgSurf->Data() + imgSurf->Stride() * y,
           sourceMap.mData + sourceMap.mStride * y,
           srcSurf->GetSize().width * BytesPerPixel(srcSurf->GetFormat()));
  }

  srcSurf->Unmap();
  return true;
}
开发者ID:Wafflespeanut,项目名称:gecko-dev,代码行数:27,代码来源:TextureDIB.cpp

示例13: BytesPerPixel

bool TextureScaler::IsEmptyOrFlat(u32* data, int pixels, int fmt) {
	int pixelsPerWord = 4 / BytesPerPixel(fmt);
	u32 ref = data[0];
	for (int i = 0; i < pixels / pixelsPerWord; ++i) {
		if (data[i] != ref) return false;
	}
	return true;
}
开发者ID:BlueSplash,项目名称:ppsspp,代码行数:8,代码来源:TextureScalerCommon.cpp

示例14: CopyRect

/**
 * aSrcRect: Rect relative to the aSrc surface
 * aDestPoint: Point inside aDest surface
 */
void
CopyRect(DataSourceSurface* aSrc, DataSourceSurface* aDest,
         IntRect aSrcRect, IntPoint aDestPoint)
{
  if (aSrcRect.Overflows() ||
      IntRect(aDestPoint, aSrcRect.Size()).Overflows()) {
    MOZ_CRASH("we should never be getting invalid rects at this point");
  }

  MOZ_RELEASE_ASSERT(aSrc->GetFormat() == aDest->GetFormat(),
                     "different surface formats");
  MOZ_RELEASE_ASSERT(IntRect(IntPoint(), aSrc->GetSize()).Contains(aSrcRect),
                     "source rect too big for source surface");
  MOZ_RELEASE_ASSERT(IntRect(IntPoint(), aDest->GetSize()).Contains(IntRect(aDestPoint, aSrcRect.Size())),
                     "dest surface too small");

  if (aSrcRect.IsEmpty()) {
    return;
  }

  DataSourceSurface::ScopedMap srcMap(aSrc, DataSourceSurface::READ);
  DataSourceSurface::ScopedMap destMap(aDest, DataSourceSurface::WRITE);
  if (MOZ2D_WARN_IF(!srcMap.IsMapped() || !destMap.IsMapped())) {
    return;
  }

  uint8_t* sourceData = DataAtOffset(aSrc, srcMap.GetMappedSurface(), aSrcRect.TopLeft());
  uint32_t sourceStride = srcMap.GetStride();
  uint8_t* destData = DataAtOffset(aDest, destMap.GetMappedSurface(), aDestPoint);
  uint32_t destStride = destMap.GetStride();

  if (BytesPerPixel(aSrc->GetFormat()) == 4) {
    for (int32_t y = 0; y < aSrcRect.height; y++) {
      PodCopy((int32_t*)destData, (int32_t*)sourceData, aSrcRect.width);
      sourceData += sourceStride;
      destData += destStride;
    }
  } else if (BytesPerPixel(aSrc->GetFormat()) == 1) {
    for (int32_t y = 0; y < aSrcRect.height; y++) {
      PodCopy(destData, sourceData, aSrcRect.width);
      sourceData += sourceStride;
      destData += destStride;
    }
  }
}
开发者ID:ShakoHo,项目名称:gecko-dev,代码行数:49,代码来源:DataSurfaceHelpers.cpp

示例15: gfxCriticalError

bool
BufferTextureData::UpdateFromSurface(gfx::SourceSurface* aSurface)
{
  if (mDescriptor.type() != BufferDescriptor::TRGBDescriptor) {
    return false;
  }
  const RGBDescriptor& rgb = mDescriptor.get_RGBDescriptor();

  uint32_t stride = ImageDataSerializer::GetRGBStride(rgb);
  RefPtr<gfx::DataSourceSurface> surface =
    gfx::Factory::CreateWrappingDataSourceSurface(GetBuffer(), stride,
                                                  rgb.size(), rgb.format());

  if (!surface) {
    gfxCriticalError() << "Failed to get serializer as surface!";
    return false;
  }

  RefPtr<gfx::DataSourceSurface> srcSurf = aSurface->GetDataSurface();

  if (!srcSurf) {
    gfxCriticalError() << "Failed to GetDataSurface in UpdateFromSurface (BT).";
    return false;
  }

  if (surface->GetSize() != srcSurf->GetSize() || surface->GetFormat() != srcSurf->GetFormat()) {
    gfxCriticalError() << "Attempt to update texture client from a surface with a different size or format (BT)! This: " << surface->GetSize() << " " << surface->GetFormat() << " Other: " << aSurface->GetSize() << " " << aSurface->GetFormat();
    return false;
  }

  gfx::DataSourceSurface::MappedSurface sourceMap;
  gfx::DataSourceSurface::MappedSurface destMap;
  if (!srcSurf->Map(gfx::DataSourceSurface::READ, &sourceMap)) {
    gfxCriticalError() << "Failed to map source surface for UpdateFromSurface (BT).";
    return false;
  }

  if (!surface->Map(gfx::DataSourceSurface::WRITE, &destMap)) {
    srcSurf->Unmap();
    gfxCriticalError() << "Failed to map destination surface for UpdateFromSurface.";
    return false;
  }


  for (int y = 0; y < srcSurf->GetSize().height; y++) {
    memcpy(destMap.mData + destMap.mStride * y,
           sourceMap.mData + sourceMap.mStride * y,
           srcSurf->GetSize().width * BytesPerPixel(srcSurf->GetFormat()));
  }

  srcSurf->Unmap();
  surface->Unmap();

  return true;
}
开发者ID:devtools-html,项目名称:gecko-dev,代码行数:55,代码来源:BufferTexture.cpp


注:本文中的BytesPerPixel函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。