📄 rle.txt
字号:
15image will have more than 2 -1 scanlines. A complete program (except forerror checking) that reads an RLE file from standard input and produces anegative image on standard output is shown in Figure 2-5. The functions rle_row_alloc and rle_raw_alloc simplify allocation of bufferspace for use by the rle routines. Both use a supplied globals structure todetermine how many and which channels need buffer space, as well as the size ofthe buffer for each scanline. The returned buffer pointers will be adjustedfor the presence of an alpha channel, if it is present. Buffer space for pixelor rle_op data will be allocate only for those channels that have bits set inthe channel bitmap. The buffer space may be freed by calling rle_row_free orrle_raw_free, respectively.3. Comments, issues, and directions Some comments on the file format and current subroutine implementation: - The background color for the alpha channel is always 0. - All channels must have the same number of bits. This could be a problem when saving, e.g., Z values, or if more than 8 bits of precision were desired for the alpha channel. /* An example of using rle_getrow */ /* Scanline pointer */ rle_pixel ** scan; int i; /* Read the RLE file from stdin */ rle_get_setup( &globals ); /* Allocate enough space for scanline data, including alpha channel */ /* (Should check for non-zero return, indicating a malloc error) */ rle_row_alloc( &globals, &scan ); /* Read scanline data */ while ( (y = rle_getrow( &globals, stdin, scan ) <= globals.sv_ymax ) /* Use the scanline data */; Figure 2-4: Example of rle_getrow use. #include <stdio.h> #include <svfb_global.h> #include <rle_getraw.h> main() { struct sv_globals in_glob, out_glob; rle_op ** scan; int * nraw, i, j, c, y, newy; in_glob.svfb_fd = stdin; rle_get_setup( &in_glob ); /* Copy setup information from input to output file */ out_glob = in_glob; out_glob.svfb_fd = stdout; /* Get storage for calling rle_getraw */ rle_raw_alloc( &in_glob, &scan, &nraw ); /* Negate background color! */ if ( in_glob.sv_background ) for ( i = 0; i < in_glob.sv_ncolors; i++ ) out_glob.sv_bg_color[i] = 255 - out_glob.sv_bg_color[i]; /* Init output file */ sv_setup( RUN_DISPATCH, &out_glob ); y = in_glob.sv_ymin; while ( (newy = rle_getraw( &in_glob, scan, nraw )) != 32768 ) { /* If > one line skipped in input, do same in output */ if ( newy - y > 1 ) sv_skiprow( &out_glob, newy - y ); y = newy; /* Map all color channels */ for ( c = 0; c < out_glob.sv_ncolors; c++ ) for ( i = 0; i < nraw[c]; i++ ) switch( scan[c][i].opcode ) { case RRunDataOp: scan[c][i].u.run_val = 255 - scan[c][i].u.run_val; break; case RByteDataOp: for ( j = 0; j < scan[c][i].length; j++ ) scan[c][i].u.pixels[j] = 255 - scan[c][i].u.pixels[j]; break; } sv_putraw( scan, nraw, &out_glob ); /* Free raw data */ rle_freeraw( &in_glob, scan, nraw ); } sv_puteof( &out_glob ); /* Free storage */ rle_raw_free( &in_glob, scan, nraw ); } Figure 2-5: Program to produce a negative of an image - Pixels are skipped (by sv_putrow) only if all channel values of the pixel are equal to the corresponding background color values. - The current Implementation of sv_putrow skips pixels only if at least 2 adjacent pixels are equal to the background. The SkipPixels operation is intended for efficiency, not to provide cheap compositing. - Nothing forces the image data to lie within the bounds declared in the header. However, rle_getrow will not write outside these bounds, to prevent core dumps. No such protection is provided by rle_getraw. - Images saved in RLE are usually about 1/3 their original size (for an "average" image). Highly complex images may end up slightly larger than they would have been if saved by the trivial method. We have not yet decided how pixels with other than 8 bits should be packedinto the file. To keep the file size down, one would like to pack ByteData astightly as possible. However, for interpretation speed, it would probably bebetter to save one value in each (pixelbits+7)/8 bytes. Some proposed enhancements include: - A "ramp" opcode. This specifies that pixel values should be linearly ramped between two values for a given number of pixels in the scanline. This opcode would be difficult to generate from an image, but if an application knew it was generating a ramp, it could produce significant file size savings (e.g. in Gouraud shaded images). - Opcodes indicating that the current scanline is identical to the previous, or that it differs only slightly (presumably followed by standard opcodes indicating the difference). Detection of identical scanlines is easy, deciding that a scanline differs slightly enough to warrant a differential description could be difficult. In images with large areas with little change, this could produce size savings(This suggestion was inspired by a description of the RLE format used at Ohio State University.) The subroutine library is still missing some useful functions. Some proposedadditions are: - Conversion from "raw" to "row" format, and back. One could then view sv_putrow as being a "raw" to "row" conversion followed by a call to sv_putraw, and rle_getrow as a call to rle_getraw followed by "row" to "raw" conversion. - A function to merge several channels of "raw" data into a single channel. For example, this would take separate red, green, and blue channels and combine them into a single RGB channel. This would be useful for RLE interpretation on devices that do not easily support the separate channel paradigm, while preserving the efficiency of the "raw" interface. It could also be used to increase the efficiency of a compositing program. The Utah RLE format has developed and matured over a period of about sixyears, and has proven to be versatile and useful for a wide variety ofapplications that require image transmittal and storage. It provides acompact, efficiently interpreted image storage capability. We expect to seecontinued development of capabilities and utility, but expect very littlechange in the basic format.4. Acknowledgments This work was supported in part by the National Science Foundation(DCR-8203692 and DCR-8121750), the Defense Advanced Research Projects Agency(DAAK11-84-K-0017), the Army Research Office (DAAG29-81-K-0111), and the Officeof Naval Research (N00014-82-K-0351). All opinions, findings, conclusions orrecommendations expressed in this document are those of the authors and do notnecessarily reflect the views of the sponsoring agencies. Table of Contents1. Introduction 02. Description of RLE Format 0 2.1. The Header 0 2.2. The Scanline Data 0 2.3. Subroutine Interface 1 2.4. Writing RLE files 1 2.5. Reading RLE Files 23. Comments, issues, and directions 24. Acknowledgments 5 List of FiguresFigure 2-1: RLE file header 0Figure 2-2: RLE file operand formats 0Figure 2-3: Example of use of sv_putrow 2Figure 2-4: Example of rle_getrow use. 3Figure 2-5: Program to produce a negative of an image 4
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -