Ejemplo n.º 1
0
bool
StructuredCloneData::Copy(const StructuredCloneData& aData)
{
  if (!aData.mData) {
    return true;
  }

  uint64_t* data = static_cast<uint64_t*>(js_malloc(aData.mDataLength));
  if (!data) {
    return false;
  }

  memcpy(data, aData.mData, aData.mDataLength);

  mData = data;
  mDataLength = aData.mDataLength;
  mDataOwned = eJSAllocated;

  MOZ_ASSERT(BlobImpls().IsEmpty());
  BlobImpls().AppendElements(aData.BlobImpls());

  MOZ_ASSERT(GetImages().IsEmpty());

  return true;
}
bool
StructuredCloneIPCHelper::Copy(const StructuredCloneIPCHelper& aHelper)
{
  if (!aHelper.mData) {
    return true;
  }

  uint64_t* data = static_cast<uint64_t*>(malloc(aHelper.mDataLength));
  if (!data) {
    return false;
  }

  memcpy(data, aHelper.mData, aHelper.mDataLength);

  mData = data;
  mDataLength = aHelper.mDataLength;
  mDataOwned = eAllocated;

  MOZ_ASSERT(BlobImpls().IsEmpty());
  BlobImpls().AppendElements(aHelper.BlobImpls());

  MOZ_ASSERT(GetImages().IsEmpty());

  return true;
}
Ejemplo n.º 3
0
int CPicFlowWidget::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QWidget::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: LeftArrowReleased(); break;
        case 1: RightArrowReleased(); break;
        case 2: scrollBarVal((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 3: DecrementVal((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 4: IncrementVal((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 5: StartVal((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 6: SetItemClickedHF((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 7: GetImages((*reinterpret_cast< QList<QImage>(*)>(_a[1]))); break;
        case 8: ShowSlide((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 9: moveScrollBarLeft(); break;
        case 10: moveScrollBarRight(); break;
        case 11: scrollBarReleased(); break;
        case 12: GetItemClickedHF((*reinterpret_cast< int(*)>(_a[1]))); break;
        default: ;
        }
        _id -= 13;
    }
    return _id;
}
bool
StructuredCloneHelper::WriteCallback(JSContext* aCx,
                                     JSStructuredCloneWriter* aWriter,
                                     JS::Handle<JSObject*> aObj)
{
  if (!mSupportsCloning) {
    return false;
  }

  // See if this is a File/Blob object.
  {
    Blob* blob = nullptr;
    if (NS_SUCCEEDED(UNWRAP_OBJECT(Blob, aObj, blob))) {
      BlobImpl* blobImpl = blob->Impl();
      if (JS_WriteUint32Pair(aWriter, SCTAG_DOM_BLOB,
                             mBlobImplArray.Length())) {
        mBlobImplArray.AppendElement(blobImpl);
        return true;
      }

      return false;
    }
  }

  {
    FileList* fileList = nullptr;
    if (NS_SUCCEEDED(UNWRAP_OBJECT(FileList, aObj, fileList))) {
      // A FileList is serialized writing the X number of elements and the offset
      // from mBlobImplArray. The Read will take X elements from mBlobImplArray
      // starting from the offset.
      if (!JS_WriteUint32Pair(aWriter, SCTAG_DOM_FILELIST,
                              fileList->Length()) ||
          !JS_WriteUint32Pair(aWriter, 0,
                              mBlobImplArray.Length())) {
        return false;
      }

      for (uint32_t i = 0; i < fileList->Length(); ++i) {
        mBlobImplArray.AppendElement(fileList->Item(i)->Impl());
      }

      return true;
    }
  }

  // See if this is an ImageBitmap object.
  {
    ImageBitmap* imageBitmap = nullptr;
    if (NS_SUCCEEDED(UNWRAP_OBJECT(ImageBitmap, aObj, imageBitmap))) {
      return ImageBitmap::WriteStructuredClone(aWriter,
                                               GetImages(),
                                               imageBitmap);
    }
  }

  return NS_DOMWriteStructuredClone(aCx, aWriter, aObj, nullptr);
}
Ejemplo n.º 5
0
// Internal function used to load the Gif.
ILboolean iLoadGifInternal()
{
	GIFHEAD	Header;
	ILpal	GlobalPal;

	if (iCurImage == NULL) {
		ilSetError(IL_ILLEGAL_OPERATION);
		return IL_FALSE;
	}

	GlobalPal.Palette = NULL;
	GlobalPal.PalSize = 0;

	//read header
	iread(&Header.Sig, 1, 6);
	Header.Width = GetLittleUShort();
	Header.Height = GetLittleUShort();
	Header.ColourInfo = igetc();
	Header.Background = igetc();
	Header.Aspect = igetc();

	if (!strnicmp(Header.Sig, "GIF87A", 6)) {
		GifType = GIF87A;
	}
	else if (!strnicmp(Header.Sig, "GIF89A", 6)) {
		GifType = GIF89A;
	}
	else {
		ilSetError(IL_INVALID_FILE_HEADER);
		return IL_FALSE;
	}

	if (!ilTexImage(Header.Width, Header.Height, 1, 1, IL_COLOUR_INDEX, IL_UNSIGNED_BYTE, NULL))
		return IL_FALSE;
	iCurImage->Origin = IL_ORIGIN_UPPER_LEFT;

	// Check for a global colour map.
	if (Header.ColourInfo & (1 << 7)) {
		if (!iGetPalette(Header.ColourInfo, &GlobalPal)) {
			return IL_FALSE;
		}
	}

	if (!GetImages(&GlobalPal, &Header))
		return IL_FALSE;

	if (GlobalPal.Palette && GlobalPal.PalSize)
		ifree(GlobalPal.Palette);
	GlobalPal.Palette = NULL;
	GlobalPal.PalSize = 0;

	ilFixImage();

	return IL_TRUE;
}
Ejemplo n.º 6
0
// Internal function used to load the Gif.
ILboolean iLoadGifInternal(ILimage* image)
{
	GIFHEAD	Header;
	ILpal	GlobalPal;

	if (image == NULL) {
		ilSetError(IL_ILLEGAL_OPERATION);
		return IL_FALSE;
	}

	GlobalPal.Palette = NULL;
	GlobalPal.PalSize = 0;

	// Read header
	iCurImage->io.read(iCurImage->io.handle, &Header, 1, sizeof(Header));
	#ifdef __BIG_ENDIAN__
	iSwapUShort(Header.Width);
	iSwapUShort(Header.Height);
	#endif

	if (strnicmp(Header.Sig, "GIF87A", 6) != 0 
	&&  strnicmp(Header.Sig, "GIF89A", 6) != 0) 
	{
		ilSetError(IL_INVALID_FILE_HEADER);
		return IL_FALSE;
	}

	if (!ilTexImage(Header.Width, Header.Height, 1, 1, IL_COLOUR_INDEX, IL_UNSIGNED_BYTE, NULL))
   //if (!ilTexImage(Header.Width, Header.Height, 1, 1, IL_RGB, IL_UNSIGNED_BYTE, NULL))
		return IL_FALSE;
	image->Origin = IL_ORIGIN_UPPER_LEFT;

	// Check for a global colour map.
	if (Header.ColourInfo & (1 << 7)) {
		if (!iGetPalette(Header.ColourInfo, &GlobalPal, NULL)) {
			return IL_FALSE;
		}
	}

	if (!GetImages(image, &GlobalPal, &Header))
		return IL_FALSE;

	if (GlobalPal.Palette && GlobalPal.PalSize)
		ifree(GlobalPal.Palette);
	GlobalPal.Palette = NULL;
	GlobalPal.PalSize = 0;

	return ilFixImage();
}
Ejemplo n.º 7
0
bool compress_and_save(const std::shared_ptr<Spec> spec)
{
    HRESULT hr;

    hr = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
    if (FAILED(hr)) {
        printf(_T("  CoInitializeEx failed. ret = 0x%x\n"), hr);
        return false;
    }

    auto image = load_image_from_file(spec->input_name);
    if (!image) {
        return false;
    }

    bool with_ispc_texcomp = true;
    auto& meta = image->GetMetadata();
    if (!ISALIGN(meta.width, 4) || !ISALIGN(meta.height, 4) || is_dither_compression(spec)) {
        with_ispc_texcomp = false;
    }

    image = with_ispc_texcomp ? compress_with_ispc(std::move(image), spec) :
                                compress_with_dxtex(std::move(image), spec);

    int res = S_FALSE;
    if (image) {
        hr = DirectX::SaveToDDSFile(image->GetImages(), image->GetImageCount(), image->GetMetadata(),
                                    DirectX::DDS_FLAGS_NONE, spec->output_name.c_str());
        if (FAILED(hr)) {
            printf(_T("  DirectX::SaveToDDSFile failed. ret = 0x%x\n"), hr);
        }
        else {
            printf(_T("done.\n"));
            res = S_OK;
        }
    }
    ::CoUninitialize();
    return res == S_OK ? true : false;
}
JSObject*
StructuredCloneHelper::ReadCallback(JSContext* aCx,
                                    JSStructuredCloneReader* aReader,
                                    uint32_t aTag,
                                    uint32_t aIndex)
{
  MOZ_ASSERT(mSupportsCloning);

  if (aTag == SCTAG_DOM_BLOB) {
    MOZ_ASSERT(aIndex < mBlobImplArray.Length());
    nsRefPtr<BlobImpl> blobImpl =  mBlobImplArray[aIndex];

    // nsRefPtr<File> needs to go out of scope before toObjectOrNull() is
    // called because the static analysis thinks dereferencing XPCOM objects
    // can GC (because in some cases it can!), and a return statement with a
    // JSObject* type means that JSObject* is on the stack as a raw pointer
    // while destructors are running.
    JS::Rooted<JS::Value> val(aCx);
    {
      nsRefPtr<Blob> blob = Blob::Create(mParent, blobImpl);
      if (!ToJSValue(aCx, blob, &val)) {
        return nullptr;
      }
    }

    return &val.toObject();
  }

  if (aTag == SCTAG_DOM_FILELIST) {
    JS::Rooted<JS::Value> val(aCx);
    {
      nsRefPtr<FileList> fileList = new FileList(mParent);

      // |aIndex| is the number of BlobImpls to use from |offset|.
      uint32_t tag, offset;
      if (!JS_ReadUint32Pair(aReader, &tag, &offset)) {
        return nullptr;
      }
      MOZ_ASSERT(tag == 0);

      for (uint32_t i = 0; i < aIndex; ++i) {
        uint32_t index = offset + i;
        MOZ_ASSERT(index < mBlobImplArray.Length());

        nsRefPtr<BlobImpl> blobImpl = mBlobImplArray[index];
        MOZ_ASSERT(blobImpl->IsFile());

        nsRefPtr<File> file = File::Create(mParent, blobImpl);
        if (!fileList->Append(file)) {
          return nullptr;
        }
      }

      if (!ToJSValue(aCx, fileList, &val)) {
        return nullptr;
      }
    }

    return &val.toObject();
  }

  if (aTag == SCTAG_DOM_IMAGEBITMAP) {
     // Get the current global object.
     // This can be null.
     nsCOMPtr<nsIGlobalObject> parent = do_QueryInterface(mParent);
     // aIndex is the index of the cloned image.
     return ImageBitmap::ReadStructuredClone(aCx, aReader,
                                             parent, GetImages(), aIndex);
   }

  return NS_DOMReadStructuredClone(aCx, aReader, aTag, aIndex, nullptr);
}
Ejemplo n.º 9
0
BOOL CXTPSkinManagerClass::GetThemePartSize(int iPartId, int iStateId, RECT *pRect, int eSize, SIZE* pSize)
{
    if (GetThemeEnumValue(iPartId, iStateId, TMT_BGTYPE) != BT_IMAGEFILE)
        return FALSE;

    int nImageFile = (GetThemeEnumValue(iPartId, iStateId, TMT_IMAGESELECTTYPE) != IST_NONE) &&
                     (GetThemeEnumValue(iPartId, iStateId, TMT_GLYPHTYPE, GT_NONE) == GT_NONE) ?
                     TMT_IMAGEFILE1: TMT_IMAGEFILE;

    CString strImageFile = GetThemeString(iPartId, iStateId, nImageFile);
    if (strImageFile.IsEmpty())
    {
        if (nImageFile != TMT_IMAGEFILE1)
            return FALSE;

        strImageFile = GetThemeString(iPartId, iStateId, TMT_IMAGEFILE);
        if (strImageFile.IsEmpty())
            return FALSE;

    }


    CXTPSkinImage* pImage = GetImages()->LoadFile(m_pSchema->GetResourceFile(), strImageFile);
    if (!pImage)
    {
        return FALSE;
    }

    int nImageCount = GetThemeInt(iPartId, iStateId, TMT_IMAGECOUNT, 1);
    if (nImageCount < 1)
        nImageCount = 1;

    BOOL bHorizontalImageLayout = GetThemeEnumValue(iPartId, iStateId, TMT_IMAGELAYOUT, IL_HORIZONTAL) == IL_HORIZONTAL;

    CSize sz(pImage->GetWidth(), pImage->GetHeight());
    if (bHorizontalImageLayout) sz.cx /= nImageCount;
    else sz.cy /= nImageCount;

    if (eSize == TS_TRUE)
    {
        *pSize = sz;
    }
    if (eSize == TS_DRAW)
    {
        if (GetThemeEnumValue(iPartId, iStateId, TMT_SIZINGTYPE, ST_STRETCH) == ST_TRUESIZE)
        {
            *pSize = sz;
            return TRUE;
        }

        if (!pRect)
        {
            pSize->cy = 0;
            pSize->cx = 0;
        }
        else
        {
            pSize->cy = pRect->bottom - pRect->top;
            pSize->cx = pRect->right - pRect->left;
        }

        if (GetThemeBool(iPartId, iStateId, TMT_UNIFORMSIZING, FALSE))
        {
            pSize->cx = MulDiv(pSize->cy, sz.cx, sz.cy);
        }
    }

    return TRUE;
}
Ejemplo n.º 10
0
int main(){
	int gd=DETECT, gm;
	int Return=0;
	char Key, ScanCode;
	int Counter=0;                          //Divide total delay & take multiple input
	initgraph(&gd, &gm,"c:\\tc\\bgi");      //initialize graphics mode
	randomize();                            //Randomize block's shapes & color
	cleardevice();                          //clear screen
	InitPalette();                          //for setting color pallete
	InitMatrix();                           //Initialize Matrix
	GetImages();                            //Saving the images
	StartScreen();                          //for start screen
	cleardevice();                          //clear screen
	AssignShape(GetRandomShape(), GetRandomColor());      //for the falling block
	NextShape=GetRandomShape();
	NextColor=GetRandomColor();                                         	DisplayScreen();                        //Show main screen
	DisplayNextShape();                     //show next brick
	MoveBlock(LEFT);                        //keep the block on center & check game over
	while(kbhit()) getch();  		//empty the keyboard input
	while (!Quit && !GameOver) {            //Moving the blocks down
		if(++Counter >= Speed)          //For controling the speed
		{	Counter=0;
			MoveBlock(DOWN);
			SoundDrop();
		}
		if(kbhit())                     //For the arrow keys
		{  Key = getch();
		   if(Key == 0)
		   {	   ScanCode = getch();
			   if(ScanCode == KEY_UP)
					RotateBlock();
			   else if(ScanCode == KEY_LEFT)
					MoveBlock(LEFT);
			   else if(ScanCode == KEY_RIGHT)
					MoveBlock(RIGHT);
			   else if(ScanCode == KEY_DOWN)
			   {		Score++;         //increase score
					PrintScore();
					MoveBlock(DOWN);
			   }
			   if(!Return)
				   SoundDrop();
			   Return = 0;
		   }
		   else if(Key == KEY_ENTER || Key == KEY_SPACE)   //Rotating bricks
				RotateBlock();
		   else if(Key == 'P' || Key == 'p')      //For pause
		   {	  MessageBox("  Paused");
			  while(kbhit()) getch();         //clear the keyboard input
			  for(int x=0; x<COLS; x++)
				 for(int y=0; y<ROWS; y++)
					PreviousScreenLayout[x][y] -= 1;    //Clear the present screen layout to refresh the whole screen
			  UpdateScreen();                //refresh screen
		   }
		   else if(Key == KEY_ESC)                                      //For quit
		   {	  char ret = MessageBox("Are you sure, you want to Quit?", 563, 2);
			  if(ret == 'y' || ret == 'Y' || ret == KEY_ENTER)
			  {	  Quit = 1;
				  break;
			  }
			  cleardevice();                              //Clear the message box
			  while(kbhit()) getch();  		      //Clear the keyboard input
			  for(int x=0; x<COLS; x++)
				 for(int y=0; y<ROWS; y++)
					PreviousScreenLayout[x][y] -= 1;    // Clear the present screen layout to refresh the whole screen
			  UpdateScreen();                //refresh screen
			  DisplayScreen();               //show the main screen again
			  DisplayNextShape();            //show next brick box
		   }
		   else if(Key == 's' || Key == 'S')        //For sound on/off
		   {
			  SoundOn = !SoundOn;

		   }
		   else if(Key=='a' || Key=='A')                      //For author
		   {	 MessageBox("Author: Aguntuk Group",450);
			 cleardevice();                               //Clear the message box
			 while(kbhit()) getch();                      //Clear the keyboard input
			 for(int x=0;x<COLS;x++)
				for(int y=0;y<ROWS;y++)
					PreviousScreenLayout[x][y] -=1;     //Clear the present screen layout to refresh the whole screen
			 UpdateScreen();                   //refresh screen
			 DisplayScreen();                  //show the main screen again
			 DisplayNextShape();               //show next brick box
		   }
		}
		delay(6);      	      //For moving down the blocks slowly
	}
	if(GameOver)                  //For game over option
	{      	DisplayBlock(6,0);    //For display the top most brick
		ShowGameOver();       //For display game over message box
	}
	restorecrtmode();    //For closing graphicg mode
	return 0;
}