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


C++ BBitmap::Bits方法代码示例

本文整理汇总了C++中BBitmap::Bits方法的典型用法代码示例。如果您正苦于以下问题:C++ BBitmap::Bits方法的具体用法?C++ BBitmap::Bits怎么用?C++ BBitmap::Bits使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BBitmap的用法示例。


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

示例1: new

// SetIcon
status_t
IconButton::SetIcon(const unsigned char* bitsFromQuickRes,
                    uint32 width, uint32 height, color_space format, bool convertToBW)
{
    status_t status = B_BAD_VALUE;
    if (bitsFromQuickRes && width > 0 && height > 0) {
        BBitmap* quickResBitmap = new(nothrow) BBitmap(BRect(0.0, 0.0, width - 1.0, height - 1.0), format);
        status = quickResBitmap ? quickResBitmap->InitCheck() : B_ERROR;
        if (status >= B_OK) {
            // It doesn't look right to copy BitsLength() bytes, but bitmaps
            // exported from QuickRes still contain their padding, so it is alright.
            memcpy(quickResBitmap->Bits(), bitsFromQuickRes, quickResBitmap->BitsLength());
            if (format != B_RGB32 && format != B_RGBA32 && format != B_RGB32_BIG && format != B_RGBA32_BIG) {
                // colorspace needs conversion
                BBitmap* bitmap = new(nothrow) BBitmap(quickResBitmap->Bounds(), B_RGB32, true);
                if (bitmap && bitmap->IsValid()) {
                    BView* helper = new BView(bitmap->Bounds(), "helper",
                                              B_FOLLOW_NONE, B_WILL_DRAW);
                    if (bitmap->Lock()) {
                        bitmap->AddChild(helper);
                        helper->SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
                        helper->FillRect(helper->Bounds());
                        helper->SetDrawingMode(B_OP_OVER);
                        helper->DrawBitmap(quickResBitmap, BPoint(0.0, 0.0));
                        helper->Sync();
                        bitmap->Unlock();
                    }
                    status = _MakeBitmaps(bitmap);
                } else
                    printf("IconButton::SetIcon() - B_RGB32 bitmap is not valid\n");
                delete bitmap;
            } else {
                // native colorspace (32 bits)
                if (convertToBW) {
                    // convert to gray scale icon
                    uint8* bits = (uint8*)quickResBitmap->Bits();
                    uint32 bpr = quickResBitmap->BytesPerRow();
                    for (uint32 y = 0; y < height; y++) {
                        uint8* handle = bits;
                        uint8 gray;
                        for (uint32 x = 0; x < width; x++) {
                            gray = uint8((116 * handle[0] + 600 * handle[1] + 308 * handle[2]) / 1024);
                            handle[0] = gray;
                            handle[1] = gray;
                            handle[2] = gray;
                            handle += 4;
                        }
                        bits += bpr;
                    }
                }
                status = _MakeBitmaps(quickResBitmap);
            }
        } else
            printf("IconButton::SetIcon() - error allocating bitmap: %s\n", strerror(status));
        delete quickResBitmap;
    }
    return status;
}
开发者ID:mmanley,项目名称:Antares,代码行数:59,代码来源:IconButton.cpp

示例2: WriteRGBSpanBack

void MesaDriver::WriteRGBSpanBack(const GLcontext *ctx, GLuint n,
                                GLint x, GLint y,
                                CONST GLubyte rgb[][3],
                                const GLubyte mask[])
{
	MesaDriver *md = (MesaDriver *) ctx->DriverCtx;
	BBitmap *bitmap = md->m_bitmap;

	assert(bitmap);

	int row = md->m_bottom - y;
	uint8 * ptr = (uint8 *) bitmap->Bits() + (row * bitmap->BytesPerRow()) + x * 4;
 	uint32 * pixel = (uint32 *) ptr;
	
	if (mask) {
		while(n--) {
			if (*mask++)
				*pixel = PACK_B_RGB32(rgb[0]);
			pixel++;
			rgb++;
		};
	} else {
		while(n--) {
			*pixel++ = PACK_B_RGB32(rgb[0]);
			rgb++;
		};
	};
}
开发者ID:MttDs,项目名称:new-rexeno-tindpe,代码行数:28,代码来源:GLView.cpp

