Example #1
0
        VP8StatusCode WebPAllocateDecBuffer(int w, int h, WebPDecoderOptions options, WebPDecBuffer _out)
        {
            if (_out == null || w <= 0 || h <= 0) {
            return VP8_STATUS_INVALID_PARAM;
              }
              if (options != null) {    // First, apply options if there is any.
            if (options.use_cropping) {
              int cw = options.crop_width;
              int ch = options.crop_height;
              int x = options.crop_left & ~1;
              int y = options.crop_top & ~1;
              if (x < 0 || y < 0 || cw <= 0 || ch <= 0 || x + cw > w || y + ch > h) {
                return VP8_STATUS_INVALID_PARAM;   // out of frame boundary.
              }
              w = cw;
              h = ch;
            }
            if (options.use_scaling) {
              if (options.scaled_width <= 0 || options.scaled_height <= 0) {
                return VP8_STATUS_INVALID_PARAM;
              }
              w = options.scaled_width;
              h = options.scaled_height;
            }
              }
              _out.width = w;
              _out.height = h;

              // Then, allocate buffer for real
              return _out.AllocateBuffer();
        }
Example #2
0
File: io.cs Project: soywiz/nwebp
		//------------------------------------------------------------------------------
		// Default custom functions

		// Setup crop_xxx fields, mb_w and mb_h
		static int InitFromOptions(WebPDecoderOptions* options,
								   VP8Io* io) {
		  int W = io.width;
		  int H = io.height;
		  int x = 0, y = 0, w = W, h = H;

		  // Cropping
		  io.use_cropping = (options != null) && (options.use_cropping > 0);
		  if (io.use_cropping) {
			w = options.crop_width;
			h = options.crop_height;
			// TODO(skal): take colorspace into account. Don't assume YUV420.
			x = options.crop_left & ~1;
			y = options.crop_top & ~1;
			if (x < 0 || y < 0 || w <= 0 || h <= 0 || x + w > W || y + h > H) {
			  return 0;  // out of frame boundary error
			}
		  }
		  io.crop_left   = x;
		  io.crop_top    = y;
		  io.crop_right  = x + w;
		  io.crop_bottom = y + h;
		  io.mb_w = w;
		  io.mb_h = h;

		  // Scaling
		  io.use_scaling = (options != null) && (options.use_scaling > 0);
		  if (io.use_scaling) {
			if (options.scaled_width <= 0 || options.scaled_height <= 0) {
			  return 0;
			}
			io.scaled_width = options.scaled_width;
			io.scaled_height = options.scaled_height;
		  }

		  // Filter
		  io.bypass_filtering = options && options.bypass_filtering;

		  // Fancy upsampler
		#if FANCY_UPSAMPLING
		  io.fancy_upsampling = (options == null) || (!options.no_fancy_upsampling);
		#endif

		  if (io.use_scaling) {
			// disable filter (only for large downscaling ratio).
			io.bypass_filtering = (io.scaled_width < W * 3 / 4) &&
								   (io.scaled_height < H * 3 / 4);
			io.fancy_upsampling = 0;
		  }
		  return 1;
		}