/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-
BMP SUPPORT (SAVING) - James Heinrich
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-
172221
private function GD2BMPstring(&$gd_image)
		# Author:     James Heinrich
		# Purpose:    Save file as type bmp
		# Param in:   The image canvas (passed as ref)
		# Param out:
		# Reference:
		# Notes:    This code was stripped out of two external files
		#       (phpthumb.bmp.php,phpthumb.functions.php) and added below to
		#       avoid dependancies.
		#
	{
		$imageX = ImageSX($gd_image);
		$imageY = ImageSY($gd_image);

		$BMP = '';
		for ($y = ($imageY - 1); $y >= 0; $y--)
		{
			$thisline = '';
			for ($x = 0; $x < $imageX; $x++)
			{
				$argb = $this->GetPixelColor($gd_image, $x, $y);
				$thisline .= chr($argb['blue']) . chr($argb['green']) . chr($argb['red']);
			}
			while (strlen($thisline) % 4)
			{
				$thisline .= "\x00";
			}
			$BMP .= $thisline;
		}

		$bmpSize = strlen($BMP) + 14 + 40;
		// BITMAPFILEHEADER [14 bytes] - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_62uq.asp
		$BITMAPFILEHEADER = 'BM';                                    // WORD    bfType;
		$BITMAPFILEHEADER .= $this->LittleEndian2String($bmpSize, 4); // DWORD   bfSize;
		$BITMAPFILEHEADER .= $this->LittleEndian2String(0, 2); // WORD    bfReserved1;
		$BITMAPFILEHEADER .= $this->LittleEndian2String(0, 2); // WORD    bfReserved2;
		$BITMAPFILEHEADER .= $this->LittleEndian2String(54, 4); // DWORD   bfOffBits;

		// BITMAPINFOHEADER - [40 bytes] http://msdn.microsoft.com/library/en-us/gdi/bitmaps_1rw2.asp
		$BITMAPINFOHEADER = $this->LittleEndian2String(40, 4); // DWORD  biSize;
		$BITMAPINFOHEADER .= $this->LittleEndian2String($imageX, 4); // LONG   biWidth;
		$BITMAPINFOHEADER .= $this->LittleEndian2String($imageY, 4); // LONG   biHeight;
		$BITMAPINFOHEADER .= $this->LittleEndian2String(1, 2); // WORD   biPlanes;
		$BITMAPINFOHEADER .= $this->LittleEndian2String(24, 2); // WORD   biBitCount;
		$BITMAPINFOHEADER .= $this->LittleEndian2String(0, 4); // DWORD  biCompression;
		$BITMAPINFOHEADER .= $this->LittleEndian2String(0, 4); // DWORD  biSizeImage;
		$BITMAPINFOHEADER .= $this->LittleEndian2String(2835, 4); // LONG   biXPelsPerMeter;
		$BITMAPINFOHEADER .= $this->LittleEndian2String(2835, 4); // LONG   biYPelsPerMeter;
		$BITMAPINFOHEADER .= $this->LittleEndian2String(0, 4); // DWORD  biClrUsed;
		$BITMAPINFOHEADER .= $this->LittleEndian2String(0, 4); // DWORD  biClrImportant;

		return $BITMAPFILEHEADER . $BITMAPINFOHEADER . $BMP;
	}
1161425
function resizeImageBase64 (successCallback, errorCallback, file, targetWidth, targetHeight) {
    fileIO.readBufferAsync(file).done(function (buffer) {
        var strBase64 = encodeToBase64String(buffer);
        var imageData = 'data:' + file.contentType + ';base64,' + strBase64;

        var image = new Image(); /* eslint no-undef : 0 */
        image.src = imageData;

        image.onload = function () {
            var ratio = Math.min(targetWidth / this.width, targetHeight / this.height);
            var imageWidth = ratio * this.width;
            var imageHeight = ratio * this.height;
            var canvas = document.createElement('canvas');

            canvas.width = imageWidth;
            canvas.height = imageHeight;

            var ctx = canvas.getContext('2d');
            ctx.drawImage(this, 0, 0, imageWidth, imageHeight);

            // The resized file ready for upload
            var finalFile = canvas.toDataURL(file.contentType);

            // Remove the prefix such as "data:" + contentType + ";base64," , in order to meet the Cordova API.
            var arr = finalFile.split(',');
            var newStr = finalFile.substr(arr[0].length + 1);
            successCallback(newStr);
        };
    }, function (err) { errorCallback(err); });
}
1194268
function BlobReader(blob, opts) {
  stream.Readable.call(this);
  opts = opts || {};

  this._batchSize = opts.batchSize || 65536;
  this._blob = blob;
  this._pos = 0;
}
260717
public static void saveBmp(Bitmap src, String fileName) throws ImageSaveException {
        try {
            BitmapUtil.save(src, fileName);
        } catch (IOException e) {
            throw new ImageSaveException(e);
        }
    }
208272
function(callback) {
		
		if(!this.ifLoad) {
			this.history.push('add to stack task: bmpToData');
			this.stack(this.bmpToData, callback);
			return;
		} 
		
		this.history.push('bmp decode');
		
		var fileSize, headerLength, i, magic, offset, b, data, g, r, w, x, y, _ref;
		this.pos = 0;
		this.bpp = 24;
		
		magic = ((function() {
			var _results;
			_results = [];
			for (i = 0; i < 2; i++) {
				_results.push(String.fromCharCode(this.data[this.pos++]));
			}
			return _results;
		}).call(this)).join('');
		
		if (magic !== 'BM') {
			throw 'Invalid BMP file.';
		}
		
		fileSize = this._readUInt32Bmp();
		this.pos += 4;
		offset = this._readUInt32Bmp();
		headerLength = this._readUInt32Bmp();
		this.width = this._readUInt32Bmp();
		this.height = this._readUInt32Bmp();
		this.colorPlaneCount = this._readUInt16Bmp();
		this.bitsPerPixel = this._readUInt16Bmp();
		this.compressionMethod = this._readUInt32Bmp();
		this.rawSize = this._readUInt32Bmp();
		this.hResolution = this._readUInt32Bmp();
		this.vResolution = this._readUInt32Bmp();
		this.paletteColors = this._readUInt32Bmp();
		this.importantColors = this._readUInt32Bmp();


		var Ndata = [];

		for(y = this.height; y > 0; y--) {
			i = 4 * y * this.width;
			
			for (var x = 0; x < this.width; x++) {
				
				b = this.data[this.pos++];
				g = this.data[this.pos++];
				r = this.data[this.pos++];
				
				Ndata[i++] = r;
				Ndata[i++] = g;
				Ndata[i++] = b;
				Ndata[i++] = 255;
			}
			
			if(this.width%2) {
				this.pos++;
			}
			
			if(this.width%4) {
				this.pos++;
				this.pos++;
			}
		}
	
		for(var i=0, null_elems=0; i < Ndata.length; i ++) {
			if(Ndata[i] != null) {
				break;
			}
			null_elems++;
		}
		
		Ndata.splice(0, this.width*4);
		
		this.data = Ndata;
		callback.call(this);
		
		return;
	}
1126973
function ( videoNode ) {

			var content = videoNode.Content;
			var fileName = videoNode.RelativeFilename || videoNode.Filename;
			var extension = fileName.slice( fileName.lastIndexOf( '.' ) + 1 ).toLowerCase();

			var type;

			switch ( extension ) {

				case 'bmp':

					type = 'image/bmp';
					break;

				case 'jpg':
				case 'jpeg':

					type = 'image/jpeg';
					break;

				case 'png':

					type = 'image/png';
					break;

				case 'tif':

					type = 'image/tiff';
					break;

				case 'tga':

					if ( typeof THREE.TGALoader !== 'function' ) {

						console.warn( 'FBXLoader: THREE.TGALoader is required to load TGA textures' );
						return;

					} else {

						if ( THREE.Loader.Handlers.get( '.tga' ) === null ) {

							THREE.Loader.Handlers.add( /\.tga$/i, new THREE.TGALoader() );

						}

						type = 'image/tga';
						break;

					}

				default:

					console.warn( 'FBXLoader: Image type "' + extension + '" is not supported.' );
					return;

			}

			if ( typeof content === 'string' ) { // ASCII format

				return 'data:' + type + ';base64,' + content;

			} else { // Binary Format

				var array = new Uint8Array( content );
				return window.URL.createObjectURL( new Blob( [ array ], { type: type } ) );

			}

		}