示例3: CopyPixelsIn

status_t MesaDriver::CopyPixelsIn(BBitmap *bitmap, BPoint location)
{
	color_space scs = bitmap->ColorSpace();
	color_space dcs = m_bitmap->ColorSpace();

	if (scs != dcs && (dcs != B_RGBA32 || scs != B_RGB32)) {
		printf("CopyPixelsIn(): incompatible color space: %s != %s\n",
			color_space_name(scs),
			color_space_name(dcs));
		return B_BAD_TYPE;
	}
	
	// debugger("CopyPixelsIn()");

	BRect sr = bitmap->Bounds();
	BRect dr = m_bitmap->Bounds();

	sr = sr & dr.OffsetBySelf(location);
	dr = sr.OffsetByCopy(-location.x, -location.y); 
	
	uint8 *ps = (uint8 *) bitmap->Bits();
	uint8 *pd = (uint8 *) m_bitmap->Bits();
	uint32 *s, *d;
	uint32 y;
	for (y = (uint32) sr.top; y <= (uint32) sr.bottom; y++) {
		s = (uint32 *) (ps + y * bitmap->BytesPerRow());
		s += (uint32) sr.left;
		
		d = (uint32 *) (pd + (y + (uint32) (dr.top - sr.top)) * m_bitmap->BytesPerRow());
		d += (uint32) dr.left;
		
		memcpy(d, s, dr.IntegerWidth() * 4);
	}
	return B_OK;
}
开发者ID:MttDs,项目名称:new-rexeno-tindpe,代码行数:35,代码来源:GLView.cpp

示例4: ClearBack

void MesaDriver::ClearBack(GLcontext *ctx,
                        GLboolean all, GLint x, GLint y,
                        GLint width, GLint height)
{
   MesaDriver *md = (MesaDriver *) ctx->DriverCtx;
   BGLView *bglview = md->m_bglview;
   assert(bglview);
   BBitmap *bitmap = md->m_bitmap;
   assert(bitmap);
   GLuint *start = (GLuint *) bitmap->Bits();
   const GLuint *clearPixelPtr = (const GLuint *) md->m_clear_color;
   const GLuint clearPixel = B_LENDIAN_TO_HOST_INT32(*clearPixelPtr);

   if (all) {
      const int numPixels = md->m_width * md->m_height;
      if (clearPixel == 0) {
         memset(start, 0, numPixels * 4);
      }
      else {
         for (int i = 0; i < numPixels; i++) {
             start[i] = clearPixel;
         }
      }
   }
   else {
      // XXX untested
      start += y * md->m_width + x;
      for (int i = 0; i < height; i++) {
         for (int j = 0; j < width; j++) {
            start[j] = clearPixel;
         }
         start += md->m_width;
      }
   }
}
开发者ID:MttDs,项目名称:new-rexeno-tindpe,代码行数:35,代码来源:GLView.cpp

示例5: r

BBitmap *
TransportButton::MakeBitmap(uint32 mask)
{
    BRect r(Bounds());
    BBitmap *result = new BBitmap(r, B_CMAP8);

    uint8* src = (uint8*)BitsForMask(mask);

    if (src && result && result->IsValid()) {
        // int32 width = r.IntegerWidth() + 1;
        int32 height = r.IntegerHeight() + 1;
        int32 bpr = result->BytesPerRow();
        uint8* dst = (uint8*)result->Bits();
        // copy source bits into bitmap line by line,
        // taking possible alignment into account
        // since the source data has been generated
        // by QuickRes, it still contains aligment too
        // (hence skipping bpr and not width bytes)
        for (int32 y = 0; y < height; y++) {
            memcpy(dst, src, bpr);
            src += bpr;
            dst += bpr;
        }
        ReplaceTransparentColor(result, Parent()->ViewColor());
    } else {
        delete result;
        result = NULL;
    }
    
    return result;
}
开发者ID:FLYKingdom,项目名称:vlc,代码行数:31,代码来源:TransportButton.cpp

