Beispiel #1
0
/* internal routines */
static void 
init_dispinfo(struct dispinfo *d)
{
    int total_squares;
    ulong h;

    d->win_width = WIN_WIDTH;
    d->win_height = WIN_HEIGHT;

    d->pixel_xmult = PIX_SIZE;
    d->pixel_ymult = PIX_SIZE;

    total_squares = WinSize(d) / PixelSize(d);
    d->bytes_vp = d->alloc_unit;

    /* compute how many bytes of memory one square on the display should 
     * represent so you have the smallest granularity without the window size 
     * exceeding the initial height.
     */
    while (total_squares < DivideRoundedUp(d->arena_size, d->bytes_vp))
	d->bytes_vp *= 2;
    
    h = DivideRoundedUp(d->arena_size, d->bytes_vp) * PixelSize(d);
    d->win_height = DivideRoundedUp(h, d->win_width);
    d->win_height = RoundUp(d->win_height, d->pixel_ymult);
    
    sprintf(d->title + strlen(d->title), " (1 square = %d bytes)", 
	    d->bytes_vp);
}
Beispiel #2
0
/**
 * Returns the screen dimension rect to be used
 * @return The screen dimension rect to be used
 */
PixelSize
SystemWindowSize()
{
#if defined(WIN32) && !defined(_WIN32_WCE)
  unsigned width = CommandLine::width + 2 * GetSystemMetrics(SM_CXFIXEDFRAME);
  unsigned height = CommandLine::height + 2 * GetSystemMetrics(SM_CYFIXEDFRAME)
    + GetSystemMetrics(SM_CYCAPTION);

  return { width, height };
#else
  #ifdef WIN32
  return { GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN) };
#elif defined(ANDROID)
  return { native_view->get_width(), native_view->get_height() };
#elif defined(USE_VIDEOCORE)
  uint32_t width, height;
  return graphics_get_display_size(0, &width, &height) >= 0
    ? PixelSize(width, height)
    : PixelSize(640, 480);
#else
  /// @todo implement this properly for SDL/UNIX
  return { CommandLine::width, CommandLine::height };
  #endif /* !WIN32 */

#endif
}
Beispiel #3
0
static void 
resize_display(struct dispinfo *d, int new_width, int new_height)
{
    int total_squares;
    uint h;
    char *cp;

    /* round down to even multiple of square size */
    new_width = RoundDown(new_width, d->pixel_xmult);
    new_height = RoundDown(new_height, d->pixel_ymult);

    if (new_width <= 0 || new_height <= 0)
	return;

    total_squares = (new_width * new_height) / PixelSize(d);
    d->bytes_vp = d->alloc_unit;

    /* compute how many bytes of memory one square on the display should 
     * represent, so you have the smallest granularity without the window size
     * exceeding the initial height.
     */
    while (total_squares < DivideRoundedUp(d->arena_size, d->bytes_vp))
	d->bytes_vp *= 2;
    
    h = DivideRoundedUp(d->arena_size, d->bytes_vp) * PixelSize(d);
    new_height = DivideRoundedUp(h, new_width);
    new_height = RoundUp(new_height, d->pixel_ymult);

    cp = strchr(d->title, '=');
    if (cp)
	sprintf(cp, "= %d bytes)", d->bytes_vp);

    if (!(d->memory_pixel = DXReAllocate((Pointer)d->memory_pixel, 
					 new_width * new_height))) {
	xerror = 1;
	return;
    }
	
    d->win_width = new_width;
    d->win_height = new_height;
    memset (d->memory_pixel, color_free, d->win_width * d->win_height);

    /* don't let X free our pixel buffer while destroying old image */
    d->memory_image->data = NULL;
    XDestroyImage(d->memory_image);

    d->memory_image = XCreateImage(d->disp,
			     XDefaultVisual(d->disp, XDefaultScreen(d->disp)),
			     8, ZPixmap, 0, (char *) d->memory_pixel,
			     d->win_width, d->win_height, 8, 0);

    XResizeWindow(d->disp, d->wind, d->win_width, d->win_height);
    XStoreName(d->disp, d->wind, d->title);

}
Beispiel #4
0
PixelSize
TopCanvas::GetNativeSize() const
{
  unsigned w = 0, h = 0;
  glXQueryDrawable(x_display, glx_window, GLX_WIDTH, &w);
  glXQueryDrawable(x_display, glx_window, GLX_HEIGHT, &h);
  if (w <= 0 || h <= 0)
    return PixelSize(0, 0);

  return PixelSize(w, h);
}
Beispiel #5
0
void
TopCanvas::SetupViewport(PixelSize native_size)
{
  auto new_size = OpenGL::SetupViewport(UnsignedPoint2D(native_size.cx,
                                                        native_size.cy));
  Canvas::Create(PixelSize(new_size.x, new_size.y));
}
Beispiel #6
0
void
RawBitmap::SurfaceCreated()
{
  if (texture == nullptr) {
    texture = new GLTexture(PixelSize(corrected_width, height));
    texture->EnableInterpolation();
  }
}
Beispiel #7
0
const PixelSize
Canvas::CalcTextSize(const TCHAR *text, size_t length) const
{
  assert(IsDefined());

  SIZE size;
  ::GetTextExtentPoint(dc, text, length, &size);
  return PixelSize(size.cx, size.cy);
}
Beispiel #8
0
void
TopCanvas::SetDisplayOrientation(DisplayOrientation orientation)
{
  const auto native_size = GetNativeSize();
  if (native_size.cx <= 0 || native_size.cy <= 0)
    return;

  OpenGL::display_orientation = orientation;
  SetupViewport(PixelSize(OpenGL::window_size.x, OpenGL::window_size.y));
}
Beispiel #9
0
RawBitmap::RawBitmap(unsigned nWidth, unsigned nHeight)
  :width(nWidth), height(nHeight),
   corrected_width(CorrectedWidth(nWidth)),
   buffer(new RawColor[corrected_width * height]),
   texture(new GLTexture(PixelSize(corrected_width, nHeight)))
{
  assert(nWidth > 0);
  assert(nHeight > 0);

  texture->EnableInterpolation();

  AddSurfaceListener(*this);
}
void dng_image::SetPixelType (uint32 pixelType)
	{
	
	if (TagTypeSize (pixelType) != PixelSize ())
		{
		
		ThrowProgramError ("Cannot change pixel size for existing image");
		
		}
	
	fPixelType = pixelType;
	
	}
Beispiel #11
0
void PngFile::SetFromImage(const class Image2D &image, const class ColorMap &colorMap, long double normalizeFactor, long double zeroLevel) throw(IOException)
{
	png_bytep *row_pointers = RowPointers();
	for(unsigned long y=0;y<image.Height();y++) {
		for(unsigned long x=0;x<image.Width();x++) {
			int xa = x * PixelSize();
			row_pointers[y][xa]=colorMap.ValueToColorR((image.Value(x, y) - zeroLevel) * normalizeFactor);
			row_pointers[y][xa+1]=colorMap.ValueToColorG((image.Value(x, y) - zeroLevel) * normalizeFactor);
			row_pointers[y][xa+2]=colorMap.ValueToColorB((image.Value(x, y) - zeroLevel) * normalizeFactor);
			row_pointers[y][xa+3]=colorMap.ValueToColorA((image.Value(x, y) - zeroLevel) * normalizeFactor);
		}
	}
}
Beispiel #12
0
int main(int argc, char **argv)
{
  /* enable FreeType anti-aliasing, because we don't use dithering in
     this program */
  FreeType::mono = false;

  ScreenGlobalInit screen_init;
  Layout::Initialize({600, 800});

  Font::Initialise();
  Display::Rotate(DisplayOrientation::PORTRAIT);

  InitialiseFonts();

  {
    TopCanvas screen;
    screen.Create(PixelSize(100, 100), true, false);

    Canvas canvas = screen.Lock();
    if (canvas.IsDefined()) {
      /* all black first, to eliminate E-ink ghost images */
      canvas.Clear(COLOR_BLACK);
      screen.Flip();
      screen.Wait();

      /* disable dithering, render with 16 shades of gray, to make the
         (static) display more pretty */
      screen.SetEnableDither(false);

      /* draw the pictuer */
      canvas.ClearWhite();
      Draw(canvas);

      /* finish */
      screen.Unlock();
      screen.Flip();
      screen.Wait();
    }
  }

  /* now we can power off the Kobo; the picture remains on the
     screen */
  if (DetectKoboModel() == KoboModel::GLO_HD)
    //The GloHD needs -f to not clear screen
    execl("/sbin/poweroff", "poweroff", "-f", nullptr);
  else
    execl("/sbin/poweroff", "poweroff", nullptr);

  return 0;
}
Beispiel #13
0
bool COrder_Still::AutoAttackStand(CUnit &unit)
{
	//Wyrmgus start
//	if (unit.Type->CanAttack == false) {
	if (unit.CanAttack() == false) {
	//Wyrmgus end
		return false;
	}
	// Removed units can only attack in AttackRange, from bunker
	//Wyrmgus start
	//if unit is in a container which is attacking, and the container has a goal, use that goal (if possible) instead
//	CUnit *autoAttackUnit = AttackUnitsInRange(unit);
	CUnit *autoAttackUnit = unit.Container && unit.Container->CurrentAction() == UnitActionAttack && unit.Container->CurrentOrder()->HasGoal() ? unit.Container->CurrentOrder()->GetGoal() : AttackUnitsInRange(unit);
	//Wyrmgus end

	if (autoAttackUnit == nullptr) {
		return false;
	}
	// If unit is removed, use container's x and y
	const CUnit *firstContainer = unit.GetFirstContainer();
	if (firstContainer->MapDistanceTo(*autoAttackUnit) > unit.GetModifiedVariable(ATTACKRANGE_INDEX)) {
		return false;
	}
	//Wyrmgus start
//	if (GameSettings.Inside && CheckObstaclesBetweenTiles(unit.tilePos, autoAttackUnit->tilePos, MapFieldRocks | MapFieldForest) == false) {
	if (Map.IsLayerUnderground(autoAttackUnit->MapLayer->ID) && unit.GetModifiedVariable(ATTACKRANGE_INDEX) > 1 && CheckObstaclesBetweenTiles(unit.tilePos, autoAttackUnit->tilePos, MapFieldAirUnpassable, autoAttackUnit->MapLayer->ID) == false) {
	//Wyrmgus end
		return false;
	}
	this->State = SUB_STILL_ATTACK; // Mark attacking.
	this->SetGoal(autoAttackUnit);
	//Wyrmgus start
//	UnitHeadingFromDeltaXY(unit, autoAttackUnit->tilePos + autoAttackUnit->Type->GetHalfTileSize() - unit.tilePos);
	UnitHeadingFromDeltaXY(unit, PixelSize(PixelSize(autoAttackUnit->tilePos) * Map.GetMapLayerPixelTileSize(autoAttackUnit->MapLayer->ID)) + autoAttackUnit->GetHalfTilePixelSize() - PixelSize(PixelSize(unit.tilePos) * Map.GetMapLayerPixelTileSize(autoAttackUnit->MapLayer->ID)) - unit.GetHalfTilePixelSize());
	//Wyrmgus end
	return true;
}
Beispiel #14
0
void PngFile::Save(const Image2D &image, const ColorMap &colorMap) throw(IOException)
{
	long double normalizeFactor = image.GetMaxMinNormalizationFactor();
	
	png_bytep *row_pointers = RowPointers();
	
	for(unsigned long y=0;y<image.Height();++y) {
		for(unsigned long x=0;x<image.Width();++x) {
			int xa = x * PixelSize();
			row_pointers[y][xa]=colorMap.ValueToColorR(image.Value(x, y) * normalizeFactor);
			row_pointers[y][xa+1]=colorMap.ValueToColorG(image.Value(x, y) * normalizeFactor);
			row_pointers[y][xa+2]=colorMap.ValueToColorB(image.Value(x, y) * normalizeFactor);
			row_pointers[y][xa+3]=colorMap.ValueToColorA(image.Value(x, y) * normalizeFactor);
		}
	}
}
Beispiel #15
0
/* the main routine which arranges for the memory manager to call us back
 *  for each allocated block, and then asks the x server to display our
 *  updated image.
 */
