Class: CooCoo::DataSources::Xournal::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/coo-coo/data_sources/xournal/document.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(left, top, right, bottom, data = nil) ⇒ Image

Returns a new instance of Image.



321
322
323
324
325
326
327
# File 'lib/coo-coo/data_sources/xournal/document.rb', line 321

def initialize(left, top, right, bottom, data = nil)
  @left = left.to_f
  @top = top.to_f
  @right = right.to_f
  @bottom = bottom.to_f
  self.data = data
end

Instance Attribute Details

#bottomObject

Returns the value of attribute bottom.



318
319
320
# File 'lib/coo-coo/data_sources/xournal/document.rb', line 318

def bottom
  @bottom
end

#dataObject

Returns the value of attribute data.



319
320
321
# File 'lib/coo-coo/data_sources/xournal/document.rb', line 319

def data
  @data
end

#leftObject

Returns the value of attribute left.



318
319
320
# File 'lib/coo-coo/data_sources/xournal/document.rb', line 318

def left
  @left
end

#raw_dataObject

Returns the value of attribute raw_data.



319
320
321
# File 'lib/coo-coo/data_sources/xournal/document.rb', line 319

def raw_data
  @raw_data
end

#rightObject

Returns the value of attribute right.



318
319
320
# File 'lib/coo-coo/data_sources/xournal/document.rb', line 318

def right
  @right
end

#topObject

Returns the value of attribute top.



318
319
320
# File 'lib/coo-coo/data_sources/xournal/document.rb', line 318

def top
  @top
end

Instance Method Details

#data_stringObject



367
368
369
# File 'lib/coo-coo/data_sources/xournal/document.rb', line 367

def data_string
  Base64.encode64(raw_data)
end

#decode_image(data) ⇒ Object



363
364
365
# File 'lib/coo-coo/data_sources/xournal/document.rb', line 363

def decode_image(data)
  ChunkyPNG::Image.from_string(data)
end

#heightObject



359
360
361
# File 'lib/coo-coo/data_sources/xournal/document.rb', line 359

def height
  (bottom - top).to_i
end

#sized_data(zx = 1.0, zy = 1.0) ⇒ Object



347
348
349
350
351
352
353
# File 'lib/coo-coo/data_sources/xournal/document.rb', line 347

def sized_data(zx = 1.0, zy = 1.0)
  if zx == 1.0 && zy == 1.0
    @sized_data ||= @data.resample_bilinear(width, height)
  else
    @data.resample_bilinear((width * zx).to_i, (height * zy).to_i)
  end
end

#widthObject



355
356
357
# File 'lib/coo-coo/data_sources/xournal/document.rb', line 355

def width
  (right - left).to_i
end