1025428
function save_options() {
  var showChangeLog = document.getElementById('show_changelog').checked;
  chrome.storage.sync.set({
    showChangeLog: showChangeLog
  }, function () {
    // Update status to let user know options were saved.
    var status = document.getElementById('status');
    status.textContent = 'Options saved.';
    setTimeout(function () {
      status.textContent = '';
    }, 750);
  });
}
468931
function(img, convert_grayscale) {

    if(typeof(convert_grayscale)==='undefined') var convert_grayscale = false;

    var canvas = document.createElement('canvas');
    canvas.width = img.width;
    canvas.height = img.height;
    var ctx = canvas.getContext("2d");

    // due to a Firefox bug
    try {
      ctx.drawImage(img, 0, 0);
    } catch (e) {
      if (e.name === "NS_ERROR_NOT_AVAILABLE") {
        // sometimes happens, lets just abort
        return false;
      } else {
        throw e;
      }
    }

    try {
      var img_data = ctx.getImageData(0, 0, canvas.width, canvas.height);
    } catch (e) {
      if(e.name === 'IndexSizeError') {
        return false; // not sure what causes this sometimes but okay abort
      } else {
        throw e;
      }
    }

    // prepare the input: get pixels and normalize them
    var p = img_data.data;
    var W = img.width;
    var H = img.height;
    var pv = []
    for(var i=0;i<p.length;i++) {
      pv.push(p[i]/255.0-0.5); // normalize image pixels to [-0.5, 0.5]
    }
    var x = new Vol(W, H, 4, 0.0); //input volume (image)
    x.w = pv;

    if(convert_grayscale) {
      // flatten into depth=1 array
      var x1 = new Vol(W, H, 1, 0.0);
      for(var i=0;i<W;i++) {
        for(var j=0;j<H;j++) {
          x1.set(i,j,0,x.get(i,j,0));
        }
      }
      x = x1;
    }

    return x;
  }
997121
function(fileId, imgOrCanvas, maxSize, fromServer, customResizeFunction) {
            var promiseToReturn = new qq.Promise(),
                fileOrUrl, options;

            if (this._imageGenerator) {
                fileOrUrl = this._thumbnailUrls[fileId];
                options = {
                    customResizeFunction: customResizeFunction,
                    maxSize: maxSize > 0 ? maxSize : null,
                    scale: maxSize > 0
                };

                // If client-side preview generation is possible
                // and we are not specifically looking for the image URl returned by the server...
                if (!fromServer && qq.supportedFeatures.imagePreviews) {
                    fileOrUrl = this.getFile(fileId);
                }

                /* jshint eqeqeq:false,eqnull:true */
                if (fileOrUrl == null) {
                    promiseToReturn.failure({container: imgOrCanvas, error: "File or URL not found."});
                }
                else {
                    this._imageGenerator.generate(fileOrUrl, imgOrCanvas, options).then(
                        function success(modifiedContainer) {
                            promiseToReturn.success(modifiedContainer);
                        },

                        function failure(container, reason) {
                            promiseToReturn.failure({container: container, error: reason || "Problem generating thumbnail"});
                        }
                    );
                }
            }
            else {
                promiseToReturn.failure({container: imgOrCanvas, error: "Missing image generator module"});
            }

            return promiseToReturn;
        }