static Error    
report_memory (struct dispinfo *d)
{
    int wsquares;		/* count of window squares */
    int mblocks;		/* count of memory blocks */

    /* mark all of memory free
     */
    memset (d->memory_pixel, color_free, WinSize(d));

    /* arrange for the memory manager to call us back with each allocated 
     *  block.  the memsee() routines set the pixels as allocated.
     */
    if (d->which == MEMORY_LOCAL) {
	DXDebugLocalAlloc(d->nproc, MEMORY_ALLOCATED, memsee, (Pointer)d);
    } else {
	DXDebugAlloc(d->which, MEMORY_ALLOCATED, memsee, (Pointer)d);
	if (d->smallsize > 0)
	    DXDebugAlloc(d->which, MEMORY_ALLOCATED, memsee1, (Pointer)d);
    }
	
    /* and finally, see if there are any squares at the end of the window
     *  which are beyond the end of the arena and are only there because
     *  the window is square and the number of rows had to be rounded up.
     */
    wsquares = WinSize(d) / PixelSize(d);
    mblocks = DivideRoundedUp(d->arena_size, d->bytes_vp);
    if (wsquares > mblocks)
	pix_set(d, (Pointer)((ubyte *)d->arena_base + d->arena_size), 
		(wsquares - mblocks) * d->bytes_vp, color_extra);

    
    /* finished image.  make it available to be displayed.
     */
    XPutImage (d->disp, d->wind, d->gc, d->memory_image, 0, 0, 0, 0, 
	       d->win_width, d->win_height);
    XFlush(d->disp);

    return OK;
}
Beispiel #16
0
void
TMagnify::MouseDown(BPoint where)
{
	BMessage *currentMsg = Window()->CurrentMessage();
	if (currentMsg->what == B_MOUSE_DOWN) {
		uint32 buttons = 0;
		currentMsg->FindInt32("buttons", (int32 *)&buttons);

		uint32 modifiers = 0;
		currentMsg->FindInt32("modifiers", (int32 *)&modifiers);

		if ((buttons & B_SECONDARY_MOUSE_BUTTON) || (modifiers & B_CONTROL_KEY)) {
			// secondary button was clicked or control key was down, show menu and return

			BPopUpMenu *menu = new BPopUpMenu(B_TRANSLATE("Info"));
			menu->SetFont(be_plain_font);
			BuildInfoMenu(menu);

			BMenuItem *selected = menu->Go(ConvertToScreen(where));
			if (selected)
				Window()->PostMessage(selected->Message()->what);
			delete menu;
			return;
		}

		// add a mousedown looper here

		int32 pixelSize = PixelSize();
		float x = where.x / pixelSize;
		float y = where.y / pixelSize;

		MoveSelectionTo(x, y);

		// draw the frozen image
		// update the info region

		fNeedToUpdate = true;
		Invalidate();
	}
}
Beispiel #17
0
dng_image::dng_image (const dng_rect &bounds,
				      uint32 planes,
				      uint32 pixelType)

	: 	fBounds    (bounds)
	,	fPlanes    (planes)
	,	fPixelType (pixelType)
	
	{
	if (bounds.IsEmpty () || planes == 0 || PixelSize () == 0)
		{
		
		#if qDNGValidate
		
		ReportError ("Fuzz: Attempt to create zero size image");
		
		#endif
		
		ThrowBadFormat ();
		
		}
		
	}
const PixelSize TestPlatformAbstraction::GetFontLineHeightFromCapsHeight(const std::string& fontFamily, const std::string& fontStyle, const CapsHeight& capsHeight) const
{
  mTrace.PushCall("GetFontLineHeightFromCapsHeight", "");
  // LineHeight will be bigger than CapsHeight, so return capsHeight + 1
  return PixelSize(capsHeight + 1);
}
Beispiel #19
0
void
DPXCodec::decompress(const DataChunk &data)
{
	MemoryFile file(data);
	
	DPXCodec_InStream istream(file);
	
	dpx::Reader dpx;
	
	dpx.SetInStream(&istream);
	
	const bool header_read = dpx.ReadHeader();
	
	if(header_read)
	{
		const int dpx_width = dpx.header.Width();
		const int dpx_height = dpx.header.Height();
		const int dpx_channels = dpx.header.ImageElementComponentCount(0);
		
		assert(dpx_width == _descriptor.getStoredWidth());
		assert(dpx_height == _descriptor.getStoredHeight());
		assert(dpx_channels == (_channels == DPX_RGBA ? 4 : 3));
		
		
		const Box2i dataW = dataWindow();
		
		if(dpx_width != (dataW.max.x - dataW.min.x + 1))
			throw MoxMxf::InputExc("Stored data is wrong width");

		if(dpx_height != (dataW.max.y - dataW.min.y + 1))
			throw MoxMxf::InputExc("Stored data is wrong height");
		
		
		const size_t pixsize = (_depth == DPX_8 ? sizeof(unsigned char) : sizeof(unsigned short));
		const size_t rowbytes = dpx_width * pixsize * dpx_channels;
		const size_t buffer_size = rowbytes * dpx_height;
		
		DataChunkPtr frame_data = new DataChunk(buffer_size);
		
		char *origin = (char *)frame_data->Data;
		
		FrameBufferPtr frame_buffer = new FrameBuffer(dataW);
		
		const PixelType pixel_type = (_depth == DPX_8 ? MoxFiles::UINT8 : MoxFiles::UINT16);
		const size_t bytes_per_subpixel = PixelSize(pixel_type);
		const size_t bytes_per_pixel = bytes_per_subpixel * dpx_channels;
	
		frame_buffer->insert("R", Slice(pixel_type, origin + (bytes_per_subpixel * 0), bytes_per_pixel, rowbytes));
		frame_buffer->insert("G", Slice(pixel_type, origin + (bytes_per_subpixel * 1), bytes_per_pixel, rowbytes));
		frame_buffer->insert("B", Slice(pixel_type, origin + (bytes_per_subpixel * 2), bytes_per_pixel, rowbytes));
		
		if(_channels == DPX_RGBA)
			frame_buffer->insert("A", Slice(pixel_type, origin + (bytes_per_subpixel * 3), bytes_per_pixel, rowbytes));
			
		frame_buffer->attachData(frame_data);
		
		
		dpx::Block block(0, 0, dpx_width - 1, dpx_height - 1);
		
		const dpx::Descriptor dpx_desc = dpx.header.ImageDescriptor(0);
		const dpx::DataSize dpx_size = (_depth == DPX_8 ? dpx::kByte : dpx::kWord);
		
		const bool image_read = dpx.ReadBlock((void *)origin, dpx_size, block, dpx_desc);
		
		if(image_read)
		{
			storeFrame(frame_buffer);
		}
		else
			assert(false);
	}
	else
		assert(false);
}
Beispiel #20
0
void
DPXCodec::compress(const FrameBuffer &frame)
{
	const PixelType pixel_type = (_depth == DPX_8 ? MoxFiles::UINT8 : MoxFiles::UINT16);
	const size_t bytes_per_subpixel = PixelSize(pixel_type);
	const int num_channels = (_channels == DPX_RGBA ? 4 : 3);
	
	const Box2i dataW = dataWindow();
	
	const int width = (dataW.max.x - dataW.min.x + 1);
	const int height = (dataW.max.y - dataW.min.y + 1);
	
	const size_t bytes_per_pixel = bytes_per_subpixel * num_channels;
	const size_t rowbytes = bytes_per_pixel * width;
	const size_t buffer_size = rowbytes * height;
	
	
	DataChunk data(buffer_size);
	
	FrameBuffer frame_buffer(dataW);
		
	char *origin = (char *)data.Data;
	
	frame_buffer.insert("R", Slice(pixel_type, origin + (bytes_per_subpixel * 0), bytes_per_pixel, rowbytes));
	frame_buffer.insert("G", Slice(pixel_type, origin + (bytes_per_subpixel * 1), bytes_per_pixel, rowbytes));
	frame_buffer.insert("B", Slice(pixel_type, origin + (bytes_per_subpixel * 2), bytes_per_pixel, rowbytes));
	
	if(_channels == DPX_RGBA)
		frame_buffer.insert("A", Slice(pixel_type, origin + (bytes_per_subpixel * 3), bytes_per_pixel, rowbytes));
	
	
	frame_buffer.copyFromFrame(frame);
	
	
	MemoryFile file(buffer_size);
	
	DPXCodec_OutStream ostream(file);
	
	dpx::Writer dpx;
	
	dpx.SetOutStream(&ostream);
	
	dpx.SetFileInfo("MOX",	// fileName
					NULL,			// creation time (set by libdpx)
					"DPXcodec, part of MOX", // creator
					NULL,			// project
					NULL,			// copyright
					~0,				// encryption key (0xffffffff means no encryption)
					false);			// don't swap byte order
	
	dpx.SetImageInfo(width, height);
	
	dpx.header.SetAspectRatio(0, _pixelAspectRatio.Numerator);
	dpx.header.SetAspectRatio(1, _pixelAspectRatio.Denominator);
	
	dpx.header.SetFrameRate((dpx::R32)_frameRate.Numerator / (dpx::R32)_frameRate.Denominator);
	
	//dpx.header.SetInterlace(info->field_label->type == FIEL_Type_FRAME_RENDERED ? 0 : 1);
	
	const unsigned int bit_depth = (_depth == DPX_8 ? 8 :
									_depth == DPX_10 ? 10 :
									_depth == DPX_12 ? 12 :
									_depth == DPX_16 ? 16 :
									10);
	
	const dpx::Descriptor dpx_desc = (_channels == DPX_RGBA ? dpx::kRGBA : dpx::kRGB);
	const dpx::Packing packing = ((bit_depth == 8 || bit_depth == 16) ? dpx::kPacked : dpx::kFilledMethodA);
	
	const dpx::Characteristic transfer = dpx::kLogarithmic;
	const dpx::Characteristic colorimetric = dpx::kLogarithmic;
	
	dpx.SetElement(0, dpx_desc, bit_depth, transfer, colorimetric, packing);
	
	
	const bool wrote_header = dpx.WriteHeader();
	
	if(!wrote_header)
		throw MoxMxf::ArgExc("Error writing header");
	

	const dpx::DataSize size = (pixel_type == MoxFiles::UINT16 ? dpx::kWord : dpx::kByte);
	
	const bool wrote_element = dpx.WriteElement(0, data.Data, size);
	
	if(!wrote_element)
		throw MoxMxf::ArgExc("Error writing image");
	
	
	const bool wrote_finish = dpx.Finish();
	
	if(!wrote_finish)
		throw MoxMxf::ArgExc("Error writing finish");
	
	
	storeData( file.getDataChunk() );
}
Beispiel #21
0
static PixelSize
GetSize(const struct fb_var_screeninfo &vinfo)
{
  return PixelSize(GetWidth(vinfo), GetHeight(vinfo));
}
Beispiel #22
0
void
JPEGLSCodec::decompress(const DataChunk &data)
{
	ByteStreamInfo inStream = FromByteArray(data.Data, data.Size);
	
	
	struct JlsParameters info;
	
	JLS_ERROR err = JpegLsReadHeaderStream(inStream, &info);
	
	if(err == OK)
	{
		const int width = info.width;
		const int height = info.height;
		
		assert(info.components == (_channels == JPEGLS_RGBA ? 4 : 3));
		assert(info.colorTransform == COLORXFORM_NONE);
		
		const PixelType pixType = (_depth == JPEGLS_8 ? UINT8 :
									_depth == JPEGLS_10 ? UINT10 :
									_depth == JPEGLS_12 ? UINT12 :
									_depth == JPEGLS_16 ? UINT16 :
									UINT8);
		
		const size_t pixSize = PixelSize(pixType);
		const unsigned int bitDepth = PixelBits(pixType);
		
		assert(info.bitspersample == bitDepth);
									
		const size_t pixelSize = (info.components * PixelSize(pixType));
		const size_t rowBytes = (width * pixelSize);
		const size_t bufSize = (height * rowBytes);
		
		DataChunkPtr frameData = new DataChunk(bufSize);
		
		char *buf = (char *)frameData->Data;
		
		const Box2i dataW = dataWindow();
		
		assert(width == (dataW.max.x - dataW.min.x + 1));
		assert(height == (dataW.max.y - dataW.min.y + 1));
		assert(dataW.min.x == 0);
		assert(dataW.min.y == 0);
			
		FrameBufferPtr frameBuffer = new FrameBuffer(dataW);
		
		frameBuffer->insert("R", Slice(pixType, &buf[0 * pixSize], pixelSize, rowBytes));
		frameBuffer->insert("G", Slice(pixType, &buf[1 * pixSize], pixelSize, rowBytes));
		frameBuffer->insert("B", Slice(pixType, &buf[2 * pixSize], pixelSize, rowBytes));
		
		if(info.components >= 4)
			frameBuffer->insert("A", Slice(pixType, &buf[3 * pixSize], pixelSize, rowBytes));
		
		frameBuffer->attachData(frameData);
		
		
		ByteStreamInfo outStream = FromByteArray(frameData->Data, frameData->Size);
		
		
		err = JpegLsDecodeStream(outStream, inStream, &info);
		
		if(err == OK)
		{
			storeFrame(frameBuffer);
		}
	}
	
	if(err != OK)
		throw MoxMxf::ArgExc("JPEG-LS decompression error");
}
Beispiel #23
0
void
JPEGLSCodec::compress(const FrameBuffer &frame)
{
	const Box2i dataW = dataWindow();
	
	const int width = (dataW.max.x - dataW.min.x + 1);
	const int height = (dataW.max.y - dataW.min.y + 1);

	const PixelType pixType = (_depth == JPEGLS_8 ? UINT8 :
								_depth == JPEGLS_10 ? UINT10 :
								_depth == JPEGLS_12 ? UINT12 :
								_depth == JPEGLS_16 ? UINT16 :
								UINT8);
	
	const size_t pixSize = PixelSize(pixType);
	const unsigned int bitDepth = PixelBits(pixType);
	const int numChannels = (_channels == JPEGLS_RGBA ? 4 : 3);
	
	const size_t tempPixelSize = (numChannels * pixSize);
	const size_t tempRowbytes = (tempPixelSize * width);
	const size_t tempBufSize = (tempRowbytes * height);
	
	DataChunk dataChunk(tempBufSize);
	
	char *tempBuffer = (char *)dataChunk.Data;
	
	assert(dataW.min.x == 0 && dataW.min.y == 0);
	
	FrameBuffer tempFrameBuffer(dataW);
	
	tempFrameBuffer.insert("R", Slice(pixType, &tempBuffer[0 * pixSize], tempPixelSize, tempRowbytes));
	tempFrameBuffer.insert("G", Slice(pixType, &tempBuffer[1 * pixSize], tempPixelSize, tempRowbytes));
	tempFrameBuffer.insert("B", Slice(pixType, &tempBuffer[2 * pixSize], tempPixelSize, tempRowbytes));
	
	if(_channels == JPEGLS_RGBA)
		tempFrameBuffer.insert("A", Slice(pixType, &tempBuffer[3 * pixSize], tempPixelSize, tempRowbytes));
	
	tempFrameBuffer.copyFromFrame(frame);
	
	
	JlsParameters params = JlsParameters();
	
	params.width = width;
	params.height = height;
	params.bitspersample = bitDepth;
	//params.bytesperline = (tempRowbytes / 3);
	params.components = numChannels;
	params.allowedlossyerror = 0; // always lossless
	params.ilv = ILV_SAMPLE;
	params.colorTransform = COLORXFORM_NONE;
	//params.outputBgr = 0;
	
	/*
	params.custom.MAXVAL = 255;
	params.custom.T1 = 0;
	params.custom.T2 = 0;
	params.custom.T3 = 0;
	params.custom.RESET = 1;
	
	
	params.jfif.Ver = 123;
	params.jfif.units = 0;
	params.jfif.XDensity = 72;
	params.jfif.YDensity = 72;
	params.jfif.Xthumb = 0;
	params.jfif.Ythumb = 0;
	params.jfif.pdataThumbnail = NULL;
	*/
	
	
	ByteStreamInfo inStream = FromByteArray(dataChunk.Data, dataChunk.Size);
	
	DataChunkPtr outDataChunk = new DataChunk(tempBufSize);
	
	
	size_t bytesWritten = 0;
	
	JLS_ERROR err = OK;
	
	do
	{
		ByteStreamInfo outStream = FromByteArray(outDataChunk->Data, outDataChunk->Size);
		
		err = JpegLsEncodeStream(outStream, &bytesWritten, inStream, &params);
		
		if(err == CompressedBufferTooSmall)
		{
			outDataChunk->Resize(2 * outDataChunk->Size, false);
		}
	
	}while(err == CompressedBufferTooSmall);
	
	assert(err != TooMuchCompressedData);
	
	
	if(err == OK)
	{
		assert(bytesWritten > 0);
	
		outDataChunk->Resize(bytesWritten);
		
		storeData(outDataChunk);
	}
	else
		throw MoxMxf::ArgExc("JPEG-LS compression error");
}
Beispiel #24
0
void
JPEGCodec::compress(const FrameBuffer &frame)
{
	struct jpeg_error_mgr jerr;
	
	jerr.error_exit = my_error_exit;
	jerr.emit_message = my_emit_message;
	jerr.output_message = my_output_message;
	jerr.format_message = my_format_message;
	jerr.reset_error_mgr = my_reset_error_mgr;
	
	jerr.trace_level = 0;
	jerr.num_warnings = 0;
	jerr.msg_code = 0;
	
	jerr.jpeg_message_table = jpeg_std_message_table;
	jerr.last_jpeg_message = (int) JMSG_LASTMSGCODE - 1;
	
	jerr.addon_message_table = NULL;
	jerr.first_addon_message = 0;
	jerr.last_jpeg_message = 0;
	
	
	
	struct jpeg_compress_struct cinfo;
	
	cinfo.err = &jerr;
	
	jpeg_create_compress(&cinfo);
	
	
	my_destination_mgr mgr;
	
	mgr.outfile = new MemoryFile;
	mgr.buffer = NULL;
	mgr.bufferSize = 0;
	
	mgr.pub.init_destination = my_init_destination;
	mgr.pub.empty_output_buffer = my_empty_output_buffer;
	mgr.pub.term_destination = my_term_destination;
	
	
	cinfo.dest = (jpeg_destination_mgr *)&mgr;
	
	
	const Box2i dataW = dataWindow();
	
	const int width = (dataW.max.x - dataW.min.x + 1);
	const int height = (dataW.max.y - dataW.min.y + 1);
	
	cinfo.image_width = width;
	cinfo.image_height = height;
	cinfo.input_components = 3;
	cinfo.in_color_space = JCS_RGB;
	
	jpeg_set_defaults(&cinfo);
	
	
	jpeg_set_quality(&cinfo, _quality, TRUE);
	
	
	bool success = true;
	
	try
	{
		jpeg_start_compress(&cinfo, TRUE);
		
		
		const size_t tempPixelSize = (3 * PixelSize(UINT8));
		const size_t tempRowbytes = (tempPixelSize * width);
		const size_t tempBufSize = (tempRowbytes * height);
		
		DataChunk dataChunk(tempBufSize);
		
		char *tempBuffer = (char *)dataChunk.Data;
		
		FrameBuffer tempFrameBuffer(dataW);
		
		tempFrameBuffer.insert("R", Slice(UINT8, &tempBuffer[0], tempPixelSize, tempRowbytes));
		tempFrameBuffer.insert("G", Slice(UINT8, &tempBuffer[1], tempPixelSize, tempRowbytes));
		tempFrameBuffer.insert("B", Slice(UINT8, &tempBuffer[2], tempPixelSize, tempRowbytes));
		
		tempFrameBuffer.copyFromFrame(frame);
		
		
		JSAMPARRAY scanlines = (JSAMPARRAY)malloc(height * sizeof(JSAMPROW));
		
		if(scanlines == NULL)
			throw MoxMxf::NullExc("out of memory");
		
		for(int y=0; y < height; y++)
		{
			scanlines[y] = (JSAMPROW)(tempBuffer + (y * tempRowbytes));
		}
		
		
		const JDIMENSION linesWrote = jpeg_write_scanlines(&cinfo, scanlines, height);
		
		assert(linesWrote == height);
		
		
		jpeg_finish_compress(&cinfo);
		
		
		assert(jerr.msg_code == 0);
		
		storeData( mgr.outfile->getDataChunk() );
		
		
		free(scanlines);
	}
	catch(...)
	{
		success = false;
	}
	
	
	jpeg_destroy_compress(&cinfo);
	
	
	if(mgr.buffer != NULL)
		free(mgr.buffer);
	
	delete mgr.outfile;
	
	
	if(!success)
		throw MoxMxf::ArgExc("JPEG compression error");
}
Beispiel #25
0
void
JPEGCodec::decompress(const DataChunk &data)
{
	struct jpeg_error_mgr jerr;
	
	jerr.error_exit = my_error_exit;
	jerr.emit_message = my_emit_message;
	jerr.output_message = my_output_message;
	jerr.format_message = my_format_message;
	jerr.reset_error_mgr = my_reset_error_mgr;
	
	jerr.trace_level = 0;
	jerr.num_warnings = 0;
	jerr.msg_code = 0;
	
	jerr.jpeg_message_table = jpeg_std_message_table;
	jerr.last_jpeg_message = (int) JMSG_LASTMSGCODE - 1;
	
	jerr.addon_message_table = NULL;
	jerr.first_addon_message = 0;
	jerr.last_jpeg_message = 0;
	
	
	my_source_mgr mgr;
	
	mgr.infile = new MemoryFile(data);
	mgr.buffer = (JOCTET *)malloc(4096 * sizeof(JOCTET));
	mgr.bufferSize = 4096;
	mgr.pub.bytes_in_buffer = 0;
	mgr.pub.next_input_byte = NULL;
	
	if(mgr.buffer == NULL)
		throw MoxMxf::NullExc("out of memory");
	
	mgr.pub.init_source = my_init_source;
	mgr.pub.fill_input_buffer = my_fill_input_buffer;
	mgr.pub.skip_input_data = my_skip_input_data;
	mgr.pub.resync_to_restart = jpeg_resync_to_restart;
	mgr.pub.term_source = my_term_source;
	
	
	struct jpeg_decompress_struct cinfo;
	
	cinfo.err = &jerr;
	
	jpeg_create_decompress(&cinfo);
	
	
	cinfo.src = (jpeg_source_mgr *)&mgr;
	
	
	bool success = true;
	
	try
	{
		const int status = jpeg_read_header(&cinfo, TRUE);
		
		if(status == JPEG_HEADER_OK)
		{
			jpeg_start_decompress(&cinfo);
			
			const JDIMENSION width = cinfo.image_width;
			const JDIMENSION height = cinfo.image_height;
			
			assert(cinfo.num_components == 3);
			assert(cinfo.out_color_space == JCS_RGB);
			
			
			const size_t pixelSize = (3 * PixelSize(UINT8));
			const size_t rowBytes = (width * pixelSize);
			const size_t bufSize = (height * rowBytes);
			
			DataChunkPtr frameData = new DataChunk(bufSize);
			
			char *buf = (char *)frameData->Data;
			
			const Box2i dataW = dataWindow();
			
			assert(width == (dataW.max.x - dataW.min.x + 1));
			assert(height == (dataW.max.y - dataW.min.y + 1));
			assert(dataW.min.x == 0);
			assert(dataW.min.y == 0);
				
			FrameBufferPtr frameBuffer = new FrameBuffer(dataW);
			
			frameBuffer->insert("R", Slice(UINT8, &buf[0], pixelSize, rowBytes));
			frameBuffer->insert("G", Slice(UINT8, &buf[1], pixelSize, rowBytes));
			frameBuffer->insert("B", Slice(UINT8, &buf[2], pixelSize, rowBytes));
			
			frameBuffer->attachData(frameData);
			
			
			JSAMPARRAY scanlines = (JSAMPARRAY)malloc(height * sizeof(JSAMPROW));
			
			if(scanlines == NULL)
				throw MoxMxf::NullExc("out of memory");
			
			for(int y=0; y < height; y++)
			{
				scanlines[y] = (JSAMPROW)(buf + (y * rowBytes));
			}
			
			
			JDIMENSION linesRead = 0;
			
			while(linesRead < height)
			{
				linesRead += jpeg_read_scanlines(&cinfo, &scanlines[linesRead], height - linesRead);
			}
			
			
			free(scanlines);
			
			jpeg_finish_decompress(&cinfo);
			
			
			storeFrame(frameBuffer);
		}
		else
			throw MoxMxf::ArgExc("Error reading header");
	}
	catch(...)
	{
		success = false;
	}
	
	
	jpeg_destroy_decompress(&cinfo);
	
	
	free(mgr.buffer);
	
	delete mgr.infile;
	
	
	if(!success)
		throw MoxMxf::ArgExc("JPEG decompression error");
}
Beispiel #26
0
bool
TopWindow::OnEvent(const Event &event)
{
  switch (event.type) {
    Window *w;

  case Event::NOP:
  case Event::USER:
  case Event::CALLBACK:
    break;

  case Event::CLOSE:
    OnClose();
    break;

  case Event::KEY_DOWN:
    w = GetFocusedWindow();
    if (w == nullptr)
      w = this;

    return w->OnKeyDown(event.param);

  case Event::KEY_UP:
    w = GetFocusedWindow();
    if (w == nullptr)
      w = this;

    return w->OnKeyUp(event.param);

  case Event::MOUSE_MOTION:
#ifdef DRAW_MOUSE_CURSOR
    /* redraw to update the mouse cursor position */
    Invalidate();
#endif

    // XXX keys
    return OnMouseMove(event.point, 0);

  case Event::MOUSE_DOWN:
    return double_click.Check(event.point)
      ? OnMouseDouble(event.point)
      : OnMouseDown(event.point);

  case Event::MOUSE_UP:
    double_click.Moved(event.point);

    return OnMouseUp(event.point);

  case Event::MOUSE_WHEEL:
    return OnMouseWheel(event.point, (int)event.param);

#ifdef USE_X11
  case Event::RESIZE:
    if (screen->CheckResize(PixelSize(event.point.x, event.point.y)))
      Resize(screen->GetSize());
    return true;

  case Event::EXPOSE:
    Invalidate();
    return true;
#endif
  }

  return false;
}
PixelSize CUnitType::GetPixelSize() const
{
	return PixelSize(TileWidth * PixelTileSize.x, TileHeight * PixelTileSize.y);
}
Beispiel #28
0
 gcc_pure
 PixelSize GetRecommendedSize() const {
   return PixelSize(columns[length - 1].right, bottom + top);
 }