示例6: sizeof

/* Dump data from stream into a BBitmap */
status_t
GetBitmap(BPositionIO *in, BBitmap **out)
{
	TranslatorBitmap header;

	status_t err = in->Read(&header, sizeof(header));
	if (err != sizeof(header))
		return B_IO_ERROR;

	header.magic = B_BENDIAN_TO_HOST_INT32(header.magic);
	header.bounds.left = B_BENDIAN_TO_HOST_FLOAT(header.bounds.left);
	header.bounds.top = B_BENDIAN_TO_HOST_FLOAT(header.bounds.top);
	header.bounds.right = B_BENDIAN_TO_HOST_FLOAT(header.bounds.right);
	header.bounds.bottom = B_BENDIAN_TO_HOST_FLOAT(header.bounds.bottom);
	header.rowBytes = B_BENDIAN_TO_HOST_INT32(header.rowBytes);
	header.colors = (color_space)B_BENDIAN_TO_HOST_INT32(header.colors);
	header.dataSize = B_BENDIAN_TO_HOST_INT32(header.dataSize);

	BBitmap *bitmap = new BBitmap(header.bounds, header.colors);
	*out = bitmap;
	if (bitmap == NULL) return B_NO_MEMORY;
	unsigned char *bits = (unsigned char *)bitmap->Bits();
	if (bits == NULL) {
		delete bitmap;
		return B_NO_MEMORY;
	}
	err = in->Read(bits, header.dataSize);
	if (err == (status_t)header.dataSize) return B_OK;
	else {
		delete bitmap;
		return B_IO_ERROR;
	}
}
开发者ID:veer77,项目名称:Haiku-services-branch,代码行数:34,代码来源:GIFTranslator.cpp

示例7: message

status_t
RemoteDrawingEngine::ReadBitmap(ServerBitmap* bitmap, bool drawCursor,
	BRect bounds)
{
	if (_AddCallback() != B_OK)
		return B_UNSUPPORTED;

	RemoteMessage message(NULL, fHWInterface->SendBuffer());

	message.Start(RP_READ_BITMAP);
	message.Add(fToken);
	message.Add(bounds);
	message.Add(drawCursor);
	if (message.Flush() != B_OK)
		return B_UNSUPPORTED;

	status_t result;
	do {
		result = acquire_sem_etc(fResultNotify, 1, B_RELATIVE_TIMEOUT,
			100 * 1000 * 1000);
	} while (result == B_INTERRUPTED);

	if (result != B_OK)
		return result;

	BBitmap* read = fReadBitmapResult;
	if (read == NULL)
		return B_UNSUPPORTED;

	result = bitmap->ImportBits(read->Bits(), read->BitsLength(),
		read->BytesPerRow(), read->ColorSpace());
	delete read;
	return result;
}
开发者ID:mariuz,项目名称:haiku,代码行数:34,代码来源:RemoteDrawingEngine.cpp

示例8: BBitmap

/*!
	\brief Retrieves a cursor from the set.
	\param which System cursor specifier defined in CursorSet.h
	\param cursor Bitmap** to receive a newly-allocated BBitmap containing the appropriate data
	\param hotspot The recipient of the hotspot for the cursor
	\return
	- \c B_OK: Success
	- \c B_BAD_VALUE: a NULL parameter was passed
	- \c B_NAME_NOT_FOUND: The specified cursor does not exist in this set
	- \c B_ERROR: An internal error occurred
	
	BBitmaps created by this function are the responsibility of the caller.
*/
status_t
CursorSet::FindCursor(BCursorID which, BBitmap **cursor, BPoint *hotspot)
{
	if (!cursor || !hotspot)
		return B_BAD_VALUE;

	BMessage msg;
	if (FindMessage(_CursorWhichToString(which), &msg) != B_OK)
		return B_NAME_NOT_FOUND;

	const void *buffer;
	const char *tempstr;
	int32 bufferLength;
	BBitmap *bmp;
	BPoint hotpt;

	if (msg.FindString("class", &tempstr) != B_OK)
		return B_ERROR;

	if (msg.FindPoint("hotspot", &hotpt) != B_OK)
		return B_ERROR;

	if (strcmp(tempstr, "cursor") == 0) {
		bmp = new BBitmap(msg.FindRect("_frame"),
			(color_space)msg.FindInt32("_cspace"), true);
		msg.FindData("_data", B_RAW_TYPE, (const void **)&buffer,
			(ssize_t *)&bufferLength);
		memcpy(bmp->Bits(), buffer, bufferLength);

		*cursor = bmp;
		*hotspot = hotpt;
		return B_OK;
	}
	return B_ERROR;
}
开发者ID:mariuz,项目名称:haiku,代码行数:48,代码来源:CursorSet.cpp

示例9: WriteMonoRGBASpanBack

void MesaDriver::WriteMonoRGBASpanBack(const GLcontext *ctx, GLuint n,
                                    GLint x, GLint y,
                                    const GLchan color[4], const GLubyte mask[])
{
	MesaDriver *md = (MesaDriver *) ctx->DriverCtx;
	BBitmap *bitmap = md->m_bitmap;

	assert(bitmap);

	int row = md->m_bottom - y;
	uint8 * ptr = (uint8 *) bitmap->Bits() + (row * bitmap->BytesPerRow()) + x * 4;
 	uint32 * pixel = (uint32 *) ptr;
	uint32 pixel_color = PACK_B_RGBA32(color);
	
	if (mask) {
		while(n--) {
			if (*mask++)
				*pixel = pixel_color;
			pixel++;
		};
	} else {
		while(n--) {
			*pixel++ = pixel_color;
		};
	};
}
开发者ID:MttDs,项目名称:new-rexeno-tindpe,代码行数:26,代码来源:GLView.cpp

示例10: WriteRGBAPixelsBack

void MesaDriver::WriteRGBAPixelsBack(const GLcontext *ctx,
                                   GLuint n, const GLint x[], const GLint y[],
                                   CONST GLubyte rgba[][4],
                                   const GLubyte mask[] )
{
   MesaDriver *md = (MesaDriver *) ctx->DriverCtx;
   BBitmap *bitmap = md->m_bitmap;

	assert(bitmap);
#if 0
	while(n--) {
		if (*mask++) {
			int row = md->m_bottom - *y;
			uint8 * pixel = (uint8 *) bitmap->Bits() + (row * bitmap->BytesPerRow()) + *x * 4;
			*((uint32 *) pixel) = PACK_B_RGBA32(rgba[0]);
		};
		x++;
		y++;
		rgba++;
	};
#else
   if (mask) {
      for (GLuint i = 0; i < n; i++) {
         if (mask[i]) {
            GLubyte *pixel = (GLubyte *) bitmap->Bits()
            + ((md->m_bottom - y[i]) * bitmap->BytesPerRow()) + x[i] * 4;
            pixel[BE_RCOMP] = rgba[i][RCOMP];
            pixel[BE_GCOMP] = rgba[i][GCOMP];
            pixel[BE_BCOMP] = rgba[i][BCOMP];
            pixel[BE_ACOMP] = rgba[i][ACOMP];
         }
      }
   }
   else {
      for (GLuint i = 0; i < n; i++) {
         GLubyte *pixel = (GLubyte *) bitmap->Bits()
            + ((md->m_bottom - y[i]) * bitmap->BytesPerRow()) + x[i] * 4;
         pixel[BE_RCOMP] = rgba[i][RCOMP];
         pixel[BE_GCOMP] = rgba[i][GCOMP];
         pixel[BE_BCOMP] = rgba[i][BCOMP];
         pixel[BE_ACOMP] = rgba[i][ACOMP];
      }
   }
#endif
}
开发者ID:MttDs,项目名称:new-rexeno-tindpe,代码行数:45,代码来源:GLView.cpp