473986
@SubscribeEvent
	public void onDataSave(ChunkDataEvent.Save event)
	{
		NBTTagCompound nbt = event.getData();

		for (HandlerInfo<?> handlerInfo : handlerInfos.values())
		{
			ChunkData<?> chunkData = chunkData(handlerInfo.identifier, event.getWorld(), event.getChunk());
			if (chunkData != null && chunkData.hasData())
			{
				//				MalisisCore.message("onDataSave (" + event.getChunk().xPosition + "/" + event.getChunk().zPosition + ") for "
				//						+ handlerInfo.identifier);
				ByteBuf buf = Unpooled.buffer();
				chunkData.toBytes(buf);
				nbt.setByteArray(handlerInfo.identifier, buf.capacity(buf.writerIndex()).array());
			}

			//unload data on save because saving is called after unload
			if (event.getChunk().unloadQueued)
				datas.get().remove(handlerInfo.identifier, event.getChunk());

		}
	}
953991
function(cb){
      this.toCanvas(function(canvas){
        var canvasData = canvas.toDataURL("image/png");
        var img = document.createElement('img');

        img.onload = function(){
          cb(img);
        };

        // Make pngImg's source the canvas data.
        img.setAttribute('src', canvasData);
      });
    }
657668
function main() {
    var TIME_STEP_MS = 20;
    var frameCount = sozi.presentation.frames.length;
    var imageIndex = 0;

    document.querySelector(".sozi-blank-screen").style.display = "none";
    
    sozi.presentation.frames.forEach(function (currentFrame, currentFrameIndex) {
        console.log("Exporting frame: " + (currentFrameIndex + 1));

        sozi.player.jumpToFrame(currentFrameIndex);

        // Generate images for the duration of the current frame
        for (var timeMs = 0; timeMs < currentFrame.timeoutMs; timeMs += TIME_STEP_MS, imageIndex ++) {
            window.callPhantom(imageIndex);
        }

        // Generate images for the transition to the next frame.
        // If the last frame has a timeout enabled, transition to the first frame.
        if (currentFrameIndex < frameCount - 1 || currentFrame.timeoutEnable) {
            if (typeof sozi.player.nextFrameIndex === "number") {
                sozi.player.targetFrameIndex = sozi.player.nextFrameIndex; // Sozi < 18
            }
            else {
                sozi.player.targetFrame = sozi.player.nextFrame; // Sozi 18
            }

            sozi.viewport.cameras.forEach(function (camera) {
                var lp = sozi.player.targetFrame.layerProperties[camera.layer.index];
                sozi.player.setupTransition(camera, sozi.Timing[lp.transitionTimingFunction], lp.transitionRelativeZoom, lp.transitionPath, false);
            });

            for (timeMs = 0; timeMs < sozi.player.targetFrame.transitionDurationMs; timeMs += TIME_STEP_MS, imageIndex ++) {
                sozi.player.onAnimatorStep(timeMs / sozi.player.targetFrame.transitionDurationMs);
                window.callPhantom(imageIndex);
            }
        }
    });
}
903425
function init() {
  if ('BlocklyStorage' in window) {
    BlocklyStorage.HTTPREQUEST_ERROR =
        'There was a problem with the request.\n';
    BlocklyStorage.LINK_ALERT =
        'Share your blocks with this link:\n\n%1';
    BlocklyStorage.HASH_ERROR =
        'Sorry, "%1" doesn\'t correspond with any saved Blockly file.';
    BlocklyStorage.XML_ERROR = 'Could not load your saved file.\n'+
        'Perhaps it was created with a different version of Blockly?';
    var linkButton = document.getElementById('linkButton');
    linkButton.style.display = 'inline-block';
    linkButton.addEventListener('click',
        function() {BlocklyStorage.link(mainWorkspace);});
    disableEnableLink();
  }

  document.getElementById('helpButton').addEventListener('click',
    function() {
      open('https://developers.google.com/blockly/custom-blocks/block-factory',
           'BlockFactoryHelp');
    });

  var expandList = [
    document.getElementById('blockly'),
    document.getElementById('blocklyMask'),
    document.getElementById('preview'),
    document.getElementById('languagePre'),
    document.getElementById('languageTA'),
    document.getElementById('generatorPre')
  ];
  var onresize = function(e) {
    for (var i = 0, expand; expand = expandList[i]; i++) {
      expand.style.width = (expand.parentNode.offsetWidth - 2) + 'px';
      expand.style.height = (expand.parentNode.offsetHeight - 2) + 'px';
    }
  };
  onresize();
  window.addEventListener('resize', onresize);

  var toolbox = document.getElementById('toolbox');
  mainWorkspace = Blockly.inject('blockly',
      {collapse: false,
       toolbox: toolbox,
       media: '../../media/'});

  // Create the root block.
  if ('BlocklyStorage' in window && window.location.hash.length > 1) {
    BlocklyStorage.retrieveXml(window.location.hash.substring(1),
                               mainWorkspace);
  } else {
    var xml = '<xml><block type="factory_base" deletable="false" movable="false"></block></xml>';
    Blockly.Xml.domToWorkspace(Blockly.Xml.textToDom(xml), mainWorkspace);
  }
  mainWorkspace.clearUndo();

  mainWorkspace.addChangeListener(updateLanguage);
  document.getElementById('direction')
      .addEventListener('change', updatePreview);
  document.getElementById('languageTA')
      .addEventListener('change', updatePreview);
  document.getElementById('languageTA')
      .addEventListener('keyup', updatePreview);
  document.getElementById('format')
      .addEventListener('change', formatChange);
  document.getElementById('language')
      .addEventListener('change', updatePreview);
}
381116
function saveFileChanges(themeId, folderName, fileName, text) {
        io({
            url:getURL("save") + "/" + themeId + "/" + folderName + "/" + fileName,
            data:{
                content:encodeURI(text)
            },
            callback:function (isSuccess, message, response) {
                if (!isSuccess) {
                    showErrorMsg(message);
                }
            }
        });
    }
436615
function downloadHeightMap() {
    console.log('downloadHeightMap:', file.name);
    var heightMapFile = new Blob([heightMap], { type: 'text/plain;charset=utf-8' });
    saveAs(heightMapFile, file.name + '.height-map.txt');
}
197575
private function ImageCreateFromBMP($filename)
		# Author:     DHKold
		# Date:     The 15th of June 2005
		# Version:    2.0B
		# Purpose:    To create an image from a BMP file.
		# Param in:   BMP file to open.
		# Param out:  Return a resource like the other ImageCreateFrom functions
		# Reference:  http://us3.php.net/manual/en/function.imagecreate.php#53879
		# Bug fix:    Author:   domelca at terra dot es
		#       Date:   06 March 2008
		#       Fix:    Correct 16bit BMP support
		# Notes:
		#
	{

		//Ouverture du fichier en mode binaire
		if ( ! $f1 = fopen($filename, "rb"))
		{
			return false;
		}

		//1 : Chargement des ent�tes FICHIER
		$FILE = unpack("vfile_type/Vfile_size/Vreserved/Vbitmap_offset", fread($f1, 14));
		if ($FILE['file_type'] != 19778)
		{
			return false;
		}

		//2 : Chargement des ent�tes BMP
		$BMP = unpack('Vheader_size/Vwidth/Vheight/vplanes/vbits_per_pixel' .
			'/Vcompression/Vsize_bitmap/Vhoriz_resolution' .
			'/Vvert_resolution/Vcolors_used/Vcolors_important', fread($f1, 40));
		$BMP['colors'] = pow(2, $BMP['bits_per_pixel']);

		if ($BMP['size_bitmap'] == 0)
		{
			$BMP['size_bitmap'] = $FILE['file_size'] - $FILE['bitmap_offset'];
		}

		$BMP['bytes_per_pixel'] = $BMP['bits_per_pixel'] / 8;
		$BMP['bytes_per_pixel2'] = ceil($BMP['bytes_per_pixel']);
		$BMP['decal'] = ($BMP['width'] * $BMP['bytes_per_pixel'] / 4);
		$BMP['decal'] -= floor($BMP['width'] * $BMP['bytes_per_pixel'] / 4);
		$BMP['decal'] = 4 - (4 * $BMP['decal']);

		if ($BMP['decal'] == 4)
		{
			$BMP['decal'] = 0;
		}

		//3 : Chargement des couleurs de la palette
		$PALETTE = array();
		if ($BMP['colors'] < 16777216)
		{
			$PALETTE = unpack('V' . $BMP['colors'], fread($f1, $BMP['colors'] * 4));
		}

		//4 : Cr�ation de l'image
		$IMG = fread($f1, $BMP['size_bitmap']);
		$VIDE = chr(0);

		$res = imagecreatetruecolor($BMP['width'], $BMP['height']);
		$P = 0;
		$Y = $BMP['height'] - 1;
		while ($Y >= 0)
		{
			$X = 0;
			while ($X < $BMP['width'])
			{
				if ($BMP['bits_per_pixel'] == 24)
				{
					$COLOR = unpack("V", substr($IMG, $P, 3) . $VIDE);
				}
				elseif ($BMP['bits_per_pixel'] == 16)
				{

					/*
           * BMP 16bit fix
           * =================
           *
           * Ref: http://us3.php.net/manual/en/function.imagecreate.php#81604
           *
           * Notes:
           * "don't work with bmp 16 bits_per_pixel. change pixel
           * generator for this."
           *
           */

					// *** Original code (don't work)
					//$COLOR = unpack("n",substr($IMG,$P,2));
					//$COLOR[1] = $PALETTE[$COLOR[1]+1];

					$COLOR = unpack("v", substr($IMG, $P, 2));
					$blue = ($COLOR[1] & 0x001f) << 3;
					$green = ($COLOR[1] & 0x07e0) >> 3;
					$red = ($COLOR[1] & 0xf800) >> 8;
					$COLOR[1] = $red * 65536 + $green * 256 + $blue;

				}
				elseif ($BMP['bits_per_pixel'] == 8)
				{
					$COLOR = unpack("n", $VIDE . substr($IMG, $P, 1));
					$COLOR[1] = $PALETTE[ $COLOR[1] + 1 ];
				}
				elseif ($BMP['bits_per_pixel'] == 4)
				{
					$COLOR = unpack("n", $VIDE . substr($IMG, floor($P), 1));
					if (($P * 2) % 2 == 0)
					{
						$COLOR[1] = ($COLOR[1] >> 4);
					}
					else
					{
						$COLOR[1] = ($COLOR[1] & 0x0F);
					}
					$COLOR[1] = $PALETTE[ $COLOR[1] + 1 ];
				}
				elseif ($BMP['bits_per_pixel'] == 1)
				{
					$COLOR = unpack("n", $VIDE . substr($IMG, floor($P), 1));
					if (($P * 8) % 8 == 0)
					{
						$COLOR[1] = $COLOR[1] >> 7;
					}
					elseif (($P * 8) % 8 == 1)
					{
						$COLOR[1] = ($COLOR[1] & 0x40) >> 6;
					}
					elseif (($P * 8) % 8 == 2)
					{
						$COLOR[1] = ($COLOR[1] & 0x20) >> 5;
					}
					elseif (($P * 8) % 8 == 3)
					{
						$COLOR[1] = ($COLOR[1] & 0x10) >> 4;
					}
					elseif (($P * 8) % 8 == 4)
					{
						$COLOR[1] = ($COLOR[1] & 0x8) >> 3;
					}
					elseif (($P * 8) % 8 == 5)
					{
						$COLOR[1] = ($COLOR[1] & 0x4) >> 2;
					}
					elseif (($P * 8) % 8 == 6)
					{
						$COLOR[1] = ($COLOR[1] & 0x2) >> 1;
					}
					elseif (($P * 8) % 8 == 7)
					{
						$COLOR[1] = ($COLOR[1] & 0x1);
					}
					$COLOR[1] = $PALETTE[ $COLOR[1] + 1 ];
				}
				else
				{
					return false;
				}

				imagesetpixel($res, $X, $Y, $COLOR[1]);
				$X++;
				$P += $BMP['bytes_per_pixel'];
			}

			$Y--;
			$P += $BMP['decal'];
		}
		//Fermeture du fichier
		fclose($f1);

		return $res;
	}
447609
@SuppressWarnings("unchecked")
	@Override
	public T blobParamIfAbsent(final String paramName, final InputStream value) {
		context().blobParamIfAbsent(paramName, value);
		return (T) this;
	}