Extending interMedia Image, Audio and Video Format Support

 

Due to rapidly evolving technology, a MIME type may be encountered that is not recognized by all  interMedia methods. In this case, the media data can still be stored and retrieved using interMedia objects, but automatic property extraction and image processing will not be available without some additional work.

This document talks about the different levels of support available for image, audio and video formats that are not natively understood by interMedia.

 

Table of Contents:

  1. Extending interMedia Image Format Support
    • To store and retrieve image data in the database (no attribute extraction and no processing)
    • To store an uncompressed format in ORDImage and process with interMedia methods
    • To extend the interMedia ORDImage data type with a new object type 
  2. Extending interMedia Audio Format Support
    • To store and retrieve audio data in the database (no attribute extraction)
    • To extend the interMedia ORDAudio data type with new format support
  3. Extending interMedia Video Format Support
    • To store and retrieve video data in the database (no attribute extraction)
    • To extend the interMedia ORDVideo data type with new format support

 


A. Extending interMedia Image Format Support


interMedia provides native support and understanding for many popular image formats including GIF, JFIF, TIFF and BMP. For these natively understood formats, interMedia is able to extract metadata from the image, and process the image to generate thumbnails, cut, scale, compress and/or convert format.  For all formats, both those natively understood, and those not natively understood (referred to as 'foreign'), interMedia is able to store and retrieve the image, and associate the image with other relational data.

This section describes the three levels of support that are possible for foreign images: 

 

To store and retrieve image data in the database (no attribute  extraction and no processing)

Any image, regardless of format, can be stored in the interMedia ORDImage object.  However, the setProperties() method cannot be used to automatically extract attributes from foreign images, and the process and processCopy() methods cannot be used to process foreign images.  Instead, image data can be stored, and image attributes such as height, width and MimeType can be set explicitly in ORDImage object attributes.

If you do not need automatic metadata extraction or processing of your foreign images,  you can perform the following steps to load/retrieve foreign images with the ORDImage object:
 

  • Create an empty ORDImage object.
  • Call the setProperties() method and provide, minimally, MIME type as a parameter. Check the target client viewer documentation to determine if additional attributes are needed by the viewer to read and display rich media data retrieved from Oracle8i.
  • Use the import() method to load the image from the file system or URL into the database.
Note: For ORDImage objects, the import() method calls setProperties() implicitly unless the format attribute is set to something beginning with 'OTHER'.  This call to setProperties() will fail if interMedia does not understand the format. Calling the foreign setProperties() method with a description (see below) will cause the format attribute to be set to 'OTHER' with the UserString appended if specified.  Alternatively, the format attribut can be explicitly set to 'OTHER' before calling the ORDImage.import() method.
 
Example 1: Loading a foreign image

Foreign media objects are those that have MIME types interMedia does not recognize. The  characteristics of these files cannot be read from the image header automatically. To load an IPIX image for instance, explicitly set the MIME type, height and width before importing the image.

set serveroutput on 
set echo on 

create table pictures 
	(id			number,
	 image		ordsys.ordimage);

create or replace directory imgdir as 'c:\temp\';

create sequence imageseq start with 1;

create or replace procedure load_image_ipix(file_name varchar) 

as 
        obj ORDSYS.ORDImage; 
        nxtSeq number; 
        ctx raw(4000):=null; 


BEGIN 
        select imageseq.nextval into nxtseq from dual; 
        insert into pictures (id, image) values (nxtseq, 
                ORDSYS.ORDImage (ORDSYS.ORDSOURCE(EMPTY_BLOB(),
                NULL,NULL,NULL,SYSDATE,NULL), 
                NULL,NULL,NULL,NULL,NULL,NULL,NULL)); 
       
        select t.image into obj from pictures t 
        where t.id = nxtseq for update; 
        
        obj.setProperties('height=320 width=240 mimeType=application/x-ipix'); 
        obj.importFrom(ctx,'FILE','IMGDIR',file_name); 

        update pictures t set t.image=obj 
        where t.id = nxtseq; 

        commit; 
END; 

/ 

show errors;



-- format is load_image_ipix(file_name)
begin load_image_ipix('mountains.ipx'); 
end;
/


Note: In version 8.1.5, the setProperties() foreign method did not allow you to specify the MIME type attribute. You must invoke the setMimeType( ) method to set the MIME type for foreign images if you're running with version 8.1.5.

 

To store an uncompressed format in ORDImage and process with interMedia methods