示例11: file

void
TBarApp::FetchAppIcon(BarTeamInfo* barInfo)
{
	int32 width = IconSize();
	int32 index = (width - kMinimumIconSize) / kIconSizeInterval;

	// first look in the icon cache
	barInfo->icon = barInfo->iconCache[index];
	if (barInfo->icon != NULL)
		return;

	// icon wasn't in cache, get it from be_roster and cache it
	app_info appInfo;
	icon_size size = width >= 31 ? B_LARGE_ICON : B_MINI_ICON;
	BBitmap* icon = new BBitmap(IconRect(), kIconColorSpace);
	if (be_roster->GetAppInfo(barInfo->sig, &appInfo) == B_OK) {
		// fetch the app icon
		BFile file(&appInfo.ref, B_READ_ONLY);
		BAppFileInfo appMime(&file);
		if (appMime.GetIcon(icon, size) == B_OK) {
			delete barInfo->iconCache[index];
			barInfo->iconCache[index] = barInfo->icon = icon;
			return;
		}
	}

	// couldn't find the app icon
	// fetch the generic 3 boxes icon and cache it
	BMimeType defaultAppMime;
	defaultAppMime.SetTo(B_APP_MIME_TYPE);
	if (defaultAppMime.GetIcon(icon, size) == B_OK) {
		delete barInfo->iconCache[index];
		barInfo->iconCache[index] = barInfo->icon = icon;
		return;
	}

	// couldn't find generic 3 boxes icon
	// fill with transparent
	uint8* iconBits = (uint8*)icon->Bits();
	if (icon->ColorSpace() == B_RGBA32) {
		int32 i = 0;
		while (i < icon->BitsLength()) {
			iconBits[i++] = B_TRANSPARENT_32_BIT.red;
			iconBits[i++] = B_TRANSPARENT_32_BIT.green;
			iconBits[i++] = B_TRANSPARENT_32_BIT.blue;
			iconBits[i++] = B_TRANSPARENT_32_BIT.alpha;
		}
	} else {
		// Assume B_CMAP8
		for (int32 i = 0; i < icon->BitsLength(); i++)
			iconBits[i] = B_TRANSPARENT_MAGIC_CMAP8;
	}

	delete barInfo->iconCache[index];
	barInfo->iconCache[index] = barInfo->icon = icon;
}
开发者ID:kbjava,项目名称:haiku,代码行数:56,代码来源:BarApp.cpp

示例12: BBitmap

BBitmap*
OffscreenBitmap::Copy()
{
	// the result bitmap that does not accept views	
	// to save resources in the application server
	BBitmap *copy = new BBitmap(fFrame, fColorSpace, false);
	AutoDelete<BBitmap> _copy(copy);
	if (copy == NULL || copy->IsValid() == false || copy->InitCheck() != B_OK)
		return NULL;

	fView->Sync();
	fBitmap->Unlock();
	
	memcpy(copy->Bits(), fBitmap->Bits(), fBitmap->BitsLength());	
	
	fBitmap->Lock();

	return _copy.Release();
}
开发者ID:SummerSnail2014,项目名称:haiku,代码行数:19,代码来源:PictureTest.cpp

示例13: Refresh

void Window::Refresh(int x, int y, int w, int h) {
  int32* d = (int32*)_offscreen->Bits();
  int32* dl = d;
  uint8* s = (uint8*)_bitmap->Bits();
  uint8* sl = s;
  if (Lock()) {
    switch(_surface->root.bitmap.mode) {
	case gr_pixel_mode_mono:
	  for (y = 0; y < _surface->root.bitmap.rows; y++) {
	    sl = s;
	    dl = d;
	    for (x = 0; x < _surface->root.bitmap.width; x++) {
	      *dl = *sl ? -1 : 0;
	      sl++; dl++;
	    }
	    s += _bitmap->BytesPerRow();
	    d = (int32*)(((char*)d) + _offscreen->BytesPerRow());
	  }
	  break;
	case gr_pixel_mode_gray:
	  for (y = 0; y < _surface->root.bitmap.rows; y++) {
	    sl = s;
	    int8* dx = (int8*)d;
	    for (x = 0; x < _surface->root.bitmap.width; x++) {
	      *dx = *sl; dx++;
	      *dx = *sl; dx++;
	      *dx = *sl; dx++;
	      *dx = *sl; dx++;
	      sl++;
	    }
	    s += _bitmap->BytesPerRow();
	    d = (int32*)(((char*)d) + _offscreen->BytesPerRow());
	  }
	  break;
	default:
	  fprintf(stderr, "unsupported mode: %d\n", _surface->root.bitmap.mode);
	  break;
    }
    _view->Invalidate();
    Unlock();
  }
}
开发者ID:sean93park,项目名称:freetype2-demos,代码行数:42,代码来源:grbeos.cpp

示例14: BMenuItem

BitmapMenuItem::BitmapMenuItem(const char* name, const BBitmap& bitmap,
	BMessage* message, char shortcut, uint32 modifiers)
	: BMenuItem(name, message, shortcut, modifiers),
	m_bitmap(bitmap.Bounds(), bitmap.ColorSpace())
{
	// Sadly, operator= for bitmaps is not yet implemented.
	// Half of m_bitmap's initialization is above; now we copy
	// the bits.
	m_bitmap.SetBits(bitmap.Bits(), bitmap.BitsLength(),
		0, bitmap.ColorSpace());
}
开发者ID:SummerSnail2014,项目名称:haiku,代码行数:11,代码来源:BitmapMenuItem.cpp

示例15: if

// Retrieves an icon associated with a given device.
status_t
get_device_icon(const char *device, BBitmap *icon, icon_size which)
{
	// check parameters
	if (device == NULL || icon == NULL)
		return B_BAD_VALUE;

	uint8* data;
	size_t size;
	type_code type;
	status_t status = get_device_icon(device, &data, &size, &type);
	if (status == B_OK) {
		status = BIconUtils::GetVectorIcon(data, size, icon);
		delete[] data;
		return status;
	}

	// Vector icon was not available, try old one

	BRect rect;
	if (which == B_MINI_ICON)
		rect.Set(0, 0, 15, 15);
	else if (which == B_LARGE_ICON)
		rect.Set(0, 0, 31, 31);

	BBitmap* bitmap = icon;
	int32 iconSize = which;

	if (icon->ColorSpace() != B_CMAP8
		|| (which != B_MINI_ICON && which != B_LARGE_ICON)) {
		if (which < B_LARGE_ICON)
			iconSize = B_MINI_ICON;
		else
			iconSize = B_LARGE_ICON;

		bitmap = new(std::nothrow) BBitmap(
			BRect(0, 0, iconSize - 1, iconSize -1), B_BITMAP_NO_SERVER_LINK,
			B_CMAP8);
		if (bitmap == NULL || bitmap->InitCheck() != B_OK) {
			delete bitmap;
			return B_NO_MEMORY;
		}
	}

	// get the icon, convert temporary data into bitmap if necessary
	status = get_device_icon(device, bitmap->Bits(), iconSize);
	if (status == B_OK && icon != bitmap)
		status = BIconUtils::ConvertFromCMAP8(bitmap, icon);

	if (icon != bitmap)
		delete bitmap;

	return status;
}
开发者ID:Barrett17,项目名称:haiku-contacts-kit-old,代码行数:55,代码来源:Mime.cpp


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