interMedia provides support for reading certain foreign images that can be described in terms of a few simple parameters, and whose data is arranged in a certain straightforward way within the image file.  You can use the interMedia foreign image mechanism to tell interMedia enough about the foreign image that interMedia can process the image using the process() and processCopy() methods.

There is no list of formats that may be supported via the foreign image mechanism because the list would be large and continually changing. Instead, there are some simple guidelines to determine if an image can be read using the foreign image support in interMedia. These rules are summarized here:

 

Table 1: Foreign Image Support Guidelines

Rule Description
Header
Foreign images may have any header (or no header), in any format, as long as its length does not exceed 4,294,967,265 bytes. As has been noted before, all information in this header will be ignored. 
Image Width Foreign images may be up to 32,767 pixels wide.
Image Height Foreign images may be up to 32,767 pixels high.
Compression Type Foreign images must be uncompressed or compressed using CCITT Fax Group 3 or Fax Group 4. Other compression schemes, such as run-length encoding, are not currently supported.
Pixel Data Foreign images must represent pixel data in either a grayscale or RGB color space, with 8 bits per color plane or sample. Other color spaces such as CMYK or HSV are not allowed. The only exceptions are images compressed using CCITT Fax Group 3 and Fax Group 4 compression which are allowed to represent images using 1 bit per pixel.
Pixel Order Foreign images may store pixels from left-to-right or right-to-left. Other pixel ordering schemes, such as boustrophedonic ordering, are not currently supported.
Scanline Order Foreign images may have top-first or bottom-first scanline orders. Scanlines that are adjacent in the image display must be adjacent in the image storage. Some image formats stagger their image scanlines so that, for example, scanlines 1,5,9, and so forth are adjacent, and then 2,6,10 are also adjacent. This is not currently supported.
Interleave Foreign images must use BIP, BIL, or BSQ interleaving. Other arrangements of data bands are not allowed, nor may bands have any pixel, scanline, or band-level blocking or padding.
Number of Bands Foreign images may have up to 255 bands of data. If there are more bands of data, the first 255 can be accessed if the interleaving of the image is "band sequential." In this case, the additional bands of data lie past the accessible bands and do not affect the layout of the first 255 bands. Images with other interleaving types may not have more than 255 bands because the additional bands will change the layout of the bitmap data.
Trailer Foreign images may have an image trailer following the bitmap data, and this trailer may be of arbitrary length. However, such data is completely ignored by interMedia image, and there is no method (or need) to specify the presence or length of such a trailer.

If your image format meets the criteria described above, you can use the foreign image setProperties() method to describe the foreign image to interMedia. Once the image has been described, the process() and processCopy() methods can be used to process the image. 

You can set the following image characteristics for foreign images, as shown in the Table 2 below. The format for the setProperties(description) method is:

 

setProperties(description IN VARCHAR2);
 
 

Table 2: Image Characteristics for Foreign Images

Field Data Type Description
CompressionFormat 
STRING 
Value must be CCITG3, CCITG4, or NONE (default). 
DataOffset 
INTEGER 
The offset allows the image to have a header that interMedia image does not try to interpret. Set the offset to avoid any potential header. The value must be a positive integer less than the LOB length. Default is zero. 
DefaultChannelSelection 

INTEGER 

For multiband images, specify either one (grayscale) or three integers indicating which channels to assign to red (first), green (second), and blue (third). 
Height 
INTEGER 
Height of the image in pixels. Value must be a positive integer. There is no default, thus a value must be specified. 
Interleave 

STRING 

Band layout within the image. Valid styles are: 
  • BIP (default) Band Interleaved by Pixel 
  • BIL Band Interleaved by Line 
  • BSQ Band Sequential 
NumberOfBands 

INTEGER 

Value must be a positive integer less than 255 describing the number of color bands in the image. Default is 3. 

PixelOrder 

STRING 

If NORMAL (default), the leftmost pixel appears first in the file. If REVERSE, the rightmost pixel appears first. 

ScanlineOrder 

STRING 

If NORMAL (default), the top scanline appears first in the file. If INVERSE, then the bottom scanline appears first. 

UserString 

STRING 

A 4-character descriptive string. If used, the string is stored in the fileFormat field, appended to the file format ("OTHER:"). Default is blank and fileFormat is set to "OTHER". 

Width 

INTEGER 

Width of the image in pixels. Value must be a positive integer. There is no default, thus a value must be specified. 

The values supplied to setProperties( ) are written to the existing ORDImage data attributes. The fileFormat is set to "OTHER" and includes the user string, if supplied; for example, 'OTHER: LANDSAT'.

If the description attribute value is NULL, calling this method raises a NULL_PROPERTIES_DESCRIPTION exception.
 

Example 2: Selecting the foreign image and then setting the properties for the image
create table emp 
	(ename 		varchar2(20), 
	large_photo 	ordsys.ordimage);

-- insert some records into emp at this point 
-- including ename = 'John Doe';


DECLARE

	Image ORDSYS.ORDImage;

BEGIN

	SELECT large_photo INTO Image FROM emp 
	WHERE ename = 'John Doe' FOR UPDATE;

	-- set property attributes for the image data
	Image.setProperties('width=123 height=321 compressionFormat=NONE'|| 

	' userString=DJM dataOffset=128' || 
	' scanlineOrder=INVERSE pixelOrder=REVERSE' || 
	' interleaving=BIL numberOfBands=1' || 
	' defaultChannelSelection=1' || 
	' mimeType=application/x-djm' );

	UPDATE emp SET large_photo = Image WHERE ename = 'John Doe';
	COMMIT;
END;
/
Note: Once you have set the properties for a foreign image, it is up to you to keep the properties consistent if you modify the image. If interMedia image detects an unknown file format, it will not implicitly set the properties. Once you have set the properties for a foreign image, you can use the process() and processCopy() methods to process the image.


Note: If you process a forgeign image and do not specify a format to convert to, the image will be converted to an Oracle Raw Pixel image (RPIX is a natively understood image format).  Any image header or trailer in the original image will not be copied to the target image.

 

To extend the interMedia ORDImage data type with a new object type

If you require metadata extraction and processing capabilities for image formats that don't meet the requirements of the interMedia foreign image mechanism described above, you can create your own Image object type and implement your own properties extraction and processing methods.  You can create a composite type including an ORDImage type. Use the interMedia ORDImage methods for import and export, and then implement your own setProperties() and process() methods.

You can use the ORDImage type as the basis for a new type of your own creation as shown in the example below.  Note, the example below is very simple and does not show replacing the ORDImage process and setProperties methods.  It simply adds a new attribute, "description", and modifies a few methods to deal with the new attribute.

 

Example 3: Extend Oracle8i interMedia Image with a new object type
CREATE TYPE AnnotatedImage AS OBJECT
	(image ORDSYS.ORDImage,
	description VARCHAR2(2000),
	MEMBER PROCEDURE SetProperties(SELF IN OUT AnnotatedImage),
	MEMBER PROCEDURE Copy(dest IN OUT AnnotatedImage),
	MEMBER PROCEDURE ProcessCopy(command IN VARCHAR2, 
	dest IN OUT AnnotatedImage)
);
/


CREATE TYPE BODY AnnotatedImage AS

MEMBER PROCEDURE SetProperties(SELF IN OUT AnnotatedImage) IS
BEGIN
	SELF.image.setProperties;
	SELF.description := 
		This is an example of using Image object as a subtype';
END SetProperties;

MEMBER PROCEDURE Copy(dest IN OUT AnnotatedImage) IS
BEGIN
	SELF.image.copy(dest.image);
	dest.description := SELF.description;
END Copy;


MEMBER PROCEDURE ProcessCopy(command IN VARCHAR2,
				dest IN OUT AnnotatedImage) IS
BEGIN
	SELF.Image.processCopy(command,dest.image);
	dest.description := SELF.description;
END ProcessCopy;

END;
/

After creating the new type, you can use it as you would any other type. For example:
CREATE or REPLACE DIRECTORY TEST_DIR as 'C:\TESTS';

CREATE TABLE my_example(ID number, an_image AnnotatedImage);

INSERT INTO my_example VALUES (1, 
	AnnotatedImage(ORDSYS.ORDImage(
	ORDSYS.ORDSource(empty_blob(),'file','TEST_DIR', 
	'jdoe.gif',SYSDATE,0), 
	NULL,NULL,NULL,NULL,NULL,NULL,NULL), NULL)
);

COMMIT;

DECLARE

	myimage AnnotatedImage;

BEGIN

	SELECT an_image INTO myimage FROM my_example;

	myimage.SetProperties;
	DBMS_OUTPUT.PUT_LINE('This image has a description of ');
	DBMS_OUTPUT.PUT_LINE(myimage.description);
	UPDATE my_example SET an_image = myimage;

END;
/

 

 

E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy